mkshaw / r2mlm

r2mlm: R Package for Calculating R-Squared in Multilevel Models
27 stars 1 forks source link

Error: Your data must be numeric #22

Open YouriLMora opened 4 years ago

YouriLMora commented 4 years ago

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

YouriLMora commented 4 years ago

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

mkshaw commented 4 years ago

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

Michaeladebolt commented 3 years ago

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!

mkshaw commented 3 years ago

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.

serpentislord commented 2 years ago

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