Dear Soon Yi,
Yes, if a variable in the model doesn't appear in the data (either a data
set, given by the data argument, or a covariance or moment matrix given by the S
argument to sem), sem will assume that the variable is a latent variable.
On the other hand, the models you've specified have puzzling features. In
the first model, you fix the error variances for med and endo to 1. Normally,
these would be free parameters. Setting the error variance for latent in the
second model to 1 is a normalizing constraint to set the scale of the variable,
but I believe that the model is underidentified.
A few additional comments: (1) You don't have to formulate the model as a
character matrix; you can use specifyModel() instead. Similarly, readMoments()
makes it easier to input the covariance matrix. (2) It's generally easier to
specify the model in equation form, rather than path form, using
specifyEquations(). (3) If you use specifyModel() or specifyEquations(),
it's not necessary (though also not wrong) to specify error variances for
endogenous variables; if omitted, these will be supplied by default (but as free
parameters).
For a number of examples, see ?sem and the document at
<http://socserv.socsci.mcmaster.ca/jfox/Books/Companion/appendix/Appendix-SEMs.pdf>.
I hope this helps,
John
------------------------------------------------
John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/
On Sun, 4 Nov 2012 19:27:12 +0000 (GMT)
Soon Yi <soon.yi at ymail.com> wrote:> Hello
>
> I am using sem to look at the direct effect of one variable on another but
i am uncertain if i am progressing correctly.
>
> An example:
>
> covar1<-? matrix(c(0.4,-0.2,3,-0.2 , 0.3,-2 , 3 ,-2 , 60),
nrow=3,byrow=T)
>
>
rownames(covar1)<-colnames(covar1)<-c("endo","exo","med")
>
> path1<-matrix(c(? ? "exo -> endo",? "g1", NA,
> ????????????????????????? "exo -> med", "g2",? NA,
> ????????????????????????? "med -> endo", "g3", NA
> ??? ??? ??? ??? ??? ??? ??? "med<->med",NA,1,
> ??? ??? ??? ??? ??? ??? ??? "endo<->endo",NA,1),?
ncol=3,byrow=T)
>
> output2<-sem(path1,covar1,N=400,fixed=c("exo"))
> summary(output)
>
> With this i can get the direct effect of exo on endo.
>
>
> ?But? if i want 'med' above to be a latent variable that is
identified by a number of variables - in the example below i use just one - do i
proceed as follows. ???
>
> ?????
> ##With latent variable
> path2<-matrix(c(?? "exo -> endo", "g1",NA,
> ???? ??? ??? ??? ??? "exo -> latent", "g2",? NA,
> ???????????????????? "latent -> endo","g3", NA,
> ???????????????????? "latent -> med", "g4", NA,
> ??? ??? ??? ??? ????? "med<->med",NA,1,??? ??? ??? ??? ???
?"endo<->endo",NA,1? ,
> ? ??? ??? ??? ??? ?"latent<->latent",NA,1), ncol=3,byrow=T)
>
>
> output2<-sem(path2,covar1,N=400,fixed=c("exo"))??
>
>
> Is this the correct way to formulate this please?
>
> thanks for any advice ?????
> ______________________________________________
> R-help at 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.