mkshaw / r2mlm

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

Interaction and higher-order terms. #4

Closed mkshaw closed 4 years ago

mkshaw commented 4 years ago

Users currently have to create separate variables for interaction terms (like data$x1x2 = data$x1 * data$x2). We want to allow users to use lmer's/nlme's syntax to create such predictors.

mkshaw commented 4 years ago

(1) Iterate through the terms in the model with attr(terms(model), "term.labels") and a for loop. (2) For each term, run grepl(":", term, fixed = TRUE) (3) If grepl returns true, then that term is an interaction, and you would want to further sort by whether either of the words is in l2_vars. If yes, add the interaction to l2_vars, else add it to l1_vars.

Things to consider downstream: how will clustermeancentered be impacted by an interaction term being included in l1_vars? Might have to check clustermeancentered before allocating interaction terms, because the interaction won't have a column in the dataset.

mkshaw commented 4 years ago

Successfully found and sorted interaction terms, but right now adding them to the data frame is giving me some issues. Next up: how to add "extravCWC:texp" as the variable name to the dataframe (because within() later pulls the column number from the data frame by indexing the variable names stored in l1_vars, and "extravCWC:texp" is what's stored in l1_vars.