Skip to contents

Easily compute simple slopes in moderation analysis, with effect sizes, and format in publication-ready format.

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

Usage

nice_slopes(
  data,
  response,
  predictor,
  moderator,
  moderator2 = NULL,
  covariates = NULL,
  b.label,
  mod.id = TRUE,
  ...
)

Arguments

data

The data frame

response

The dependent variable.

predictor

The independent variable

moderator

The moderating variable.

moderator2

The second moderating variable, if applicable.

covariates

The desired covariates in the model.

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_mod, nice_lm, nice_lm_slopes. Tutorial: https://rempsyc.remi-theriault.com/articles/moderation

Examples

# Make the basic table
nice_slopes(
  data = mtcars,
  response = "mpg",
  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

# Multiple dependent variables at once
nice_slopes(
  data = mtcars,
  response = c("mpg", "disp", "hp"),
  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               disp       gear (LOW-wt) 28  50.510710  0.6654856
#> 5            2               disp      gear (MEAN-wt) 28  35.797623  0.6121820
#> 6            2               disp      gear (HIGH-wt) 28  21.084536  0.5067498
#> 7            3                 hp       gear (LOW-wt) 28 -21.687555 -0.3482182
#> 8            3                 hp      gear (MEAN-wt) 28  -7.461189 -0.1554963
#> 9            3                 hp      gear (HIGH-wt) 28   6.765177  0.1981502
#>            p          sr2
#> 1 0.05408136 0.0304844847
#> 2 0.06204275 0.0284883047
#> 3 0.08336403 0.0243112307
#> 4 0.51118526 0.0032346367
#> 5 0.54535707 0.0027372180
#> 6 0.61629796 0.0018755795
#> 7 0.73028083 0.0019485684
#> 8 0.87754563 0.0003885555
#> 9 0.84435922 0.0006309595

# Add covariates
nice_slopes(
  data = mtcars,
  response = "mpg",
  predictor = "gear",
  moderator = "wt",
  covariates = c("am", "vs")
)
#>   Dependent Variable Predictor (+/-1 SD) df        b        t          p
#> 1                mpg       gear (LOW-wt) 26 7.891888 2.211309 0.03601159
#> 2                mpg      gear (MEAN-wt) 26 5.840594 2.077348 0.04778660
#> 3                mpg      gear (HIGH-wt) 26 3.789301 1.815690 0.08096849
#>          sr2
#> 1 0.02824004
#> 2 0.02492212
#> 3 0.01903925

# Three-way interaction (continuous moderator and binary
# second moderator required)
nice_slopes(
  data = mtcars,
  response = "mpg",
  predictor = "gear",
  moderator = "wt",
  moderator2 = "am"
)
#>   Dependent Variable am Predictor (+/-1 SD) df         b          t          p
#> 1                mpg  0       gear (LOW-wt) 24 67.737763  1.8085806 0.08306317
#> 2                mpg  0      gear (MEAN-wt) 24 52.970093  1.8315641 0.07945785
#> 3                mpg  0      gear (HIGH-wt) 24 38.202424  1.8731910 0.07327171
#> 4                mpg  1       gear (LOW-wt) 24 -7.526458 -0.9092225 0.37227347
#> 5                mpg  1      gear (MEAN-wt) 24 -5.862384 -0.9829465 0.33543976
#> 6                mpg  1      gear (HIGH-wt) 24 -4.198309 -1.1312335 0.26913442
#>           sr2
#> 1 0.016188137
#> 2 0.016602191
#> 3 0.017365419
#> 4 0.004091302
#> 5 0.004781684
#> 6 0.006333236