Description Usage Arguments Details Value See Also Examples
View source: R/plot_interaction.r
The function plot_interaction
provides interaction plots for linear regression models or linear fixed effects models. For linear models, the user can provide a cluster variable to cluster the standard errors and can select to use bootstraping for clustering.
1 | plot_interaction(input, iv, moderator, ci = 0.9, type = 0, var_cluster = NULL)
|
input |
Object of class "mod_vcov", linear model of class "lm" or "glm", or linear fixed effects model of class "lmerMod" or "glmerMod" |
iv |
|
moderator |
|
ci |
Confidence interval shown in interaction plot - must be numeric between 0 and 1 |
type |
Indicator which type of standard errors is to be computed: 0 - no clustering, 1 - clustering using |
var_cluster |
Vector, matrix, or data.frame containing the variables that are used for clustering |
For input of class "lm" or "glm" the function uses cplot
from the margins
package to prepare the interaction plot. For input of class "lmerMod" and "glmerMod" the funciton uses interplot
from the interplot
package to prepare the interaction plot. For input of class "lm" or "glm" the options type == 0
, type == 1
, and type == 2
control how the variance-covariance matrix for standard error estimation is computed. The options type == 1
and type == 2
require a cluster variable defined in var_cluster
.
Interaction plot as ggplot2
object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | data <- supportR::create_data()
mod1 <- lm(firm_value ~ profit + cogs + rnd + competition * board_size, data = data)
mod1_vcov <- model_vcov(model = mod1, type = 1, var_cluster = data$country)
plot_interaction(input = mod1_vcov, iv = "competition", moderator = "board_size", ci = 0.9)
plot_interaction(input = mod1, iv = "competition", moderator = "board_size", ci = 0.9, type = 0, var_cluster = NULL)
mod2 <- glm(female_ceo ~ profit + cogs + rnd + ceo_age * board_size, data = data, family = "binomial")
plot_interaction(input = mod2, iv = "ceo_age", moderator = "board_size", ci = 0.9, type = 2, var_cluster = data$industry)
mod3 <- lme4::lmer(firm_value ~ profit + cogs + rnd + competition * board_size + (1 | country), data = data)
plot_interaction(input = mod3, iv = "competition", moderator = "board_size", ci = 0.9)
mod4 <- lme4::glmer(female_ceo ~ profit + cogs + rnd + ceo_age * board_size + (1 | industry), data = data, family = "binomial")
plot_interaction(input = mod4, iv = "ceo_age", moderator = "board_size", ci = 0.9)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.