Hi John

Thanks for your quick reply.

The full warning I got is

' Error in csem(model = model.description, start, opt.flag = 1, typsize = 
typsize,  :
  The matrix is non-invertable.'

The eigenvalues of the tetrachoric correlations are non negative. So it is must 
be how I am defining my model.

I have also tried it without having lavaan in the session.

A wee example of my error (whether it is sensible);

library(sem)

my.cor<-matrix(c( 1.0000000  ,  0.7600616  ,  0.3653309 ,   0.4377949 , 
0.2917927 ,   0.5133697,
    0.7600616 ,   1.0000000,   0.6335519 ,   0.8288809 , 0.6223942  ,  
0.6355725,
     0.3653309 ,  0.6335519  ,  1.0000000 ,   0.9098309 , 0.9098309  ,  
0.7693395,
     0.4377949 , 0.8288809  ,  0.9098309  ,  1.0000000  ,0.9136967   , 
0.7829854,
      0.2917927  ,0.6223942  ,  0.9098309  ,  0.9136967  ,1.0000000   , 
0.7354562,
     0.5133697  ,0.6355725  ,  0.7693395  ,  0.7829854 , 0.7354562   , 
1.0000000),
        nrow=6,byrow=T)

colnames(my.cor)<-rownames(my.cor)<-c("a","b","c","d","e","g")

eigen(my.cor)
solve(my.cor)

#i tried defining the model in two ways

        model.1<-matrix(c(
        #       arrow           #parameter              #start
                "f -> a",       "g1",                   NA,
                "f -> b",       "g2",                   NA,
                "f -> c",       "g3",                   NA,
                "f -> d",       "g4",                   NA,
                "f -> e",       "g5",                   NA,
                "f -> g",       "g6",                   NA,
                "f <-> f",      NA,                     1),
                ncol=3,byrow=T)

out<-sem(model.1,S=my.cor,200)

model.1 <- specifyEquations()
 f1 = gam11*a + gam12*b + gam13*c + gam14*d + gam15*e + gam16*g
 f1 = 1* f1

out<-sem(model.1,S=my.cor,200)

But the same error.

I would be very grateful if you could indicate where the error in my code is 
please.


thanks, david




-----Original Message-----
From: John Fox [mailto:j...@mcmaster.ca]
Sent: 23 January 2013 14:00
To: David Purves
Cc: r-help@R-project.org
Subject: Re: [R] CFA with lavaan or with SEM

Dear David,

On Wed, 23 Jan 2013 11:19:09 +0000
 David Purves <david.pur...@glasgow.ac.uk> wrote:
> Hi
>
> Sorry for the rather long message.
>

. . .

>
> I have tried the analysis using John Fox's SEM package / command.
>
> I calculate the correlation matrix with smoothing
>
> my.cor<-hetcor(north.dat.sub,use="pairwise.complete.obs")$correlations
>
> This returns the warning indicating that the correlation matrix was adjusted 
> to make it positive definite. However the following sem model does not run, 
> with the error message that the matrix is non-invertible.
>
> mod1<-sem::sem(sem .model.1, S=my.cor, 300)
>
> Should the smoothing not allow it to be inverted?
>

If the input correlation matrix is really positive definite, then it has an 
inverse. You could check directly, e.g., by looking at the eignevalues of the 
tetrachoric correlation matrix. There's very little here to go on, not even the 
error message produced by sem(). By the way, I assume that you didn't really 
call sem in the sem package as sem::sem in a session in which lavann was 
loaded. I'm not sure what would happen if you did that.

Best,
 John

------------------------------------------------
John Fox
Sen. William McMaster Prof. of Social Statistics Department of Sociology 
McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/

>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




The University of Glasgow, charity number SC004401

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to