Skip to contents

Extracts simple slopes from lm model object and format for a publication-ready format.

Note: this function uses the modelEffectSizes function from the lmSupport package to get the sr2 effect sizes.

Usage

nice_lm_slopes(model, predictor, moderator, b.label = "b", mod.id = TRUE, ...)

Arguments

model

The model to be formatted.

predictor

The independent variable.

moderator

The moderating variable.

b.label

What to rename the default "b" column (e.g., to capital B if using standardized data for it to be converted to the Greek beta symbol in the nice_table function).

mod.id

Logical. Whether to display the model number, when there is more than one model.

...

Further arguments to be passed to the lm function for the models.

See also

Checking for moderation before checking simple slopes: nice_lm, nice_mod, nice_slopes. Tutorial: https://rempsyc.remi-theriault.com/articles/moderation

Examples

# Make and format model
model <- lm(mpg ~ gear * wt, mtcars)
nice_lm_slopes(model, predictor = "gear", moderator = "wt")
#>   Dependent Variable Predictor (+/-1 SD) df        b        t          p
#> 1                mpg       gear (LOW-wt) 28 7.540509 2.010656 0.05408136
#> 2                mpg      gear (MEAN-wt) 28 5.615951 1.943711 0.06204275
#> 3                mpg      gear (HIGH-wt) 28 3.691393 1.795568 0.08336403
#>          sr2
#> 1 0.03048448
#> 2 0.02848830
#> 3 0.02431123

# Make and format multiple models
model2 <- lm(qsec ~ gear * wt, mtcars)
my.models <- list(model, model2)
nice_lm_slopes(my.models, predictor = "gear", moderator = "wt")
#>   Model Number Dependent Variable Predictor (+/-1 SD) df         b          t
#> 1            1                mpg       gear (LOW-wt) 28  7.540509  2.0106560
#> 2            1                mpg      gear (MEAN-wt) 28  5.615951  1.9437108
#> 3            1                mpg      gear (HIGH-wt) 28  3.691393  1.7955678
#> 4            2               qsec       gear (LOW-wt) 28 -1.933515 -0.8847558
#> 5            2               qsec      gear (MEAN-wt) 28 -1.742853 -1.0351610
#> 6            2               qsec      gear (HIGH-wt) 28 -1.552191 -1.2956736
#>            p        sr2
#> 1 0.05408136 0.03048448
#> 2 0.06204275 0.02848830
#> 3 0.08336403 0.02431123
#> 4 0.38382325 0.02280057
#> 5 0.30945179 0.03121151
#> 6 0.20566798 0.04889790