r2mlm icon indicating copy to clipboard operation
r2mlm copied to clipboard

Can't subset columns that don't exist.

Open smasters11 opened this issue 4 years ago • 11 comments

Can't subset columns that don't exist. x Column na.exclude doesn't exist.

smasters11 avatar Oct 21 '20 17:10 smasters11

Hi @smasters11, can you provide me with some more information about your model and data? What's the structure of your dataset (run str(data)) and what model(s) you ran?

mkshaw avatar Oct 21 '20 19:10 mkshaw

I used hierarchical linear modeling (HLM) with the “nlme” package with maximum likelihood estimation. I do have some missing data points, so my code included “na.action=na.exclude” in my code. I don't know how to tell R that na.exlclude is not a column

smasters11 avatar Oct 21 '20 21:10 smasters11

Can you post your model definition here? For example, this is the model from the r2mlm documentation:

model_lme4 <- lmer(satisfaction ~ 1 + salary_c + control_c + salary_m + control_m + s_t_ratio + (1 + salary_c + control_c| schoolID), data = teachsat, REML = TRUE)

mkshaw avatar Oct 21 '20 21:10 mkshaw

energy3 <- lme(fixed = ZQ4.3 ~ ZQ4.2Gender + ZQ4.5Gender+ ZEnergyAgenticGender + ZEnergyComGender, data = data2, random = ~ 1 | School, na.action=na.exclude, method="ML")

smasters11 avatar Oct 21 '20 21:10 smasters11

Great, thanks for bringing this to my attention! I'll look into it.

mkshaw avatar Oct 21 '20 21:10 mkshaw

@smasters11 I think I've fixed this particular issue. Can you try installing the development version of the package by running devtools::install_github("mkshaw/r2mlm", ref = "refactoring"), then library(r2mlm), and then run your model again and see what you get?

mkshaw avatar Oct 21 '20 23:10 mkshaw

I really appreciate how hard you have been working on this! I got a different error this time. Error in r2mlm_nlme(model) : Your data must be numeric. Only the cluster variable can be a factor

smasters11 avatar Oct 22 '20 00:10 smasters11

Okay, cool, this error I'm more familiar with! See here: https://github.com/mkshaw/r2mlm/issues/22 Are your predictors (ZQ4.2Gender + ZQ4.5Gender+ ZEnergyAgenticGender + ZEnergyComGender) all numeric (not text-based)? And as you can see at the github issue linked above, it seems like some people are having issues where even their clustering variable (in your case, School) must be numeric. Let me know how that goes.

mkshaw avatar Oct 22 '20 01:10 mkshaw

All of my data looks like this:

image image

Capture

smasters11 avatar Oct 22 '20 02:10 smasters11

energy3 <- lme(fixed = ZQ4.3 ~ ZQ4.2_Gender + ZQ4.5_Gender+ ZEnergyAgentic_Gender + ZEnergyCom_Gender, data = data2, random = ~ 1 | School, na.action=na.exclude, method="ML")

@smasters11 What's going on here with the variables ZQ4.2_Gender and ZEnergyAgentic_Gender -- are those interaction variables normally in your function as ZQ4.2*Gender that just dropped the asterisk when you copied them over to regular text?

mkshaw avatar Oct 28 '20 19:10 mkshaw

@smasters11 Can you also share what operating system and version of R you're using? I just tried to replicate this error and couldn't.

mkshaw avatar Nov 30 '20 16:11 mkshaw