简体   繁体   中英

i have a problem with software R with anova test for glm

Hi I would like to know the meaning of the first three columns, "Resid. Df", "Resid. Dev" and "df" and how they are calculate, on the output of anova test for glm. I put a picture of an example. Can you anyone help me? enter image description here

When multiple models are passed as arguments to the anova() function, it compares the second through n-th models to the first, or "base" model in terms of reduction of deviance.

As an example, we'll fit three generalized linear models using the Motor Trend Cars database mtcars and compare them with the anova() function.

m1 <- glm(am ~ mpg ,data = mtcars,family="binomial")
m2 <- glm(am ~ mpg + wt, data = mtcars,family="binomial")
m3 <- glm(am ~ mpg + wt + disp, data = mtcars,family="binomial")
anova(m1,m2,m3,test="Chisq")

> anova(m1,m2,m3,test="Chisq")
Analysis of Deviance Table

Model 1: am ~ mpg
Model 2: am ~ mpg + wt
Model 3: am ~ mpg + wt + disp
  Resid. Df Resid. Dev Df Deviance  Pr(>Chi)    
1        30     29.675                          
2        29     17.184  1  12.4909 0.0004089 ***
3        28     16.858  1   0.3266 0.5676480    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 

The Resid. Df Resid. Df column lists the number of degrees of freedom remaining after accounting for the independent variables in the model, each of which consumes a degree of freedom. The Resid. Dev Resid. Dev column contains the residual deviance, or the deviance left unexplained by the model. The Df column shows the additional of degrees of freedom consumed by a model relative to the models above it in the list. The Deviance column shows the incremental deviance explained by this model relative to the models above it in the list. The Pr.(>Chi) provides the probability that the model in a given row explains significantly more deviance than the row above it.

For our example analysis, the base model uses miles per gallon to predict whether a car has an automatic or manual transmission am . Adding a car's weight wt to the model significantly improves the explanatory power of the model over the base model with mpg (miles per gallon). Adding a car's displacement disp to the model does not add significant explanatory power to the model, because the Chi Square test is not significant at the 0.05 level.

How is Deviance Calculated?

Deviance is calculated as the difference of log likelihoods between the fitted model and the saturated model (ie a model that perfectly fits the data). Note that deviance is a generalization of the concept of residual sum of squares in a linear model. Eduardo Garcia Portugués has a nice writeup of the details of math in his online book, Notes on Predictive Modeling .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM