Dear Yves

Many thanks for your quick reply, I really appreciate it!

The reason I was working with a correlation matrix is because I wanted to
calculate polychoric correlations first before submitting it to the actual
sem command. I was unsure whether R would use polychoric correlations when
indicating which of the variables are ordered. A final question on the
sample.cov=hetcor command. Does this not assume it is a sample
variance-covariance rather than a correlation matrix (as calculated using
the polycor package)?

I also tried using the command (thanks for the tip!)

sem.cdu= sem(cdu, data=germany2009, ordered=c("cdupid", "MERKELLIKE",
"CDULIKE", "MERKELPROX", "CDUPROX"))

but I always get the error result:

semcdu=sem(cdu, data=germany2009, ordered=c("cdupid", "MERKELLIKE",
"CDULIKE", "MERKELPROX", "CDUPROX"), fixed.x=F)
Error in tmp[cbind(REP$row[idx], REP$col[idx])] <- partable$free[idx] :
  NAs are not allowed in subscripted assignments

Is there anything I am missing? Obviously, I would prefer using the raw
data and use the WLSMV estimator to obtain unbiased and efficient results
so I'd rather take advantage of the full data.

Many thanks for your advice on this.

Kind regards,
Laura Schwirz



On 17 November 2012 09:56, yrosseel <yrosseel@gmail.com> wrote:

> Dear Laura,
>
> John is correct. The error is produced by the sem() function in the lavaan
> package. The reason is that you did not use proper names for the function
> arguments. The correct call should be:
>
> sem.cdu= sem(cdu, sample.cov=hetcor, sampl.nobs=1861,
> meanstructure=F,fixed.x=F)
>
> But more importantly, using a polychoric correlation as input, and using
> ML estimation will not produce correct standard errors and test statistics.
> A better approach is to use the categorical capabilities of lavaan and
> provide the full data to sem(), indicating which variables can be
> considered as 'ordered'. For example:
>
> sem.cdu= sem(cdu, data=germany2009, ordered=c("cdupid", "MERKELLIKE",
> "CDULIKE", "MERKELPROX", "CDUPROX"))
>
> Here, I assumed all variables can be considered as ordered. If some of
> them should be treated as conintuous/numeric, omit them from the ordered=
> argument.
>
> By default, lavaan will use the WLSMV estimator when ordered variables are
> involved.
>
> Yves.
>
>
>
> On 11/16/2012 10:13 PM, John Fox wrote:
>
>> Dear Laura,
>>
>> As I explained to you when you wrote to me directly, you're not
>> having trouble with the polycor package, since you have AFAICS
>> successfully computed polychoric correlation among your variables.
>> The error is produced when you call sem(), apparently in the lavaan
>> package (though you don't mention that), and you should address your
>> question to the author of that package (or use an appropriate title
>> line in your r-help posting).
>>
>> Best, John
>>
>> ------------------------------**------------------ John Fox Sen.
>> William McMaster Prof. of Social Statistics Department of Sociology
>> McMaster University Hamilton, Ontario, Canada
>> http://socserv.mcmaster.ca/**jfox/ <http://socserv.mcmaster.ca/jfox/> On Fri, 16 Nov 2012 12:58:03 +0000
>> Laura Maria Schwirz <schwirzl@tcd.ie> wrote:
>>
>>> I am currently working with R's polycor package and I have
>>> encountered a problem. I tried to follow the steps as outlined in
>>> the sem.pdf file where a CFA model is run using polychoric
>>> correlations. Every time I run the command sem(model, data, N=.), I
>>> get the following warning message: Warning message: In if
>>> (orthogonal) { : the condition has length > 1 and only the first
>>> element will be used
>>>
>>> Below is the code that I am using for my dataset. I also tried to
>>> copy and paste the code from the sem.pdf file using data from CNES
>>> but I still get an error message. Any help would be much
>>> appreciated.
>>>
>>>
>>>
>>>  germany2009 <- read.dta("StataforR.dta") #attach(germany2009)
>>>> viewData(germany2009) # hcor <- function(data) hetcor(data,
>>>> std.err=F, pd=T)$correlations hetcor=hcor(germany2009) hetcor
>>>>
>>> cdupid MERKELLIKE    CDULIKE MERKELPROX    CDUPROX cdupid
>>> 1.0000000  0.5073577  0.6070514 -0.4064925 -0.4146810 MERKELLIKE
>>> 0.5073577  1.0000000  0.7832340 -0.4405571 -0.4200360 CDULIKE
>>> 0.6070514  0.7832340  1.0000000 -0.4868895 -0.5042006 MERKELPROX
>>> -0.4064925 -0.4405571 -0.4868895  1.0000000  0.8789219 CDUPROX
>>> -0.4146810 -0.4200360 -0.5042006  0.8789219  1.0000000
>>>
>>>> viewData(hetcor) cdu= ' CDULIKE ~ cdupid + CDUPROX
>>>>
>>> +   MERKELLIKE ~ cdupid + MERKELPROX +   CDUPROX ~ ~ cdupid +
>>> cdupid ~ ~ MERKELPROX +   CDUPROX ~ ~ MERKELPROX +   MERKELLIKE ~
>>> 1 +   CDULIKE ~1 '
>>>
>>>> sem.cdu= sem(cdu, hetcor, N=1861, meanstructure=F,fixed.x=F)
>>>>
>>> Warning message: In if (orthogonal) { : the condition has length >
>>> 1 and only the first element will be used
>>>
>>
>


-- 
Laura Schwirz

PhD Candidate and IRCHSS Scholar
Department of Political Science
Trinity College Dublin
Dublin 2
Republic of Ireland
Email: schwirzl@tcd.ie

	[[alternative HTML version deleted]]


