Print estimated coefficients and their standard errors in a table for several regression models.
compareCoefs.RdThis function extracts estimates of regression parameters and their standard errors from one or more models and prints them in a table.
Arguments
- ...
One or more regression-model objects. These may be of class
lm,glm,nlm, or any other regression method for which the functionscoefandvcovreturn appropriate values, or if the object inherits from themerclass created by thelme4package orlmein thenlmepackage.- se
If
TRUE, the default, show standard errors as well as estimates.- zvals
If
TRUE(the default isFALSE), print Wald statistics, the ratio of each coefficient to its standard error.- pvals
If
TRUE(the default isFALSE), print two-sided p-values from the standard normal distribution corresponding to the Wald statistics.- vcov.
an optional argument, specifying a function to be applied to all of the models, returning a coefficient covariance matrix for each, or a list with one element for each model, with each element either containing a function to be applied to the corresponding model or a coefficient covariance matrix for that model. If omitted,
vcovis applied to each model. This argument can also be a list of estimated covariance matrices of the coefficient estimates.If
TRUE, the default, the results are printed in a nice format usingprintCoefmat. IfFALSE, the results are returned as a matrix- digits
Passed to the
printCoefmatfunction for printing the result.
Value
This function is mainly used for its side-effect of printing the result. It also invisibly returns a matrix of estimates, standard errors, Wald statistics, and p-values.
References
Fox, J. and Weisberg, S. (2019) An R Companion to Applied Regression, Third Edition, Sage.
Author
John Fox jfox@mcmaster.ca
Examples
mod1 <- lm(prestige ~ income + education, data=Duncan)
mod2 <- update(mod1, subset=-c(6,16))
mod3 <- update(mod1, . ~ . + type)
mod4 <- update(mod1, . ~ . + I(income + education)) # aliased coef.
compareCoefs(mod1)
#> Calls:
#> lm(formula = prestige ~ income + education, data = Duncan)
#>
#> Model 1
#> (Intercept) -6.06
#> SE 4.27
#>
#> income 0.599
#> SE 0.120
#>
#> education 0.5458
#> SE 0.0983
#>
compareCoefs(mod1, mod2, mod4)
#> Calls:
#> 1: lm(formula = prestige ~ income + education, data = Duncan)
#> 2: lm(formula = prestige ~ income + education, data = Duncan, subset = -c(6,
#> 16))
#> 3: lm(formula = prestige ~ income + education + I(income + education), data
#> = Duncan)
#>
#> Model 1 Model 2 Model 3
#> (Intercept) -6.06 -6.41 -6.06
#> SE 4.27 3.65 4.27
#>
#> income 0.599 0.867 0.599
#> SE 0.120 0.122 0.120
#>
#> education 0.5458 0.3322 0.5458
#> SE 0.0983 0.0987 0.0983
#>
#> I(income + education) aliased
#> SE
#>
compareCoefs(mod1, mod2, mod3, zvals=TRUE, pvals=TRUE)
#> Calls:
#> 1: lm(formula = prestige ~ income + education, data = Duncan)
#> 2: lm(formula = prestige ~ income + education, data = Duncan, subset = -c(6,
#> 16))
#> 3: lm(formula = prestige ~ income + education + type, data = Duncan)
#>
#> Model 1 Model 2 Model 3
#> (Intercept) -6.065 -6.409 -0.185
#> SE 4.272 3.653 3.714
#> z -1.42 -1.75 -0.05
#> Pr(>|z|) 0.15571 0.07932 0.96026
#>
#> income 0.5987 0.8674 0.5975
#> SE 0.1197 0.1220 0.0894
#> z 5.00 7.11 6.69
#> Pr(>|z|) 5.6e-07 1.1e-12 2.3e-11
#>
#> education 0.5458 0.3322 0.3453
#> SE 0.0983 0.0987 0.1136
#> z 5.56 3.36 3.04
#> Pr(>|z|) 2.8e-08 0.00077 0.00237
#>
#> typeprof 16.66
#> SE 6.99
#> z 2.38
#> Pr(>|z|) 0.01722
#>
#> typewc -14.66
#> SE 6.11
#> z -2.40
#> Pr(>|z|) 0.01639
#>
compareCoefs(mod1, mod2, se=FALSE)
#> Calls:
#> 1: lm(formula = prestige ~ income + education, data = Duncan)
#> 2: lm(formula = prestige ~ income + education, data = Duncan, subset = -c(6,
#> 16))
#>
#> Model 1 Model 2
#> (Intercept) -6.06 -6.41
#> income 0.599 0.867
#> education 0.546 0.332
compareCoefs(mod1, mod1, vcov.=list(vcov, hccm))
#> Standard errors computed by list(vcov, hccm)Calls:
#> 1: lm(formula = prestige ~ income + education, data = Duncan)
#> 2: lm(formula = prestige ~ income + education, data = Duncan)
#>
#> Model 1 Model 2
#> (Intercept) -6.06 -6.06
#> SE 4.27 3.15
#>
#> income 0.599 0.599
#> SE 0.120 0.183
#>
#> education 0.5458 0.5458
#> SE 0.0983 0.1495
#>