Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparability of R2 Values in MLMs with Time as a Factor vs. Time as a Numeric Variable #65

Open
LudvigWR opened this issue Sep 22, 2023 · 2 comments

Comments

@LudvigWR
Copy link

Hi,

I'm currently trying to calculate R2 for my three-level MLM using the r2mlm3_manual() function. The problem I have is that one of my predictors, "Time" (Pre, Post & Follow up measurements measured at different time intervals), needs to be a factor variable for interpretative reasons.

My question is (and I realize this might be a bit far fetched): If I change "Time" into a numeric variable, will the output from r2mlm3_manual() be comparable in any way to my original MLM where "Time" is a factor? In other words, will the output from r2mlm3_manual() provide additional explanatory value, or will it simply describe a "different" model?

I'm aware of how "Time" as a numerical variable changes the MLM summary results (but not how this relates to the R2s).

My model looks something like this:
lmer(Outcome ~ A* Time + B + C + (1 | Group/Subject_ID), data = long_data, REML = FALSE)

The interaction term A*Time is the focus of my research question.

Many thanks,
Ludvig

@mkshaw
Copy link
Owner

mkshaw commented Sep 22, 2023

Hi Ludvig,

The r2mlm function doesn't "know" what your variables are, it just looks at the variance of your outcome explained by your different predictors/random effects. Is your plan here to re-run your MLM with time as a numeric variable, or to run it with time as a factor and then just change the column "time" to be numeric only for r2mlm3_manual?

If you run your model with time as a numeric variable and your results change, and you use those different results in r2mlm, you'll get different R2 values than you would if you ran the model with time as a factor.

If you run your model with time as a factor and use those results for r2mlm, but just change the column in the dataset to be numeric when using r2mlm (so your MLM results haven't changed at all, time is still a factor for those results), that shouldn't affect the R2 values.

Is what I'm saying clear?

Mairead

@LudvigWR
Copy link
Author

Hi Mairead,

Thank you for your reply.

I ran the MLM now with time as a factor variable, and then tried to input this data into r2mlm3_manual.
The problem I run into is with the input of the estimates in gamma_1.
With time as a factor in the MLM you get two estimates for the variable time (one for post, and one for follow up).

Is this fixable you think, or does this mean it might not be possible to use r2mlm3_manual in my case? (since I need to keep time as a factor variable)

Summary(model)
...
Time(post): 5
Time (follow up): 12
...

r2mlm3_manual(
...
l1_covs = c("Time"),
...
gamma_1 = c(?),
...)

/Ludvig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants