1
votes

I am trying to extract the slope and intercept for each of my groups from my linear mixed effects models. The model was constructed using lmer in the lme4 library, and I can view the results for each group using interact_plot from the jtools library. How do I get the slope and intercept for each of these lines?

I know that I can use the summary() or summ() to see the estimates for the fixed effects and the variances of the random effects but I cannot see the estimates of the random effects. Therefore, I cannot accurately calculate the slope and intercepts of the models.

>library(lme4)
> cond_waterxsilver <- lmer(LnAg ~ LnVolume + (LnVolume | FilterID) + SilverType + WaterType + SilverType*WaterType + SilverType*LnVolume +  WaterType*LnVolume, data=capwater_removed.data)


> library(jtools)
> interact_plot(cond_ranin_waterxsilver, pred = LnVolume, modx = WaterType, mod2 = SilverType)

I am just trying to get the slope and intercepts for the six lines from the model (two different WaterType and three different SilverType). Is there a tool within jtools or another package that can help me with extracting the slope and intercepts from my model?

1

1 Answers

1
votes

I'm the developer of this package!

A short note: this and the other function I'm going to mention have just been moved to a new package, called interactions, which is in the process of being added to CRAN. Assuming you haven't updated to the newest version of jtools (2.0.0; just came out days ago), these functions are still available in the jtools package. If you do update to jtools 2.0.0, you'll need to follow this link for instructions on how to download interactions before it gets to CRAN.

There should be a simple answer to your question. The sim_slopes (short for "simple slopes") function should give you what you're looking for.

sim_slopes(cond_ranin_waterxsilver, pred = LnVolume, modx = WaterType, mod2 = SilverType, cond.int = TRUE)

This will print out the conditional slopes and intercepts (the intercepts are only printed when cond.int = TRUE.

If you need to program with those values, you can save the sim_slopes object.

ss <- sim_slopes(cond_ranin_waterxsilver, pred = LnVolume, modx = WaterType, mod2 = SilverType, cond.int = TRUE)

ss$slopes # Matrix of slopes with test statistics, etc.
ss$ints # Matrix of intercepts with test statistics, etc.