DejanDraschkow / mixedpower

GNU General Public License v3.0
16 stars 13 forks source link

Random factors as numeric #9

Closed jgeller112 closed 6 months ago

jgeller112 commented 1 year ago

In the help documents it references the random variable as a character vector but throws an error when factor is not numeric. Can this be changed? In most cases my random vars are factors/chars not numeric (I have a feeling this is the case for most users).

ConnorEsterwood commented 1 year ago

I'm also having this issue where I have a categorical random variable (subjectID) for a repeated measures study design. The error code I'm getting is:

"simvar" needs to be numeric. Consider creating a numeric dummy variable.

This would be impractical for my case as it would require me to make a column for each subject if I'm interpreting that right. As far as I can tell random variables (i.e. random effects) can be categorical so why is it not permitted in this analysis?

I see where this error is coming from in the

# ------------------------------- check_input ---------------------------------#

section of the utility side of things but I'm sure there is a good reason ... just not sure what it is.

-CTE

jgeller112 commented 1 year ago

The main issue here is that it is an extra step.

Let's say participant is your varying factor: you can change your random effect to numeric like so:


data$PID <- as.numeric(factor(data$Sub.ID,levels=unique(data$Sub.ID))) 
ConnorEsterwood commented 1 year ago

Nice! yeah, I ended up doing the following to get my dummy variables:

Model_Data <- transform(Model_Data,
                ID = as.numeric(factor(Subject_ID))) 
lkumle commented 6 months ago

Hi everyone, thanks for the feedback! This seems like an appropriate update for the next version of mixedpower. In the meantime, the solutions offered in this thread are great workarounds.