Mouse-Imaging-Centre / RMINC

Statistics for MINC volumes: A library to integrate voxel-based statistics for MINC volumes into the R environment. Supports getting and writing of MINC volumes, running voxel-wise linear models, correlations, etc.; correcting for multiple comparisons using the False Discovery Rate, and more. With contributions from Jason Lerch, Chris Hammill, Jim Nikelski and Matthijs van Eede. Some additional information can be found here:
https://mouse-imaging-centre.github.io/RMINC
Other
23 stars 17 forks source link

Problem running mincLm with covariates #322

Open christianlimberger opened 4 months ago

christianlimberger commented 4 months ago

I am trying to run mincLm, but I'm encountering an error that only occurs when I include covariates. This is strange because the same error is happening with other codes that previously worked perfectly.

> df_fdg <- read.csv("final_merge-model.csv")
> df_fdg$APOE4 <- as.factor(df_fdg$APOE4)
> df_fdg$PTGENDER <- as.factor(df_fdg$PTGENDER)
> df_fdg$ABETA <- as.numeric(df_fdg$ABETA)
> df_fdg$PTAU <- as.numeric(df_fdg$PTAU)
> df_fdg$AGE <- as.numeric(df_fdg$AGE)
> df_fdg_CU <- filter(df_fdg, DX == "CU")
> df_fdg_CU$AGE <- scale(df_fdg_CU$AGE)[,1]
> df_fdg_CU$ABETA <- scale(df_fdg_CU$ABETA)[,1]
> df_fdg_CU$PTAU <- scale(df_fdg_CU$PTAU)[,1]
> df_fdg_CU$snp <- factor(df_fdg_CU$snp, levels = c("noncarrier", "carrier"))
> lm1 <- mincLm(FDG_path ~ snp + APOE4 + PTGENDER + AGE + ABETA + PTAU, data = df_fdg_CU, mask = "adni_space.mnc")
Error in formula[[3]][[nTerm]] > 1 :
comparison (>) is not possible for language types
gdevenyi commented 4 months ago

First, you can directly use the scale() function inside the RMINC equation, which is probably more clear for the latest outputs.

I suggest you try each covariate individually, something about the structure of one of your columns isn't as expected.

christianlimberger commented 4 months ago

Thank you Gabriel, I already tried putting scale() inside the function, and also testing each covariate individually, but only got the function running without any covariate...

gdevenyi commented 4 months ago

ok, something about your data is very messed up then. Please provide some kind of view of the df_fdg_CU object.

christianlimberger commented 4 months ago

image

gdevenyi commented 4 months ago

Ok. Lets look at a few more things.

Given this model is your goal,

> lm1 <- mincLm(FDG_path ~ snp + APOE4 + PTGENDER + AGE + ABETA + PTAU, data = df_fdg_CU, mask = "adni_space.mnc")

Can you successfully run

>  lm1 <- mincLm(FDG_path ~ <SINGLE PREDICTOR>, data = df_fdg_CU, mask = "adni_space.mnc")

For each of these columns successfully?

christianlimberger commented 4 months ago

yes! The problem is when I put any covariate

gdevenyi commented 4 months ago

Okay, lets pare down this to a minimum failing example.

Can you please choose a simple two-predictor model, run it without the mask option, and after the error, run traceback() and provide the full output.

In addition, please provide your sessionInfo()