r2mlm icon indicating copy to clipboard operation
r2mlm copied to clipboard

Error: Your data must be numeric

Open YouriLMora opened this issue 4 years ago • 5 comments

Hey,

Thanks a lot for this package !

I get the following error message though : image

All the independent variables in the model are factors, except for the participants (numeric) image

The depedent variable (rt.log) is also numeric.

Maybe my way of typing the model is not appropriate for pulling the variables ?

model.dt.r2 = lmer(rt.log ~ bloc.GFL * bloc.congruence + (bloc.GFL + bloc.congruence|participant) + (condition.congruence.first + bloc.GFL), data = dt.r2, REML=FALSE)

YouriLMora avatar Oct 15 '20 09:10 YouriLMora

A solution I found was to convert all variables (even IVs) as numeric. It appears that even the variable cluster cannot be factors ?

YouriLMora avatar Oct 15 '20 12:10 YouriLMora

Thanks for bringing this to my attention! I'll take a look and post updates here as I solve the issue.

mkshaw avatar Oct 15 '20 13:10 mkshaw

Hello! I'm getting the same error -- I have a mix of continuous (numeric) and factor-level variables as predictors in my model. The outcome (DV) is continuous. Curious if there are any updates on this!

Michaeladebolt avatar Nov 12 '20 18:11 Michaeladebolt

Hello! For now, you would need to manually change your factor-level predictors to numerical variables (except the clustering variable, which you can leave as a factor.) Let me know if you try that, and if it works or you run into a different issue.

I recognize the usefulness and interest in allowing the model to accept factors as predictors, and plan to incorporate it in future versions of the package. But for now, the package isn't build to deal with factor variables as predictors. This error it generates -- "Your data must be numeric. Only the cluster variable can be a factor." -- is generated on purpose, it's not the code making a mistake.

mkshaw avatar Nov 12 '20 19:11 mkshaw

Hi, all of my predictors are numeric and I am encountering this issue. My syntax is posted below. For what it's worth, the interaction terms are computed in the model but they are not separate variables in the dataset (i.e., there is no column for stigma_wp*CORE_c). However, I ran a simplified model with no interaction terms, and the same issue came up. The asterisks in the below model are spaced out for formatting issues; they are next to each other in R.

total <- lmerTest::lmer(WAI_Total ~ 1 + Session_c + stigma_c * CORE_c + stigma_c * CORE_wp + stigma_wp * CORE_c + stigma_wp * CORE_wp + (1|UniqueID), data = threesessions_noNA, na.action=na.omit, REML=FALSE, control=lmerControl(optimizer="Nelder_Mead",optCtrl=list(maxfun=2e5))) r2mlm(total)

data.frame': 177 obs. of 6 variables: $ UniqueID : num $ Session_c: num $ WAI_Total: num . $ CORE_c : num [1:177, 1] ..- attr(, "scaled:center") $ CORE_wp : num $ stigma_c : num ..- attr(, "scaled:center") $ stigma_wp: num

serpentislord avatar Aug 30 '22 18:08 serpentislord