在 R 中,拟合 glm 后,您可以获得包含残差偏差和零偏差的摘要信息,这些信息告诉您您的模型与仅包含截距项的模型相比有多好,例如模型:
model <- glm(formula = am ~ mpg + qsec, data=mtcars, family=binomial)
we have:
> summary(model)
...
Null deviance: 43.2297 on 31 degrees of freedom
Residual deviance: 7.5043 on 29 degrees of freedom
AIC: 13.504
...
在 Matlab 中,当您使用fitglm
你返回一个对象GeneralizedLinearModel
类,其中有一个Deviance
包含残余偏差的属性。但是,我找不到与零偏差直接相关的任何内容。计算这个最简单的方法是什么?
Matlab 代码示例:
load fisheriris.mat
model = fitglm(meas(:, 1), ismember(species, {'setosa'}), 'Distribution', 'binomial')
产生:
model =
Generalized Linear regression model:
logit(y) ~ 1 + x1
Distribution = Binomial
Estimated Coefficients:
Estimate SE tStat pValue
_________________ _________________ _________________ ____________________
(Intercept) 27.8285213954246 4.8275686220899 5.76450042948896 8.19000695766331e-09
x1 -5.17569812610148 0.893399843474784 -5.79326061438645 6.90328570107794e-09
150 observations, 148 error degrees of freedom
Dispersion: 1
Chi^2-statistic vs. constant model: 119, p-value = 9.87e-28
残余偏差为model.Deviance
:
>> model.Deviance
ans =
71.8363992272217