AnnalisaStacchini
2014-Feb-10 18:08 UTC
[R] Help with SEM: "Error in 1:m : NA/NaN argument"
Hi, I am trying to fit a SEM model (the ram specification of the model, along with the estimated polycoric VCmatrix (CC32), is attacched), but I get the following error message: "Error in 1:m : NA/NaN argument"I did not find any help on internet, so I tried to understend what is going wrong calling: getAnywhere(sem.default) and reproducing the sem.default function step by step.I found that the problem arises from: n.fix <- length(fixed.x) if (!is.null(fixed.x)) { for (i in 1:n.fix) { for (j in 1:i) { ram <- rbind(ram, c(2, fixed.x[i], fixed.x[j], 0, S[fixed.x[i], fixed.x[j]])) } } } m <- max(ram[, c(2, 3)]) Indeed, if I run just: for (i in 1:n.fix) {for (j in 1:i) {G<-c(2, fixed.x[i], fixed.x[j], 0, S[fixed.x[i], fixed.x[j]]) } I get only this (G=): "2" "Autunno" "Autunno" "0" "1" But I still cannot understand what is wrong.The code I used is: library(sem)CLB<-classifyVariables(Mod.Bus) fisse<-as.character(CLB$exogenous)Business32<-sem(Mod.Bus, S= as.matrix(CC32), N<- 16029, fixed.x=fisse,objective= objectiveGLS, maxiter=100000) Can anybody help me please?Any suggestion will be truly appreciated.Annalisa Model ram specific.docx (21K) <http://r.789695.n4.nabble.com/attachment/4685052/0/Model%20ram%20specific.docx> CC32.Rdata (20K) <http://r.789695.n4.nabble.com/attachment/4685052/1/CC32.Rdata> C32.Rdata (17K) <http://r.789695.n4.nabble.com/attachment/4685052/2/C32.Rdata> -- View this message in context: http://r.789695.n4.nabble.com/Help-with-SEM-Error-in-1-m-NA-NaN-argument-tp4685052.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Dear Annalisa, I was unable to load either of the data sets that you provided, obtaining the following message: ---------- snip --------> load(file.choose())Error: bad restore file magic number (file may be corrupted) -- no data loaded In addition: Warning message: file 'CC32.Rdata' has magic number '"T1" ' Use of save versions prior to 2 is deprecated ---------- snip -------- I assume from what you did that all of the exogenous variables in the model are observed variables in the covariance matrix in CC32; otherwise it wouldn't make sense to specify them as fixed.x. Some other comments: You've named a number of parameters "0", with the side effect that they are all constrained equal. One can do this, but I doubt whether you intended it. I'd encourage you to use specifyEquations(), which I think is less error-prone, rather than specifyModel(), and to pass the data, rather than a covariance matrix, to sem(). As well, I'd be concerned about a model that really required 100000 iterations to converge, and wonder why you're using the GLS objective function. I hope this helps, John ----------------------------------------------- John Fox, Professor McMaster University Hamilton, Ontario, Canada http://socserv.socsci.mcmaster.ca/jfox/> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of AnnalisaStacchini > Sent: Monday, February 10, 2014 1:08 PM > To: r-help at r-project.org > Subject: [R] Help with SEM: "Error in 1:m : NA/NaN argument" > > Hi, I am trying to fit a SEM model (the ram specification of the model, > along with the estimated polycoric VCmatrix (CC32), is attacched), but > I get the following error message: "Error in 1:m : NA/NaN argument"I > did not find any help on internet, so I tried to understend what is > going wrong calling: getAnywhere(sem.default) and reproducing the > sem.default function step by step.I found that the problem arises from: > n.fix <- length(fixed.x) > > if (!is.null(fixed.x)) { > > for (i in 1:n.fix) { > > for (j in 1:i) { > > ram <- rbind(ram, c(2, fixed.x[i], fixed.x[j], > > 0, S[fixed.x[i], > fixed.x[j]])) > > } > > } > > } > > m <- max(ram[, c(2, 3)]) > Indeed, if I run just: > for (i in 1:n.fix) {for (j in 1:i) {G<-c(2, fixed.x[i], fixed.x[j], > 0, S[fixed.x[i], fixed.x[j]]) } > I get only this (G=): "2" "Autunno" "Autunno" "0" "1" > But I still cannot understand what is wrong.The code I used is: > library(sem)CLB<-classifyVariables(Mod.Bus) > > fisse<-as.character(CLB$exogenous)Business32<-sem(Mod.Bus, > S= as.matrix(CC32), N<- 16029, fixed.x=fisse,objective= objectiveGLS, > maxiter=100000) > > Can anybody help me please?Any suggestion will be truly > appreciated.Annalisa > > > Model ram specific.docx (21K) > <http://r.789695.n4.nabble.com/attachment/4685052/0/Model%20ram%20speci > fic.docx> > CC32.Rdata (20K) > <http://r.789695.n4.nabble.com/attachment/4685052/1/CC32.Rdata> > C32.Rdata (17K) > <http://r.789695.n4.nabble.com/attachment/4685052/2/C32.Rdata> > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Help-with- > SEM-Error-in-1-m-NA-NaN-argument-tp4685052.html > Sent from the R help mailing list archive at Nabble.com. > [[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 guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.