AutoModel is an R package that makes it easier to create hierarchical multiple regression models, check model assumptions and get appropriate output.
With hierarchical multiple regression models, one wants model statistics and coefficients for each successive iteration of the model. There are ways to do this in R of course, but they aren’t particularly convenient when one wants to get all of the model overall statistics and coefficients for each iteration of the model, in one place in an easy to read format. Furthermore, this package makes it easy to check all of the standard multiple regression assumptions for a model without having to write any additional code, which makes it very easy to run many different versions of a model in quick succession.
With the main run_model
function, one can easily review all model statistics, coefficients, and check assumptions for a Hierarchical Multiple Regression model with predictors entered progressively in blocks.
For the following example, the built in dataset mtcars
is used to build a hierarchical multiple regression model with 3 blocks of predictors.
Blocks of predictors are specified by character vectors containing the variable names. The outcome is simply a string of the variable name. The dataset name must also be specified.
library(AutoModel)
run_model("mpg", c("disp", "hp"), c("cyl", "wt"), c("drat", "qsec"), dataset=mtcars)
##
##
## REGRESSION OUTPUT
##
## Durbin-Watson = 1.922 p value = 0.2638
##
## Partial Regression plots (all relationships should be linear):
## Plot of studentized residuals: uniform distibution across predicted values required
## Correlation Matrix for model (correlation >.70 indicates severe multicollinearity)
##
## mpg disp hp cyl wt drat qsec
## mpg 1.0000 -0.8476 -0.7762 -0.8522 -0.8677 0.6812 0.4187
## disp -0.8476 1.0000 0.7909 0.9020 0.8880 -0.7102 -0.4337
## hp -0.7762 0.7909 1.0000 0.8324 0.6587 -0.4488 -0.7082
## cyl -0.8522 0.9020 0.8324 1.0000 0.7825 -0.6999 -0.5912
## wt -0.8677 0.8880 0.6587 0.7825 1.0000 -0.7124 -0.1747
## drat 0.6812 -0.7102 -0.4488 -0.6999 -0.7124 1.0000 0.0912
## qsec 0.4187 -0.4337 -0.7082 -0.5912 -0.1747 0.0912 1.0000
##
## Variance inflation factor (<10 desired):
##
## disp hp cyl wt drat qsec
## 10.551 5.358 9.959 7.182 2.967 4.040
##
## Standardized Residuals (observations > 3.00 problematic):
##
## No significant outliers
##
## Cook's distance (values >.2 problematic):
##
## Chrysler Imperial
## 0.2101
##
## Normality of standardized model residuals: Shapiro-Wilk (p-value): 0.05046
## Model change statistics
##
## R R^2 Adj R^2 SE Est. Delta R^2 F Change df1 df2 p Fch
## Model 1 0.865 0.7482 0.7309 3.1266 0.7482 43.0946 2 29 0
## Model 2 0.9212 0.8486 0.8262 2.5125 0.1004 8.954 2 27 0.001
## Model 3 0.9246 0.8548 0.82 2.5572 0.0062 0.5328 2 25 0.5935
## Sig
## Model 1 ***
## Model 2 **
## Model 3
## Model 1 : mpg ~ disp + hp
## Model 2 : mpg ~ disp + hp + cyl + wt
## Model 3 : mpg ~ disp + hp + cyl + wt + drat + qsec
##
## Model Coefficients
##
## Model term estimate std.error statistic p.value sig
## Model 1 (Intercept) 30.73590 1.331566 23.0825 0.0000 ***
## Model 1 disp -0.03035 0.007405 -4.0982 0.0003 ***
## Model 1 hp -0.02484 0.013385 -1.8557 0.0737 .
## Model 2 (Intercept) 40.82854 2.757468 14.8065 0.0000 ***
## Model 2 disp 0.01160 0.011727 0.9891 0.3314
## Model 2 hp -0.02054 0.012147 -1.6909 0.1024
## Model 2 cyl -1.29332 0.655877 -1.9719 0.0589 .
## Model 2 wt -3.85390 1.015474 -3.7952 0.0008 ***
## Model 3 (Intercept) 26.30736 14.629938 1.7982 0.0842 .
## Model 3 disp 0.01320 0.012037 1.0971 0.2831
## Model 3 hp -0.01793 0.015505 -1.1564 0.2585
## Model 3 cyl -0.81856 0.811563 -1.0086 0.3228
## Model 3 wt -4.19083 1.257907 -3.3316 0.0027 **
## Model 3 drat 1.32041 1.479476 0.8925 0.3806
## Model 3 qsec 0.40146 0.516584 0.7771 0.4444
Underlying the run_model
function is a function to create the hierarchical models. The create_model_objects
function creates a list of lm
objects that run_model
uses to prepare output. This function can be used separately to create model objects that can be used for the further purposes of the user that go beyond what is enabled by the run_model
function.
This function works in combination with the create_formula_objects
, which creates a list containing the hierarchical model formulas from the character vectors of predictors.
An example of how this works is as follows. The parameters for create_formula_objects
are the outcome and predictors, whereas the dataset is passed to create_model_objects
.
formulas <- create_formula_objects("mpg", c("disp", "hp"), c("cyl", "wt"), c("drat", "qsec"))
models <- create_model_objects(formulas, dataset = mtcars)
models
## [[1]]
##
## Call:
## FUN(formula = X[[i]], data = ..1)
##
## Coefficients:
## (Intercept) disp hp
## 30.7359 -0.0303 -0.0248
##
##
## [[2]]
##
## Call:
## FUN(formula = X[[i]], data = ..1)
##
## Coefficients:
## (Intercept) disp hp cyl wt
## 40.8285 0.0116 -0.0205 -1.2933 -3.8539
##
##
## [[3]]
##
## Call:
## FUN(formula = X[[i]], data = ..1)
##
## Coefficients:
## (Intercept) disp hp cyl wt
## 26.3074 0.0132 -0.0179 -0.8186 -4.1908
## drat qsec
## 1.3204 0.4015
The function run_model
also allows you to choose whether or not to display the output for the assumptions check function. If multiple similar models are being analyzed, you may not need to see all of the output, so the assumptions.check
binary flag parameter can be used to suppress this output.
run_model("mpg", c("disp", "hp"), c("cyl", "wt"), c("drat", "qsec"), dataset=mtcars, assumptions.check = F)
## Model change statistics
##
## R R^2 Adj R^2 SE Est. Delta R^2 F Change df1 df2 p Fch
## Model 1 0.865 0.7482 0.7309 3.1266 0.7482 43.0946 2 29 0
## Model 2 0.9212 0.8486 0.8262 2.5125 0.1004 8.954 2 27 0.001
## Model 3 0.9246 0.8548 0.82 2.5572 0.0062 0.5328 2 25 0.5935
## Sig
## Model 1 ***
## Model 2 **
## Model 3
## Model 1 : mpg ~ disp + hp
## Model 2 : mpg ~ disp + hp + cyl + wt
## Model 3 : mpg ~ disp + hp + cyl + wt + drat + qsec
##
## Model Coefficients
##
## Model term estimate std.error statistic p.value sig
## Model 1 (Intercept) 30.73590 1.331566 23.0825 0.0000 ***
## Model 1 disp -0.03035 0.007405 -4.0982 0.0003 ***
## Model 1 hp -0.02484 0.013385 -1.8557 0.0737 .
## Model 2 (Intercept) 40.82854 2.757468 14.8065 0.0000 ***
## Model 2 disp 0.01160 0.011727 0.9891 0.3314
## Model 2 hp -0.02054 0.012147 -1.6909 0.1024
## Model 2 cyl -1.29332 0.655877 -1.9719 0.0589 .
## Model 2 wt -3.85390 1.015474 -3.7952 0.0008 ***
## Model 3 (Intercept) 26.30736 14.629938 1.7982 0.0842 .
## Model 3 disp 0.01320 0.012037 1.0971 0.2831
## Model 3 hp -0.01793 0.015505 -1.1564 0.2585
## Model 3 cyl -0.81856 0.811563 -1.0086 0.3228
## Model 3 wt -4.19083 1.257907 -3.3316 0.0027 **
## Model 3 drat 1.32041 1.479476 0.8925 0.3806
## Model 3 qsec 0.40146 0.516584 0.7771 0.4444
Saving the results of run_model
saves an lm
-like list (of lists) which contains all of the model summary, coefficient and assumption data to make it available for further use. The contents of the object are demonstrated below
model_object <- run_model("mpg", c("disp", "hp"), c("cyl", "wt"), c("drat", "qsec"), dataset=mtcars)
##
##
## REGRESSION OUTPUT
##
## Durbin-Watson = 1.922 p value = 0.2638
##
## Partial Regression plots (all relationships should be linear):
## Plot of studentized residuals: uniform distibution across predicted values required
## Correlation Matrix for model (correlation >.70 indicates severe multicollinearity)
##
## mpg disp hp cyl wt drat qsec
## mpg 1.0000 -0.8476 -0.7762 -0.8522 -0.8677 0.6812 0.4187
## disp -0.8476 1.0000 0.7909 0.9020 0.8880 -0.7102 -0.4337
## hp -0.7762 0.7909 1.0000 0.8324 0.6587 -0.4488 -0.7082
## cyl -0.8522 0.9020 0.8324 1.0000 0.7825 -0.6999 -0.5912
## wt -0.8677 0.8880 0.6587 0.7825 1.0000 -0.7124 -0.1747
## drat 0.6812 -0.7102 -0.4488 -0.6999 -0.7124 1.0000 0.0912
## qsec 0.4187 -0.4337 -0.7082 -0.5912 -0.1747 0.0912 1.0000
##
## Variance inflation factor (<10 desired):
##
## disp hp cyl wt drat qsec
## 10.551 5.358 9.959 7.182 2.967 4.040
##
## Standardized Residuals (observations > 3.00 problematic):
##
## No significant outliers
##
## Cook's distance (values >.2 problematic):
##
## Chrysler Imperial
## 0.2101
##
## Normality of standardized model residuals: Shapiro-Wilk (p-value): 0.05046
## Model change statistics
##
## R R^2 Adj R^2 SE Est. Delta R^2 F Change df1 df2 p Fch
## Model 1 0.865 0.7482 0.7309 3.1266 0.7482 43.0946 2 29 0
## Model 2 0.9212 0.8486 0.8262 2.5125 0.1004 8.954 2 27 0.001
## Model 3 0.9246 0.8548 0.82 2.5572 0.0062 0.5328 2 25 0.5935
## Sig
## Model 1 ***
## Model 2 **
## Model 3
## Model 1 : mpg ~ disp + hp
## Model 2 : mpg ~ disp + hp + cyl + wt
## Model 3 : mpg ~ disp + hp + cyl + wt + drat + qsec
##
## Model Coefficients
##
## Model term estimate std.error statistic p.value sig
## Model 1 (Intercept) 30.73590 1.331566 23.0825 0.0000 ***
## Model 1 disp -0.03035 0.007405 -4.0982 0.0003 ***
## Model 1 hp -0.02484 0.013385 -1.8557 0.0737 .
## Model 2 (Intercept) 40.82854 2.757468 14.8065 0.0000 ***
## Model 2 disp 0.01160 0.011727 0.9891 0.3314
## Model 2 hp -0.02054 0.012147 -1.6909 0.1024
## Model 2 cyl -1.29332 0.655877 -1.9719 0.0589 .
## Model 2 wt -3.85390 1.015474 -3.7952 0.0008 ***
## Model 3 (Intercept) 26.30736 14.629938 1.7982 0.0842 .
## Model 3 disp 0.01320 0.012037 1.0971 0.2831
## Model 3 hp -0.01793 0.015505 -1.1564 0.2585
## Model 3 cyl -0.81856 0.811563 -1.0086 0.3228
## Model 3 wt -4.19083 1.257907 -3.3316 0.0027 **
## Model 3 drat 1.32041 1.479476 0.8925 0.3806
## Model 3 qsec 0.40146 0.516584 0.7771 0.4444
model_object$Summary
## $R
## Model 1 Model 2 Model 3
## 0.865 0.9212 0.9246
## Levels: 0.865 0.9212 0.9246
##
## $R2
## Model 1 Model 2 Model 3
## 0.7482 0.8486 0.8548
## Levels: 0.7482 0.8486 0.8548
##
## $AdjR2
## Model 1 Model 2 Model 3
## 0.7309 0.8262 0.82
## Levels: 0.7309 0.82 0.8262
##
## $SE
## Model 1 Model 2 Model 3
## 3.1266 2.5125 2.5572
## Levels: 2.5125 2.5572 3.1266
##
## $DeltaR2
## Model 1 Model 2 Model 3
## 0.7482 0.1004 0.0062
## Levels: 0.0062 0.1004 0.7482
##
## $Fch
## Model 1 Model 2 Model 3
## 43.0946 8.954 0.5328
## Levels: 0.5328 43.0946 8.954
##
## $DF1
## Model 1 Model 2 Model 3
## 2 2 2
## Levels: 2
##
## $DF2
## Model 1 Model 2 Model 3
## 29 27 25
## Levels: 25 27 29
##
## $SigFch
## Model 1 Model 2 Model 3
## 0 0.001 0.5935
## Levels: 0 0.001 0.5935
##
## $pval
## Model 1 Model 2 Model 3
## *** **
## Levels: ** ***
##
## $Formula
## [1] "mpg ~ disp + hp"
## [2] "mpg ~ disp + hp + cyl + wt"
## [3] "mpg ~ disp + hp + cyl + wt + drat + qsec"
model_object$Coefficients
## $Model
## [1] Model 1 Model 1 Model 1 Model 2 Model 2 Model 2 Model 2 Model 2
## [9] Model 3 Model 3 Model 3 Model 3 Model 3 Model 3 Model 3
## Levels: Model 1 Model 2 Model 3
##
## $term
## [1] "(Intercept)" "disp" "hp" "(Intercept)" "disp"
## [6] "hp" "cyl" "wt" "(Intercept)" "disp"
## [11] "hp" "cyl" "wt" "drat" "qsec"
##
## $estimate
## (Intercept) disp hp (Intercept) disp hp
## 30.73590 -0.03035 -0.02484 40.82854 0.01160 -0.02054
## cyl wt (Intercept) disp hp cyl
## -1.29332 -3.85390 26.30736 0.01320 -0.01793 -0.81856
## wt drat qsec
## -4.19083 1.32041 0.40146
##
## $std.error
## (Intercept) disp hp (Intercept) disp hp
## 1.331566 0.007405 0.013385 2.757468 0.011727 0.012147
## cyl wt (Intercept) disp hp cyl
## 0.655877 1.015474 14.629938 0.012037 0.015505 0.811563
## wt drat qsec
## 1.257907 1.479476 0.516584
##
## $statistic
## (Intercept) disp hp (Intercept) disp hp
## 23.0825 -4.0982 -1.8557 14.8065 0.9891 -1.6909
## cyl wt (Intercept) disp hp cyl
## -1.9719 -3.7952 1.7982 1.0971 -1.1564 -1.0086
## wt drat qsec
## -3.3316 0.8925 0.7771
##
## $p.value
## (Intercept) disp hp (Intercept) disp hp
## 0.0000 0.0003 0.0737 0.0000 0.3314 0.1024
## cyl wt (Intercept) disp hp cyl
## 0.0589 0.0008 0.0842 0.2831 0.2585 0.3228
## wt drat qsec
## 0.0027 0.3806 0.4444
##
## $sig
## [1] "***" "***" "." "***" " " " " "." "***" "." " " " "
## [12] " " "**" " " " "
## attr(,"legend")
## [1] "0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1"
model_object$Checks
## $Durbin.Watson
## DW
## 1.922
##
## $DW.p.value
## [1] 0.2638
##
## $Correlation.Matrix
## mpg disp hp cyl wt drat qsec
## mpg 1.0000 -0.8476 -0.7762 -0.8522 -0.8677 0.6812 0.4187
## disp -0.8476 1.0000 0.7909 0.9020 0.8880 -0.7102 -0.4337
## hp -0.7762 0.7909 1.0000 0.8324 0.6587 -0.4488 -0.7082
## cyl -0.8522 0.9020 0.8324 1.0000 0.7825 -0.6999 -0.5912
## wt -0.8677 0.8880 0.6587 0.7825 1.0000 -0.7124 -0.1747
## drat 0.6812 -0.7102 -0.4488 -0.6999 -0.7124 1.0000 0.0912
## qsec 0.4187 -0.4337 -0.7082 -0.5912 -0.1747 0.0912 1.0000
##
## $Var.Inf.Factor
## disp hp cyl wt drat qsec
## 10.551 5.358 9.959 7.182 2.967 4.040
##
## $Stand.Residuals
## Mazda RX4 Mazda RX4 Wag Datsun 710
## -0.56014 -0.19926 -1.17401
## Hornet 4 Drive Hornet Sportabout Valiant
## 0.07271 0.32483 -0.72877
## Duster 360 Merc 240D Merc 230
## -0.62045 0.43667 -0.85586
## Merc 280 Merc 280C Merc 450SE
## -0.13402 -0.84675 0.97008
## Merc 450SL Merc 450SLC Cadillac Fleetwood
## 0.69572 -0.17720 -0.45854
## Lincoln Continental Chrysler Imperial Fiat 128
## 0.01734 2.00839 2.26243
## Honda Civic Toyota Corolla Toyota Corona
## 0.06051 2.23910 -1.68705
## Dodge Challenger AMC Javelin Camaro Z28
## -0.63023 -1.10627 -0.71940
## Pontiac Firebird Fiat X1-9 Porsche 914-2
## 1.08967 -0.18837 -0.25967
## Lotus Europa Ford Pantera L Ferrari Dino
## 1.29469 -0.97954 0.06131
## Maserati Bora Volvo 142E
## 0.98376 -1.06316
##
## $Cooks.Dist
## Mazda RX4 Mazda RX4 Wag Datsun 710
## 0.00842779 0.00098576 0.02565841
## Hornet 4 Drive Hornet Sportabout Valiant
## 0.00013035 0.00344460 0.02137999
## Duster 360 Merc 240D Merc 230
## 0.01029226 0.00614648 0.10201623
## Merc 280 Merc 280C Merc 450SE
## 0.00056968 0.02374707 0.02981800
## Merc 450SL Merc 450SLC Cadillac Fleetwood
## 0.01232015 0.00093999 0.01116684
## Lincoln Continental Chrysler Imperial Fiat 128
## 0.00001671 0.21008308 0.06992098
## Honda Civic Toyota Corolla Toyota Corona
## 0.00030271 0.14470179 0.07397365
## Dodge Challenger AMC Javelin Camaro Z28
## 0.01494786 0.03330625 0.01197522
## Pontiac Firebird Fiat X1-9 Porsche 914-2
## 0.04128541 0.00052465 0.00319338
## Lotus Europa Ford Pantera L Ferrari Dino
## 0.11653936 0.08483410 0.00020796
## Maserati Bora Volvo 142E
## 0.16495936 0.02645163
##
## $Normality.Resids
## [1] 0.05046
##
## $Prob.Dist
## Mazda RX4 Mazda RX4 Wag Datsun 710
## 0.2877 0.4210 0.1202
## Hornet 4 Drive Hornet Sportabout Valiant
## 0.5290 0.6273 0.2331
## Duster 360 Merc 240D Merc 230
## 0.2675 0.6688 0.1960
## Merc 280 Merc 280C Merc 450SE
## 0.4467 0.1986 0.8340
## Merc 450SL Merc 450SLC Cadillac Fleetwood
## 0.7567 0.4297 0.3233
## Lincoln Continental Chrysler Imperial Fiat 128
## 0.5069 0.9777 0.9882
## Honda Civic Toyota Corolla Toyota Corona
## 0.5241 0.9874 0.0458
## Dodge Challenger AMC Javelin Camaro Z28
## 0.2643 0.1343 0.2359
## Pontiac Firebird Fiat X1-9 Porsche 914-2
## 0.8621 0.4253 0.3976
## Lotus Europa Ford Pantera L Ferrari Dino
## 0.9023 0.1637 0.5244
## Maserati Bora Volvo 142E
## 0.8374 0.1439
Subsets of the information in the three main lists can also be accessed as follows.
model_object$Summary$DeltaR2
## Model 1 Model 2 Model 3
## 0.7482 0.1004 0.0062
## Levels: 0.0062 0.1004 0.7482
model_object$Coefficients$estimate
## (Intercept) disp hp (Intercept) disp hp
## 30.73590 -0.03035 -0.02484 40.82854 0.01160 -0.02054
## cyl wt (Intercept) disp hp cyl
## -1.29332 -3.85390 26.30736 0.01320 -0.01793 -0.81856
## wt drat qsec
## -4.19083 1.32041 0.40146
model_object$Checks$Correlation.Matrix
## mpg disp hp cyl wt drat qsec
## mpg 1.0000 -0.8476 -0.7762 -0.8522 -0.8677 0.6812 0.4187
## disp -0.8476 1.0000 0.7909 0.9020 0.8880 -0.7102 -0.4337
## hp -0.7762 0.7909 1.0000 0.8324 0.6587 -0.4488 -0.7082
## cyl -0.8522 0.9020 0.8324 1.0000 0.7825 -0.6999 -0.5912
## wt -0.8677 0.8880 0.6587 0.7825 1.0000 -0.7124 -0.1747
## drat 0.6812 -0.7102 -0.4488 -0.6999 -0.7124 1.0000 0.0912
## qsec 0.4187 -0.4337 -0.7082 -0.5912 -0.1747 0.0912 1.0000
The model return object also contains the two main output dataframes for summary and coefficients. These can be printed in knitr for more aesthetically pleasing output using xtable.
library(xtable)
sum_table <- xtable(model_object$SummaryDF)
coef_table <- xtable(model_object$CoefficientsDF)
print(sum_table, type="html")
R | R2 | AdjR2 | SE | DeltaR2 | Fch | DF1 | DF2 | SigFch | pval | Formula | |
---|---|---|---|---|---|---|---|---|---|---|---|
Model 1 | 0.865 | 0.7482 | 0.7309 | 3.1266 | 0.7482 | 43.0946 | 2 | 29 | 0 | *** | mpg ~ disp + hp |
Model 2 | 0.9212 | 0.8486 | 0.8262 | 2.5125 | 0.1004 | 8.954 | 2 | 27 | 0.001 | ** | mpg ~ disp + hp + cyl + wt |
Model 3 | 0.9246 | 0.8548 | 0.82 | 2.5572 | 0.0062 | 0.5328 | 2 | 25 | 0.5935 | mpg ~ disp + hp + cyl + wt + drat + qsec |
print(coef_table, type="html")
Model | term | estimate | std.error | statistic | p.value | sig | |
---|---|---|---|---|---|---|---|
1 | Model 1 | (Intercept) | 30.74 | 1.33 | 23.08 | 0.00 | *** |
2 | Model 1 | disp | -0.03 | 0.01 | -4.10 | 0.00 | *** |
3 | Model 1 | hp | -0.02 | 0.01 | -1.86 | 0.07 | . |
4 | Model 2 | (Intercept) | 40.83 | 2.76 | 14.81 | 0.00 | *** |
5 | Model 2 | disp | 0.01 | 0.01 | 0.99 | 0.33 | |
6 | Model 2 | hp | -0.02 | 0.01 | -1.69 | 0.10 | |
7 | Model 2 | cyl | -1.29 | 0.66 | -1.97 | 0.06 | . |
8 | Model 2 | wt | -3.85 | 1.02 | -3.80 | 0.00 | *** |
9 | Model 3 | (Intercept) | 26.31 | 14.63 | 1.80 | 0.08 | . |
10 | Model 3 | disp | 0.01 | 0.01 | 1.10 | 0.28 | |
11 | Model 3 | hp | -0.02 | 0.02 | -1.16 | 0.26 | |
12 | Model 3 | cyl | -0.82 | 0.81 | -1.01 | 0.32 | |
13 | Model 3 | wt | -4.19 | 1.26 | -3.33 | 0.00 | ** |
14 | Model 3 | drat | 1.32 | 1.48 | 0.89 | 0.38 | |
15 | Model 3 | qsec | 0.40 | 0.52 | 0.78 | 0.44 |
The binary logistic regression version of the run_model
function provides similar but different output for a hierarchical binary logistic regression model. Output includes a model summary table containing 4 different versions of pseudo R^2 values, a coefficient table with estimates, standard errors, wald test and p values, and a classification table that assesses the prediction accuracy of the binary regression function using an optimal cutpoint. Like the standard hierarchical multiple regression model, these elements of the output are also accessible as individual data frame objects.
model <- run_model("am", c("disp", "hp"), c("cyl", "wt"), dataset = mtcars, type="binomial")
## Warning: glm.fit: algorithm did not converge
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
##
## Model Summary Table: Pseudo R^2
##
## McFadden's Adj McFadden's Cox-Snell Nagelkerke
## Model 1 0.6134 0.4283 0.5634 0.7603
## Model 2 1.0000 0.7224 0.7410 1.0000
##
## Model Coefficient Table
##
## model_terms coefs SE wald p.value coefs.1 SE.1 wald.1
## 1 (Intercept) 1.4034 1.3676 1.0531 0.3048 -49.74 573627 0
## 2 disp -0.0952 0.048 3.9315 0.0474 * -10.07 6126 0
## 3 hp 0.1217 0.0678 3.2246 0.0725 . 13.27 2451 0
## 4 cyl -- -- -- -- 211.03 311420 0
## 5 wt -- -- -- -- -361.30 63324 0
## p.value.1
## 1 0.9999
## 2 0.9987
## 3 0.9957
## 4 0.9995
## 5 0.9954
##
## Classification Table
##
## Actual
## Predict 0 1
## 0 18 0
## 1 1 13
## Specificity: 0.9286
## Sensitivity: 1
## Total Accuracy: 0.9688
## Model 1 : am ~ disp + hp
## Model 2 : am ~ disp + hp + cyl + wt
model$Summary
## McFadden's Adj McFadden's Cox-Snell Nagelkerke
## Model 1 0.6134 0.4283 0.5634 0.7603
## Model 2 1.0000 0.7224 0.7410 1.0000
model$Coefficients
## model_terms coefs SE wald p.value coefs.1 SE.1 wald.1
## 1 (Intercept) 1.4034 1.3676 1.0531 0.3048 -49.74 573627 0
## 2 disp -0.0952 0.048 3.9315 0.0474 * -10.07 6126 0
## 3 hp 0.1217 0.0678 3.2246 0.0725 . 13.27 2451 0
## 4 cyl -- -- -- -- 211.03 311420 0
## 5 wt -- -- -- -- -361.30 63324 0
## p.value.1
## 1 0.9999
## 2 0.9987
## 3 0.9957
## 4 0.9995
## 5 0.9954
model$Class_Table
## Predict Actual Freq
## 1 0 0 18
## 2 1 0 1
## 3 0 1 0
## 4 1 1 13
Like the standard multiple regression, these output objects can also be printed as handsome latex tables for the purposes of knitr documents.
sum_table <- xtable(model$Summary)
coef_table <- xtable(model$Coefficients)
class_table <- xtable(model$Class_Table)
print(sum_table, type="html")
McFadden’s | Adj McFadden’s | Cox-Snell | Nagelkerke | |
---|---|---|---|---|
Model 1 | 0.61 | 0.43 | 0.56 | 0.76 |
Model 2 | 1.00 | 0.72 | 0.74 | 1.00 |
print(coef_table, type="html", digits = 4)
model_terms | coefs | SE | wald | p.value | coefs.1 | SE.1 | wald.1 | p.value.1 | |
---|---|---|---|---|---|---|---|---|---|
1 | (Intercept) | 1.4034 | 1.3676 | 1.0531 | 0.3048 | -49.74 | 573627.16 | 0.00 | 0.9999 |
2 | disp | -0.0952 | 0.048 | 3.9315 | 0.0474 * | -10.07 | 6126.04 | 0.00 | 0.9987 |
3 | hp | 0.1217 | 0.0678 | 3.2246 | 0.0725 . | 13.27 | 2450.53 | 0.00 | 0.9957 |
4 | cyl | – | – | – | – | 211.03 | 311420.02 | 0.00 | 0.9995 |
5 | wt | – | – | – | – | -361.30 | 63324.01 | 0.00 | 0.9954 |
print(class_table, type="html")
Predict | Actual | Freq | |
---|---|---|---|
1 | 0 | 0 | 18 |
2 | 1 | 0 | 1 |
3 | 0 | 1 | 0 |
4 | 1 | 1 | 13 |