if (FALSE) { # require("emmeans", quietly = TRUE)
# Basic usage
model <- lm(Sepal.Width ~ Species, data = iris)
estimate_contrasts(model)
# Dealing with interactions
model <- lm(Sepal.Width ~ Species * Petal.Width, data = iris)
# By default: selects first factor
estimate_contrasts(model)
# Can also run contrasts between points of numeric
estimate_contrasts(model, contrast = "Petal.Width", length = 4)
# Or both
estimate_contrasts(model, contrast = c("Species", "Petal.Width"), length = 2)
# Or with custom specifications
estimate_contrasts(model, contrast = c("Species", "Petal.Width=c(1, 2)"))
# Can fixate the numeric at a specific value
estimate_contrasts(model, fixed = "Petal.Width")
# Or modulate it
estimate_contrasts(model, at = "Petal.Width", length = 4)
# Standardized differences
estimated <- estimate_contrasts(lm(Sepal.Width ~ Species, data = iris))
standardize(estimated)
}
if (FALSE) { # require("lme4", quietly = TRUE) && require("emmeans", quietly = TRUE)
# Other models (mixed, Bayesian, ...)
data <- iris
data$Petal.Length_factor <- ifelse(data$Petal.Length < 4.2, "A", "B")
model <- lme4::lmer(Sepal.Width ~ Species + (1 | Petal.Length_factor), data = data)
estimate_contrasts(model)
}
if (FALSE) { # require("rstanarm", quietly = TRUE) && require("emmeans", quietly = TRUE)
library(rstanarm)
# \donttest{
data <- mtcars
data$cyl <- as.factor(data$cyl)
data$am <- as.factor(data$am)
model <- stan_glm(mpg ~ cyl * am, data = data, refresh = 0)
estimate_contrasts(model)
estimate_contrasts(model, fixed = "am")
model <- stan_glm(mpg ~ cyl * wt, data = data, refresh = 0)
estimate_contrasts(model)
estimate_contrasts(model, fixed = "wt")
estimate_contrasts(model, at = "wt", length = 4)
model <- stan_glm(Sepal.Width ~ Species + Petal.Width + Petal.Length, data = iris, refresh = 0)
estimate_contrasts(model, at = "Petal.Length", test = "bf")
# }
}
Run the code above in your browser using DataLab