Analisi Dati
2009-Mar-30 15:13 UTC
[R] HELP WITH SEM LIBRARY AND WITH THE MODEL'S SPECIFICATION
Dear users, i'm using the sem package in R, because i need to improve a confermative factor analisys. I have so many questions in my survey, and i suppose, for example, that Question 1 (Q1) Q2 and Q3 explain the same thing (factor F1), Q4,Q5 and Q6 explain F2 and Q7 and Q8 explain F3... For check that what i supposed is true, i run this code to see if the values of loadings are big or not. (In this code i used more than 3 factors) library("sem") #put in "mydata", the value of the questions mydata <- data.frame(X$X12a,X$X12b,X$X12c,X$X12d,X$X12e,X$X12f,X$X12g,X$X12h,X$X12i,X$X12l,X$X12m,X$X12n,X$X12o,X$X12p,X$X12q,X$X12r,X$X12s,X$X1a,X$X1b,X$X1c,X$X1d,X$X1e,X$X1f,X$X3h,X$X3i,X$X3l,X$X3m,X$X3n,X$X3o,X$X3p,X$X3q,X$X3r,X$X3s,X$X3t,X$X3u,X$X3v,X$X4a,X$X5q,X$X5r,X$X5s,X$X8a,X$X8b,X$X8c,X$X8d) #i calculate the covariance of the data mydata.cov <- cov(mydata,use="complete.obs") #I specify my model model.mydata <- specify.model() F1 -> X.X12a, lam1, NA F1 -> X.X12b, lam2, NA F1 -> X.X12c, lam3, NA F1 -> X.X12d, lam4, NA F1 -> X.X12e, lam5, NA F1 -> X.X12f, lam6, NA F1 -> X.X12g, lam7, NA F2 -> X.X12h, lam8, NA F2 -> X.X12i, lam9, NA F2 -> X.X12l, lam10, NA F2 -> X.X12m, lam11, NA F2 -> X.X12n, lam12, NA F2 -> X.X12o, lam13, NA F3 -> X.X12p, lam14, NA F3 -> X.X12q, lam15, NA F3 -> X.X12r, lam16, NA F3 -> X.X12s, lam17, NA F4 -> X.X1a, lam18, NA F4 -> X.X1b, lam19, NA F4 -> X.X1c, lam20, NA F4 -> X.X1d, lam21, NA F4 -> X.X1e, lam22, NA F4 -> X.X1f, lam23, NA F5 -> X.X3h, lam24, NA F5 -> X.X3i, lam25, NA F5 -> X.X3l, lam26, NA F5 -> X.X3m, lam27, NA F5 -> X.X3n, lam28, NA F5 -> X.X3o, lam29, NA F5 -> X.X3p, lam30, NA F5 -> X.X3q, lam31, NA F6 -> X.X3r, lam32, NA F6 -> X.X3s, lam33, NA F6 -> X.X3t, lam34, NA F6 -> X.X3u, lam35, NA F6 -> X.X3v, lam36, NA F6 -> X.X4a, lam37, NA F7 -> X.X5q, lam38, NA F7 -> X.X5r, lam39, NA F7 -> X.X5s, lam40, NA F8 -> X.X8a, lam41, NA F8 -> X.X8b, lam42, NA F8 -> X.X8c, lam43, NA F8 -> X.X8d, lam44, NA X.X12a <-> X.X12a, e1, NA X.X12b <-> X.X12b, e2, NA X.X12c <-> X.X12c, e3, NA X.X12d <-> X.X12d, e4, NA X.X12e <-> X.X12e, e5, NA X.X12f <-> X.X12f, e6, NA X.X12g <-> X.X12g, e7, NA X.X12h <-> X.X12h, e8, NA X.X12i <-> X.X12i, e9, NA X.X12l <-> X.X12l, e10, NA X.X12m <-> X.X12m, e11, NA X.X12n <-> X.X12n, e12, NA X.X12o <-> X.X12o, e13, NA X.X12p <-> X.X12p, e14, NA X.X12q <-> X.X12q, e15, NA X.X12r <-> X.X12r, e16, NA X.X12s <-> X.X12s, e17, NA X.X1a <-> X.X1a, e18, NA X.X1b <-> X.X1b, e19, NA X.X1c <-> X.X1c, e20, NA X.X1d <-> X.X1d, e21, NA X.X1e <-> X.X1e, e22, NA X.X1f <-> X.X1f, e23, NA X.X3h <-> X.X3h, e24, NA X.X3i <-> X.X3i, e25, NA X.X3l <-> X.X3l, e26, NA X.X3m <-> X.X3m, e27, NA X.X3n <-> X.X3n, e28, NA X.X3o <-> X.X3o, e29, NA X.X3p <-> X.X3p, e30, NA X.X3q <-> X.X3q, e31, NA X.X3r <-> X.X3r, e32, NA X.X3s <-> X.X3s, e33, NA X.X3t <-> X.X3t, e34, NA X.X3u <-> X.X3u, e35, NA X.X3v <-> X.X3v, e36, NA X.X4a <-> X.X4a, e37, NA X.X5q <-> X.X5q, e38, NA X.X5r <-> X.X5r, e39, NA X.X5s <-> X.X5s, e40, NA X.X8a <-> X.X8a, e41, NA X.X8b <-> X.X8b, e42, NA X.X8c <-> X.X8c, e43, NA X.X8d <-> X.X8d, e44, NA F1 <-> F1, NA, 1 F2 <-> F2, NA, 1 F3 <-> F3, NA, 1 F4 <-> F4, NA, 1 F5 <-> F5, NA, 1 F6 <-> F6, NA, 1 F7 <-> F7, NA, 1 F8 <-> F8, NA, 1 mydata.sem <- sem(model.mydata, mydata.cov, nrow(mydata)) # print results (fit indices, paramters, hypothesis tests) summary(mydata.sem) # print standardized coefficients (loadings) std.coef(mydata.sem) Now the problems, and my questions, are various: 1)In "mydata" i need to have only the questions or also my latent variables? In other words, i suppose that the mean of Q1,Q2,Q3 give me a variable called "OCB". In mydata i need also this mean??? 2)In the specification of my model, i didn't use nothing like "F1<->F2......", is this a problem? this sentence what indicates??? that i have a mediation/moderation effect between variables??? 3)Now, if you look my code,you could see that i don't put in "mydata" the mean value called "OCB" (see point 1), and i don't write nothing about the relation between F1 and F2, and when i run the sem function i receive these warnings: 1: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : S is numerically singular: expect problems 2: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : S is not positive-definite: expect problems 3: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : Could not compute QR decomposition of Hessian. Optimization probably did not converge. and after the summary i receive this error: coefficient covariances cannot be computed What i can do for all this???? Hoping in your interest about this problem, i wish you the best. Costantino Milanese, a young researcher full of problems! [[alternative HTML version deleted]]
John Fox
2009-Mar-30 17:12 UTC
[R] HELP WITH SEM LIBRARY AND WITH THE MODEL'S SPECIFICATION
Dear Costantino,> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]On> Behalf Of Analisi Dati > Sent: March-30-09 11:13 AM > To: r-help at r-project.org > Subject: [R] HELP WITH SEM LIBRARY AND WITH THE MODEL'S SPECIFICATION > > Dear users, > i'm using the sem package in R, because i need to improve a confermative > factor analisys. > I have so many questions in my survey, and i suppose, for example, that > Question 1 (Q1) Q2 and Q3 explain the same thing (factor F1), Q4,Q5 and Q6 > explain F2 and Q7 and Q8 explain F3... > For check that what i supposed is true, i run this code to see if thevalues> of loadings are big or not. > (In this code i used more than 3 factors) >. . . (many lines elided)> > > Now the problems, and my questions, are various: > 1)In "mydata" i need to have only the questions or also my latentvariables?> In other words, i suppose that the mean of Q1,Q2,Q3 give me a variable > called "OCB". In mydata i need also this mean???No. sem() recognizes as latent variables (F1, F2, etc.) those variables that do not appear in the observed-variable covariance matrix. There are several examples in ?sem that illustrate this point. Moreover, the latent variables are not in general simply means of observed variables.> 2)In the specification of my model, i didn't use nothing like "F1<- > >F2......", is this a problem? this sentence what indicates??? that i havea> mediation/moderation effect between variables???By not specifying F1 <-> F2, you imply that the factors F1 and F2 are uncorrelated. This isn't illogical, but it produces a very restrictive model. Conversely, specifying F1 <-> F2 causes the covariance of F1 and F2 to be estimated; because you set the variances of the factors to 1, this covariance would be the factor correlation.> 3)Now, if you look my code,you could see that i don't put in "mydata" the > mean value called "OCB" (see point 1), and i don't write nothing about the > relation between F1 and F2, and when i run the sem function i receivethese> warnings: > > 1: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names > vars, : > S is numerically singular: expect problems > 2: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names > vars, :That seems to me a reasonably informative error message: The observed-variable covariance matrix is singular. This could happen, e.g., if two observed variables are perfectly correlated, if an observed variable had 0 variance, or if there were more observed variables than observations.> S is not positive-definite: expect problems > 3: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names > vars, :That S is singular implies that it is not positive-definite, but because a non-singular matrix need not be positive-definite, sem() checks for both.> Could not compute QR decomposition of Hessian. > Optimization probably did not converge. > > and after the summary i receive this error: > > coefficient covariances cannot be computedThese are the problems that sem() told you to expect.> > What i can do for all this????Without more information, it's not possible to know. You should figure out why the observed-variable covariance matrix is singular. I hope this helps, John> > Hoping in your interest about this problem, i wish you the best. > > Costantino Milanese, a young researcher full of problems! > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Analisi Dati
2009-Mar-31 14:34 UTC
[R] HELP WITH SEM LIBRARY AND WITH THE MODEL'S SPECIFICATION
Dear John I want to thank you so much for the help. I've solved my problem following your instructions. The matrix S of the cov was singular because i had few complete observation. I have included 2 wrongs item, because (in the majority of cases) when one is inputed, the other one is "NA", so i have only fews complete observations... Thank you so much again, for this help and for the great job about SEM( ) that you have wrote and shared on the web. My best regards, Costantino Milanese, always the young researcher but with less problems! [[alternative HTML version deleted]]