Title: | Numeric and Visual Comparisons of Heterogeneity in Parametric Models |
---|---|
Description: | Performs statistical tests to compare coefficients and residual variance across models. Also provides graphical methods for assessing heterogeneity in coefficients and residuals. Currently supports linear models, generalized linear models, and their survey-weighted analogues. |
Authors: | Travis Loux [aut, cre], Cara Wiskow [aut] |
Maintainer: | Travis Loux <[email protected]> |
License: | GPL-3 |
Version: | 1.2.0 |
Built: | 2025-02-01 04:27:55 UTC |
Source: | https://github.com/tloux/paramhetero |
Create a ggplot forest plot of model coefficients with confidence intervals.
coefficient_forestplot( model_list, model_names = NULL, varlabs = NULL, conflevel = 0.95, horiz = TRUE )
coefficient_forestplot( model_list, model_names = NULL, varlabs = NULL, conflevel = 0.95, horiz = TRUE )
model_list |
A list of regression models. |
model_names |
A list of names for the regression models. |
varlabs |
A vector of labels for model variables. |
conflevel |
Confidence level for intervals. |
horiz |
Toggle whether confidence intervals are displayed horizontally or
vertically. Default is set to |
The forest plot groups variables along the axis determined by the horiz
parameter and colors the data by model. If model_names = NULL
, the
default, models are numbered sequentially in the order they appear in
model_list
(Model 1, Model 2, Model 3, etc.).
A ggplot object to compare model coefficient estimates with their corresponding confidence interval(s), grouped by coefficient.
states = as.data.frame(state.x77) m1 = lm(`Life Exp` ~ Income + Illiteracy, data=states, subset=state.region=='Northeast') m2 = lm(`Life Exp` ~ Income + Illiteracy, data=states, subset=state.region=='South') m3 = lm(`Life Exp` ~ Income + Illiteracy, data=states, subset=state.region=='North Central') m4 = lm(`Life Exp` ~ Income + Illiteracy, data=states, subset=state.region=='West') mList = list(m1, m2, m3, m4) coefficient_forestplot(model_list = mList, model_names =c('Northeast', 'South', 'North Central', 'West'), horiz = FALSE)
states = as.data.frame(state.x77) m1 = lm(`Life Exp` ~ Income + Illiteracy, data=states, subset=state.region=='Northeast') m2 = lm(`Life Exp` ~ Income + Illiteracy, data=states, subset=state.region=='South') m3 = lm(`Life Exp` ~ Income + Illiteracy, data=states, subset=state.region=='North Central') m4 = lm(`Life Exp` ~ Income + Illiteracy, data=states, subset=state.region=='West') mList = list(m1, m2, m3, m4) coefficient_forestplot(model_list = mList, model_names =c('Northeast', 'South', 'North Central', 'West'), horiz = FALSE)
Compare coefficient vectors, after removing intercept, across multiple models.
compare_coef_vectors(model_list)
compare_coef_vectors(model_list)
model_list |
A list of regression models. |
This function currently supports comparing coefficient vectors from two
models. The intercepts of the models are removed, if they exist, and the
coefficient vectors are compared by Hotelling's test. This can be
considered as an initial omnibus test for differences among the coefficients
before searching through all coefficients for individual differences using,
for example,
compare_coefs
.
List of test results. This includes the chi-squared statistic, degrees of freedom, and p-value.
##Simulate data N = 500 m = rep(1:2, each=N) x1 = rnorm(n=N*2) x2 = rnorm(n=N*2) x3 = rnorm(n=N*2) y = x1 + x2 + x3 + rnorm(n=N*2) dat = data.frame(m, x1, x2, x3, y) m1 = lm(y ~ x1 + x2 + x3, data=dat, subset=m==1) m2 = lm(y ~ x1 + x2 + x3, data=dat, subset=m==2) mList = list(m1, m2) compare_coef_vectors(model_list = mList)
##Simulate data N = 500 m = rep(1:2, each=N) x1 = rnorm(n=N*2) x2 = rnorm(n=N*2) x3 = rnorm(n=N*2) y = x1 + x2 + x3 + rnorm(n=N*2) dat = data.frame(m, x1, x2, x3, y) m1 = lm(y ~ x1 + x2 + x3, data=dat, subset=m==1) m2 = lm(y ~ x1 + x2 + x3, data=dat, subset=m==2) mList = list(m1, m2) compare_coef_vectors(model_list = mList)
Compares predictor coefficients across models.
compare_coefs(model_list, padj = "none")
compare_coefs(model_list, padj = "none")
model_list |
A list of regression models. |
padj |
A method from |
This function currently supports comparing coefficients from two models. For each model predictor, coefficients are compared across models. P-values come from a two-sided alternative hypothesis. They can, and should, be adjusted for multiple testing to reduce the probability of chance significant findings.
Data frame of shared coefficients, the difference between them, the
standard error of the difference, the test statistic comparing them, and the
p-value adjusted using the method provided in padj
.
##Simulate data N = 500 m = rep(1:2, each=N) x1 = rnorm(n=N*2) x2 = rnorm(n=N*2) x3 = rnorm(n=N*2) y = x1 + x2 + x3 + rnorm(n=N*2) dat = data.frame(m, x1, x2, x3, y) m1 = lm(y ~ x1 + x2 + x3, data=dat, subset=m==1) m2 = lm(y ~ x1 + x2 + x3, data=dat, subset=m==2) mList = list(m1, m2) compare_coefs(model_list = mList, padj='fdr')
##Simulate data N = 500 m = rep(1:2, each=N) x1 = rnorm(n=N*2) x2 = rnorm(n=N*2) x3 = rnorm(n=N*2) y = x1 + x2 + x3 + rnorm(n=N*2) dat = data.frame(m, x1, x2, x3, y) m1 = lm(y ~ x1 + x2 + x3, data=dat, subset=m==1) m2 = lm(y ~ x1 + x2 + x3, data=dat, subset=m==2) mList = list(m1, m2) compare_coefs(model_list = mList, padj='fdr')
Compare residual standard deviation across models. Works for linear regression
(lm
) only.
compare_resids(model_list)
compare_resids(model_list)
model_list |
A list of regression models. |
This function currently supports comparing residual standard deviation from two models. Residuals are assumed to be normally distributed (as also assumed in the linear model itself) and are compared by an F test.
Vector of results. This includes the residual standard deviation from each model, the F statistic comparing the standard deviations, the numerator and denominator degrees of freedom, and the p-value.
##Simulate data N = 500 m = rep(1:2, each=N) x1 = rnorm(n=N*2) x2 = rnorm(n=N*2) x3 = rnorm(n=N*2) y = x1 + x2 + x3 + rnorm(n=N*2) dat = data.frame(m, x1, x2, x3, y) m1 = lm(y ~ x1 + x2 + x3, data=dat, subset=m==1) m2 = lm(y ~ x1 + x2 + x3, data=dat, subset=m==2) mList = list(m1, m2) compare_resids(model_list = mList)
##Simulate data N = 500 m = rep(1:2, each=N) x1 = rnorm(n=N*2) x2 = rnorm(n=N*2) x3 = rnorm(n=N*2) y = x1 + x2 + x3 + rnorm(n=N*2) dat = data.frame(m, x1, x2, x3, y) m1 = lm(y ~ x1 + x2 + x3, data=dat, subset=m==1) m2 = lm(y ~ x1 + x2 + x3, data=dat, subset=m==2) mList = list(m1, m2) compare_resids(model_list = mList)