我正在研究生存分析。
我估计了 Cox 回归模型和 Buckley&James 回归模型。
为了确定哪种模型更适合我的数据集,我使用了 Akaike Information Criteria (AIC)。那么,如何使用 R 软件找到两个模型的 AIC 值?
我正在研究生存分析。
我估计了 Cox 回归模型和 Buckley&James 回归模型。
为了确定哪种模型更适合我的数据集,我使用了 Akaike Information Criteria (AIC)。那么,如何使用 R 软件找到两个模型的 AIC 值?
如果您正在寻找 AIC 值,您可以使用 glm 函数找到它们并将其保存为向量 x。然后执行 summary(x),您将看到所有 AIC、BIC 等。这是使用 mtcars 数据集的示例
> data(mtcars) #loads data
> head(mtcars) #summary view of data
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
> x<-glm(mtcars$cyl~mtcars$mpg) #creates a regression model
> summary(x) #summary of regression model
Call:
glm(formula = mtcars$cyl ~ mtcars$mpg)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.8569 -0.6484 0.1205 0.5965 1.5876
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 11.26068 0.59304 18.99 < 2e-16 ***
mtcars$mpg -0.25251 0.02831 -8.92 6.11e-10 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for gaussian family taken to be 0.9024651)
Null deviance: 98.875 on 31 degrees of freedom
Residual deviance: 27.074 on 30 degrees of freedom
AIC: 91.463 #AIC value you are looking for
Number of Fisher Scoring iterations: 2