Learn R Programming

modelbased (version 0.6.0)

estimate_contrasts.lm: Estimate contrasts

Description

Estimate contrasts

Usage

# S3 method for lm
estimate_contrasts(
  model,
  levels = NULL,
  fixed = NULL,
  modulate = NULL,
  transform = "none",
  length = 10,
  standardize = TRUE,
  standardize_robust = FALSE,
  ci = 0.95,
  adjust = "holm",
  ...
)

Arguments

model

A Bayesian model.

levels

A character vector or formula specifying the names of the predictors over which to estimate means or contrasts.

fixed

A character vector indicating the names of the predictors to be "fixed" (i.e., maintained), so that the estimation is made at these values.

modulate

A character vector indicating the names of a numeric variable along which the means or the contrasts will be estimated. Adjust its length using length.

transform

Can be "none" (default for contrasts), "response" (default for means), "mu", "unlink", "log". "none" will leave the values on scale of the linear predictors. "response" will transform them on scale of the response variable. Thus for a logistic model, "none" will give estimations expressed in log-odds (probabilities on logit scale) and "response" in terms of probabilities.

length

Length of the spread numeric variables.

standardize

If TRUE, adds standardized differences or coefficients.

standardize_robust

Robust standardization through MAD (Median Absolute Deviation, a robust estimate of SD) instead of regular SD.

ci

Credible Interval (CI) level. Default to 0.89 (89%). See ci for further details.

adjust

The p-values adjustment method for multi-comparisons. Can be one of "holm" (default), "tukey", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr" or "none". See the p-value adjustment section in the emmeans::test documentation.

...

Arguments passed to or from other methods.

Value

A dataframe of estimated contrasts.

Examples

Run this code
# NOT RUN {
library(modelbased)

model <- lm(Sepal.Width ~ Species, data = iris)
estimate_contrasts(model)

model <- lm(Sepal.Width ~ Species * Petal.Width, data = iris)
estimate_contrasts(model)
estimate_contrasts(model, fixed = "Petal.Width")
estimate_contrasts(model, modulate = "Petal.Width", length = 4)
estimate_contrasts(model, levels = "Petal.Width", length = 4)

if (require("lme4")) {
  data <- iris
  data$Petal.Length_factor <- ifelse(data$Petal.Length < 4.2, "A", "B")

  model <- lmer(Sepal.Width ~ Species + (1 | Petal.Length_factor), data = data)
  estimate_contrasts(model)
}
# }

Run the code above in your browser using DataLab