[BUG] olink_lmer not working with numeric main variables
joshielevy opened this issue · 2 comments
Describe the bug
If I specify a main variable that is numeric, it's failing the number_of_samples_w_more_than_one_level check, because the main variable is being added to the single_fixed_effects vector here:
if(!is.null(covariates)){
factors_in_df <- names(df)[sapply(df, is.factor)]
single_fixed_effects <- c(variable,
intersect(covariates,
factors_in_df))
}else{
single_fixed_effects <- variable
}
To Reproduce
Steps to reproduce the behavior:
try with a numeric variable
Expected behavior
should run without errors
reccomended fix
set single_fix_effects to not include numeric variables, for example:
single_fixed_effects <- setdiff(c(variable,
intersect(covariates,
factors_in_df)), num.vars)
Thanks for reaching out. When you say a numeric variable, do you mean a continuous variable or a categorical that is stored as number? Is this seen for only a fixed effect or any variable? Can you give me an example of the input you are running?
Hi Kathy - I was using a continuous variable. Here's an example:
I'm taking some real data I have - just the olink and identifier columns, then adding fake NPX and a fake continuous test_var:
fake_data$test_var <- rnorm(nrow(fake_data), 0, 10)
fake_data$visit_day <- sample(1:4, size = nrow(fake_data), replace = TRUE)
lmer_results <- olink_lmer(df = fake_data,
variable = c('test_var'),
random = 'visit_day',
return.covariates = TRUE,
verbose=TRUE
)
I get the following:
Error in withCallingHandlers({ :
There are 40 samples that do not have a unique level for the effect test_var. Only one level per sample is allowed.
If I run the same call but using the fix I mentioned above, I don't get that error.
If I were you I'd start with some real data and add the fake continuous variable, otherwise you'll get more errors...