nice_slopes: Easy simple slopes

View source: R/nice_slopes.R

nice_slopesR Documentation

Easy simple slopes

Description

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

Usage

nice_slopes(
  data,
  response,
  predictor,
  moderator,
  moderator2 = NULL,
  covariates = NULL,
  b.label = "b",
  standardize = TRUE,
  mod.id = TRUE,
  ci.alternative = "two.sided",
  ...
)

Arguments

data

The data frame

response

The dependent variable.

predictor

The independent variable

moderator

The moderating variable.

moderator2

The second moderating variable, if applicable. At this time, the second moderator variable can only be a binary variable of the form c(0, 1).

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). Now attempts to automatically detect whether the variables were standardized, and if so, sets b.label = "B" automatically. Factor variables or dummy variables (only two numeric values) are ignored when checking for standardization. This argument is now deprecated, please use argument standardize directly instead.

standardize

Logical, whether to standardize the data before fitting the model. If TRUE, automatically sets b.label = "B". Defaults to TRUE.

mod.id

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

ci.alternative

Alternative for the confidence interval of the sr2. It can be either "two.sided (the default in this package), "greater", or "less".

...

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

Details

The effect size, sr2 (semi-partial correlation squared, also known as delta R2), is computed through effectsize::r2_semipartial. Please read the documentation for that function, especially regarding the interpretation of the confidence interval. In rempsyc, instead of using the default one-sided alternative ("greater"), we use the two-sided alternative.

To interpret the sr2, use effectsize::interpret_r2_semipartial().

For the easystats equivalent, use report::report() on the lm() model object.

Value

A formatted dataframe of the simple slopes of the specified lm model, with DV, levels of IV, degrees of freedom, regression coefficient, t-value, p-value, and the effect size, the semi-partial correlation squared, and its confidence interval.

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"
)

# Multiple dependent variables at once
nice_slopes(
  data = mtcars,
  response = c("mpg", "disp", "hp"),
  predictor = "gear",
  moderator = "wt"
)

# Add covariates
nice_slopes(
  data = mtcars,
  response = "mpg",
  predictor = "gear",
  moderator = "wt",
  covariates = c("am", "vs")
)

# Three-way interaction (continuous moderator and binary
# second moderator required)
x <- nice_slopes(
  data = mtcars,
  response = "mpg",
  predictor = "gear",
  moderator = "wt",
  moderator2 = "am"
)
x


# Get interpretations
cbind(x, Interpretation = effectsize::interpret_r2_semipartial(x$sr2))


RemPsyc/rempsyc documentation built on June 23, 2024, 11:41 p.m.