Skip to contents

Easily compute moderation analyses, 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_mod(
  data,
  response,
  predictor,
  moderator,
  moderator2 = NULL,
  covariates = NULL,
  b.label = "b",
  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 simple slopes after testing for moderation: nice_slopes, nice_lm, nice_lm_slopes. Tutorial: https://rempsyc.remi-theriault.com/articles/moderation

Examples

# Make the basic table
nice_mod(
  data = mtcars,
  response = "mpg",
  predictor = "gear",
  moderator = "wt"
)
#>   Dependent Variable Predictor df         b          t          p         sr2
#> 1                mpg      gear 28  5.615951  1.9437108 0.06204275 0.028488305
#> 2                mpg        wt 28  1.403861  0.4301493 0.67037970 0.001395217
#> 3                mpg   gear:wt 28 -1.966931 -2.1551077 0.03989970 0.035022025

# Multiple dependent variables at once
nice_mod(
  data = mtcars,
  response = c("mpg", "disp", "hp"),
  predictor = "gear",
  moderator = "wt"
)
#>   Model Number Dependent Variable Predictor df          b          t          p
#> 1            1                mpg      gear 28   5.615951  1.9437108 0.06204275
#> 2            1                mpg        wt 28   1.403861  0.4301493 0.67037970
#> 3            1                mpg   gear:wt 28  -1.966931 -2.1551077 0.03989970
#> 4            2               disp      gear 28  35.797623  0.6121820 0.54535707
#> 5            2               disp        wt 28 160.930043  2.4364098 0.02144867
#> 6            2               disp   gear:wt 28 -15.037022 -0.8140664 0.42247646
#> 7            3                 hp      gear 28  -7.461189 -0.1554963 0.87754563
#> 8            3                 hp        wt 28  11.253239  0.2076235 0.83702568
#> 9            3                 hp   gear:wt 28  14.539586  0.9592587 0.34563902
#>            sr2
#> 1 0.0284883047
#> 2 0.0013952173
#> 3 0.0350220247
#> 4 0.0027372180
#> 5 0.0433559718
#> 6 0.0048402513
#> 7 0.0003885555
#> 8 0.0006927326
#> 9 0.0147871391

# Add covariates
nice_mod(
  data = mtcars,
  response = "mpg",
  predictor = "gear",
  moderator = "wt",
  covariates = c("am", "vs")
)
#>   Dependent Variable Predictor df         b          t           p         sr2
#> 1                mpg      gear 26  5.840594  2.0773482 0.047786602 0.024922116
#> 2                mpg        wt 26  3.433057  1.1692031 0.252929701 0.007894893
#> 3                mpg        am 26  1.578465  0.8569286 0.399314133 0.004240876
#> 4                mpg        vs 26  3.817509  3.2441426 0.003228614 0.060780767
#> 5                mpg   gear:wt 26 -2.096457 -2.5615471 0.016567730 0.037894048

# Three-way interaction
nice_mod(
  data = mtcars,
  response = "mpg",
  predictor = "gear",
  moderator = "wt",
  moderator2 = "am"
)
#>   Dependent Variable  Predictor df         b         t          p        sr2
#> 1                mpg       gear 24  52.97009  1.831564 0.07945785 0.01660219
#> 2                mpg         wt 24  42.12157  1.603869 0.12182331 0.01273090
#> 3                mpg         am 24 202.38995  2.216085 0.03641826 0.02430490
#> 4                mpg    gear:wt 24 -15.09281 -1.729114 0.09663310 0.01479682
#> 5                mpg    gear:am 24 -58.83248 -1.992346 0.05782588 0.01964494
#> 6                mpg      wt:am 24 -58.67147 -2.053052 0.05112221 0.02086032
#> 7                mpg gear:wt:am 24  16.79352  1.854357 0.07601677 0.01701798