Learn R Programming

regrrr (Toolkit for Compiling and Plotting Regression Results)

Description

Compiling regression results into a publishable format, conducting post-hoc hypothesis testing, and plotting moderating effects (the effect of X on Y becomes stronger/weaker as Z increases).

Installation

To install from CRAN:

install.packages("regrrr")
library(regrrr)

You can also use devtools to install the latest development version:

devtools::install_github("RkzYang/regrrr")
library(regrrr)

Examples

# build regression models using mtcars dataset
data(mtcars)
m0 <- lm(mpg ~ vs + carb + hp + wt, data = mtcars)
m1 <- update(m0, . ~ . + wt * hp)
m2 <- update(m1, . ~ . + wt * vs)
# compile the correlation table
cor.table(data = m2$model)
# compile the regression table
regression_table <- rbind(
combine_long_tab(to_long_tab(summary(m0)$coef),
                 to_long_tab(summary(m1)$coef),
                 to_long_tab(summary(m2)$coef)),
compare_models(m0, m1, m2))
rownames(regression_table) <- NULL
print(regression_table)
# plot the moderating effect
plot_effect(reg.coef = summary(m2)$coefficients, data = mtcars, model = m2,
            x_var.name = "wt", y_var.name = "mpg", moderator.name = "hp",
            confidence_interval = TRUE,  CI_Ribbon = FALSE, 
            xlab = "Weight", ylab = "MPG", moderator.lab = "Horsepower") +
ggplot2::theme(text=ggplot2::element_text(family="Times New Roman", size = 16))
# plot the moderating effect with a linear spline
library(lspline)
m3 <- lm(mpg ~ vs + carb + hp + lspline(wt, knots = 4, marginal = FALSE) * hp, data = mtcars)
plot_effect(reg.coef=summary(m3)$coefficients, data = mtcars, model = m3, 
            x_var.name = "wt", y_var.name = "mpg", moderator.name = "hp",
            xlab="Weight", ylab="MPG", moderator.lab="Horsepower") +
ggplot2::theme(text=ggplot2::element_text(family="Times New Roman", size = 16))

Copy Link

Version

Install

install.packages('regrrr')

Monthly Downloads

164

Version

0.1.3

License

GPL-3

Maintainer

Last Published

August 13th, 2021

Functions in regrrr (0.1.3)

test_tilted_slopes

significance of regression slope (the marginal effect) under moderation testing restriction: the sig. of beta_x under the moderation of z1, with or without additional interaction terms (z2, z3, etc.)
test_coef_equality

testing equality of two coefficients (difference between coefficients of regressors), a Wald test note: if v is not alternatively specified, use car::linearHypothesis(lm_model, "X1 = X2")
scale_01

Scale a vector into the 0-1 scale
to_long_tab

Convert the regression result to the long format: the standard errors are in parentheses and beneath the betas
plot_effect

plotting the marginal effect of X on Y, with or without one or multiple interaction terms
check_vif

quickly check the vifs in a regression model; for checking multi-collinearity
regrrr

regrrr: a toolkit for compiling regression results
cor.table

make the correlation matrix from the data.frame used in regression
combine_long_tab

Combine regression results from different models by columns
add.n.r

Add row numbers to regression result data.frame
add.sig

Add significance level marks to the regression result
add.pr

Add approximate p-value based on t score or z score, when sample size is large
check_na_in

quickly check the proportion of NAs in each columns of a dataframe
check_cor

quickly check correlation matrix, or the correlation between a particular X and all other vars could be useful for looking for relevant instrument
compare_models

Compare regression models, which is compatible with the reg.table output # updated 9/13/2018 #
load.pkgs

load multiple packages