Hi R-colleagues. In the sem-package i have a problem to introduce hidden variables. As a simple example I take an ordinary factor analysis. The program: cmat=c(0.14855886, 0.05774635, 0.08003300, 0.04900990, 0.05774635, 0.18042029, 0.11213013, 0.03752475, 0.08003300, 0.11213013, 0.24646337, 0.03609901, 0.04900990, 0.03752475, 0.03609901, 0.31702970) rn=c("R","L","I","M") cn=c("R","L","I","M") tcv=matrix(cmat,nrow=4,ncol=4,dimnames=list(rn,cn)) model.RLIM <- specify.model() R -> f1, laddR, NA L -> f1, laddL, NA I -> f1, laddI, NA M -> f1, laddM, NA R <-> R, dR,NA L <-> L, dL,NA I <-> I, dI,NA M <-> M, dM,NA f1 <-> f1, df1,NA sem.RLIM=sem(model.RLIM,tcv,101) The output: Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent In addition: Warning messages: 1: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : singular Hessian: model is probably underidentified. 2: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : refitting without aliased parameters. I use R version 2.10.0 (2009-10-26) under Windows XP sem_0.9-19 version. Where did I make a mistake? Have anyone of you knowledge of any other package doing similar things like Confirmative Factor Analysis Ralf Finne Novia University of Applied Science Vasa Finland
Ralf, If you are representing this as a factor model, you need to have the factors lead to the variables: model.RLIM <- specify.model() f1 -> R , laddR, NA f1 -> L , laddL, NA f1 -> I , laddI, NA f1 -> M, laddM, NA R <-> R, dR,NA L <-> L, dL,NA I <-> I, dI,NA M <-> M, dM,NA f1 <-> f1, df1,NA> sem(mod1,tcv,101)Model Chisquare = 5.955411 Df = 3 F1R F1L F1I x1e x2e x3e x4e 0.20301850 0.28443881 0.39421470 0.10734247 0.09951485 0.09105800 0.31702970 Iterations = 24 For a simple way to create the sem commands from an exploratory factor analysis, you might want to look at the psych package and the vignette: psych_for_sem. e.g.,> library(psych) > f1 <- fa(tcv) #do the exploratory factor analysis> mod1 <- structure.diagram(f1,errors=TRUE) #draw the path diagram >from the model and create the sem commands > mod1Path Parameter StartValue 1 MR1->R F1R 2 MR1->L F1L 3 MR1->I F1I 4 R<->R x1e 5 L<->L x2e 6 I<->I x3e 7 M<->M x4e 8 MR1<->MR1 <fixed> 1> sem(mod1,tcv,101) #do the semModel Chisquare = 5.955411 Df = 3 F1R F1L F1I x1e x2e x3e x4e 0.20301850 0.28443881 0.39421470 0.10734247 0.09951485 0.09105800 0.31702970 Iterations = 24 Best wishes, Bill>At 6:23 PM +0200 11/25/09, Ralf Finne wrote:>Hi R-colleagues. > >In the sem-package >i have a problem to introduce hidden variables. >As a simple example I take an ordinary factor analysis. >The program: > >cmat=c(0.14855886, 0.05774635, 0.08003300, 0.04900990, > 0.05774635, 0.18042029, 0.11213013, 0.03752475, > 0.08003300, 0.11213013, 0.24646337, 0.03609901, > 0.04900990, 0.03752475, 0.03609901, 0.31702970) >rn=c("R","L","I","M") >cn=c("R","L","I","M") > >tcv=matrix(cmat,nrow=4,ncol=4,dimnames=list(rn,cn)) > >model.RLIM <- specify.model() > R -> f1, laddR, NA > L -> f1, laddL, NA > I -> f1, laddI, NA > M -> f1, laddM, NA > R <-> R, dR,NA > L <-> L, dL,NA > I <-> I, dI,NA > M <-> M, dM,NA > f1 <-> f1, df1,NA > >sem.RLIM=sem(model.RLIM,tcv,101) > >The output: >Error in dimnames(x) <- dn : > length of 'dimnames' [2] not equal to array extent >In addition: Warning messages: >1: In sem.default(ram = ram, S = S, N = N, param.names = pars, >var.names = vars, : > singular Hessian: model is probably underidentified. > >2: In sem.default(ram = ram, S = S, N = N, param.names = pars, >var.names = vars, : > refitting without aliased parameters. > >I use R version 2.10.0 (2009-10-26) under Windows XP >sem_0.9-19 version. > >Where did I make a mistake? Have anyone of you knowledge >of any other package doing similar things like Confirmative Factor Analysis >Ralf Finne >Novia University of Applied Science >Vasa Finland > >______________________________________________ >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.-- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnight http://www.thebulletin.org
The model you have specified there is not an ordinary factor analysis model. This may be closer to what you are thinking of: model.RLIM <- specify.model() f1 -> R, laddR, NA f1 -> L, laddL, NA f1 -> I, laddI, NA f1 -> M, laddM, NA R <-> R, dR, NA L <-> L, dL, NA I <-> I, dI, NA M <-> M, dM, NA f1 <-> f1, NA, 1 sem.RLIM=sem(model.RLIM,tcv,101) summary(sem.RLIM) Note that the paths go from the latent factor to the manifest variables, not vice-versa. Best, -- Wolfgang Viechtbauer http://www.wvbauer.com/ Department of Methodology and Statistics Tel: +31 (0)43 388-2277 School for Public Health and Primary Care Office Location: Maastricht University, P.O. Box 616 Room B2.01 (second floor) 6200 MD Maastricht, The Netherlands Debyeplein 1 (Randwyck) ________________________________________ From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Ralf Finne [Ralf.Finne at novia.fi] Sent: Wednesday, November 25, 2009 5:23 PM To: r-help at r-project.org Subject: [R] Structural Equation Models(SEM) Hi R-colleagues. In the sem-package i have a problem to introduce hidden variables. As a simple example I take an ordinary factor analysis. The program: cmat=c(0.14855886, 0.05774635, 0.08003300, 0.04900990, 0.05774635, 0.18042029, 0.11213013, 0.03752475, 0.08003300, 0.11213013, 0.24646337, 0.03609901, 0.04900990, 0.03752475, 0.03609901, 0.31702970) rn=c("R","L","I","M") cn=c("R","L","I","M") tcv=matrix(cmat,nrow=4,ncol=4,dimnames=list(rn,cn)) model.RLIM <- specify.model() R -> f1, laddR, NA L -> f1, laddL, NA I -> f1, laddI, NA M -> f1, laddM, NA R <-> R, dR,NA L <-> L, dL,NA I <-> I, dI,NA M <-> M, dM,NA f1 <-> f1, df1,NA sem.RLIM=sem(model.RLIM,tcv,101) The output: Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent In addition: Warning messages: 1: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : singular Hessian: model is probably underidentified. 2: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : refitting without aliased parameters. I use R version 2.10.0 (2009-10-26) under Windows XP sem_0.9-19 version. Where did I make a mistake? Have anyone of you knowledge of any other package doing similar things like Confirmative Factor Analysis Ralf Finne Novia University of Applied Science Vasa Finland ______________________________________________ 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.
Hi R-colleagues. I have been using the sem(sem) function. It uses maximum likelyhood as optimizing. method. According to simulation study in Ume? Sweden (http://www.stat.umu.se/kursweb/vt07/stad04mom3/?download=UlfHolmberg.pdf Sorry it is in swedish, except the abstract) maximum likelihood is OK for large samples and normal distribution the SEM-problem should be optimized by GLS (Generalized Least Squares). So to the question: Is there any R-function that solves SEM with GLS? Ralf Finne Novia University of Applied Science Vasa Finland
Thank you Jeremy for your information. The world is changing though. We live in an increasing economic pressure. One symptom is that we are forced to use smaller samples for economy. This explains the interest for research in how the methods perform on small samples. The cited large simulation study shows GLS is more efficient for small and badly distributed samples. So perhaps it would be worth the effort to make an addition to sem(sem) Yours Ralf Finne Emeritus Novia University of Applied Science Vasa Finland>>> Jeremy Miles <jeremy.miles at gmail.com> 12/02/09 8:22 PM >>>In the world of SEM, GLS has pretty much fallen by the wayside - I can't recall anything I've seen arguing for it's use in the past 10 years, and I also can't recall anyone using it over ML. The recommendations for non-normal distributions tend to be robust-ML, or robust weighted least squares. These are more computationally intensive, and I *think* that John Fox (author of sem) has written somewhere that it wouldn't be possible to implement them within R, without using a lower level language - or rather that it might be possible, but it would be really, really slow. However, ML and GLS are pretty similar, if you dug around in the source code, you could probably make the change (see, http://www2.gsu.edu/~mkteer/discrep.html for example, for the equations; in fact GLS is somewhat computationally simpler, as you don't need to invert the implied covariance matrix at each iteration). However, the fact that it's not hard to make the change, and that no one has made the change, is another argument that it's not a change that needs to be made. Jeremy 2009/12/2 Ralf Finne <Ralf.Finne at novia.fi>:> Hi R-colleagues. > > I have been using the sem(sem) function. It uses > maximum likelyhood as optimizing. method. > According to simulation study in Ume? Sweden >(http://www.stat.umu.se/kursweb/vt07/stad04mom3/?download=UlfHolmberg.pdf> Sorry it is in swedish, except the abstract) > maximum likelihood is OK for large samples and normal distribution > the SEM-problem should be optimized by GLS (Generalized LeastSquares).> > > So to the question: > > Is there any R-function that solves SEM with GLS? > > > Ralf Finne > Novia University of Applied Science > Vasa Finland > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. >-- Jeremy Miles Psychology Research Methods Wiki: www.researchmethodsinpsychology.com