Dear all, I am not able to find a reliable r code to run a multilevel latent class model. Indeed, I have to analyze how social trust (three variables form the ESS survey) might vary between countries (21 countries in my database). I tried to use the poLCA package but I am not sure if my code is right. This is my code: lca <- cbind(ppltrst+1,pplfair+1,pplhlp+1)~cntry lc <- poLCA(lca,mydata) However, I get an error message: Error in `[.data.frame`(data, , match(colnames(y), colnames(data))[j]) : undefined columns selected How can I solve this? Is the code completely wrong or I missed some passages? Thank you very much for your help! Cristina [[alternative HTML version deleted]]
start at https://github.com/ajdamico/asdfree/blob/master/European%20Social%20Survey/structural%20equation%20modeling%20examples.R maybe? On Thu, Jul 7, 2016 at 6:26 AM, Cristina Cametti <cristina.cametti at gmail.com> wrote:> Dear all, > > I am not able to find a reliable r code to run a multilevel latent class > model. Indeed, I have to analyze how social trust (three variables form the > ESS survey) might vary between countries (21 countries in my database). I > tried to use the poLCA package but I am not sure if my code is right. This > is my code: > lca <- cbind(ppltrst+1,pplfair+1,pplhlp+1)~cntry > lc <- poLCA(lca,mydata) > > However, I get an error message: > Error in `[.data.frame`(data, , match(colnames(y), colnames(data))[j]) : > undefined columns selected > > How can I solve this? Is the code completely wrong or I missed some > passages? > Thank you very much for your help! > > Cristina > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >[[alternative HTML version deleted]]
Hi Cristina, Try this: names(mydata) It may be NULL or "ppitrst" may be absent. Jim On Thu, Jul 7, 2016 at 8:26 PM, Cristina Cametti <cristina.cametti at gmail.com> wrote:> Dear all, > > I am not able to find a reliable r code to run a multilevel latent class model. Indeed, I have to analyze how social trust (three variables form the ESS survey) might vary between countries (21 countries in my database). I tried to use the poLCA package but I am not sure if my code is right. This is my code: > lca <- cbind(ppltrst+1,pplfair+1,pplhlp+1)~cntry > lc <- poLCA(lca,mydata) > > However, I get an error message: > Error in `[.data.frame`(data, , match(colnames(y), colnames(data))[j]) : > undefined columns selected > > How can I solve this? Is the code completely wrong or I missed some passages? > Thank you very much for your help! > > Cristina > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
> On Jul 7, 2016, at 3:36 PM, Jim Lemon <drjimlemon at gmail.com> wrote: > > Hi Cristina, > Try this: > > names(mydata) > > It may be NULL or "ppitrst" may be absent.I've already suggested to Christina that she make sure the variables are spelled correctly and she reports they are all present in her dataset. So I tried a formula such as she posed with '1' added to each variable and this does throw the same error with the 'values'-dataframe that is used in the examples for that package.> data(values,package='poLCA') > str(values)'data.frame': 216 obs. of 4 variables: $ A: num 2 2 2 2 2 2 2 2 2 2 ... $ B: num 2 2 2 2 2 2 2 2 2 2 ... $ C: num 2 2 2 2 2 2 2 2 2 2 ... $ D: num 2 2 2 2 2 2 2 2 2 2 ...> library(poLCA)Loading required package: scatterplot3d Loading required package: MASS> poLCA( cbind(A+1,B+1) ~ C, data=values)Error in `[.data.frame`(data, , match(colnames(y), colnames(data))[j]) : undefined columns selected So I then tried removeing those "+1`"'s (which didn't seem to have much justification):> poLCA( cbind(A,B) ~ C, data=values)Conditional item response (column) probabilities, by outcome variable, for each class (row) $A Pr(1) Pr(2) class 1: 0.3428 0.6572 class 2: 0.0307 0.9693 $B Pr(1) Pr(2) class 1: 0.7737 0.2263 class 2: 0.1386 0.8614 snipped the rest of the output. So "why add 1?" Seems to disturb the functions formula processing logic and is so far not explained. -- David.> > Jim > > > On Thu, Jul 7, 2016 at 8:26 PM, Cristina Cametti > <cristina.cametti at gmail.com> wrote: >> Dear all, >> >> I am not able to find a reliable r code to run a multilevel latent class model. Indeed, I have to analyze how social trust (three variables form the ESS survey) might vary between countries (21 countries in my database). I tried to use the poLCA package but I am not sure if my code is right. This is my code: >> lca <- cbind(ppltrst+1,pplfair+1,pplhlp+1)~cntry >> lc <- poLCA(lca,mydata) >> >> However, I get an error message: >> Error in `[.data.frame`(data, , match(colnames(y), colnames(data))[j]) : >> undefined columns selected >> >> How can I solve this? Is the code completely wrong or I missed some passages? >> Thank you very much for your help! >> >> Cristina >> [[alternative HTML version deleted]] >>David Winsemius Alameda, CA, USA