我正在尝试存储不同模型的系数估计值。为了说明我的问题,下面是一个示例。
library(fpp)
creditlog <- data.frame(score=credit$score,
log.savings=log(credit$savings+1),
log.income=log(credit$income+1),
log.address=log(credit$time.address+1),
log.employed=log(credit$time.employed+1))
fit_1 <-lm(score ~ log.income + log.address + log.employed , data=creditlog)
fit_2 <-lm(score ~ log.savings + log.employed , data=creditlog)
fit_3 <-lm(score ~ log.address + log.employed , data=creditlog)
fit_4 <- lm(score ~ log.income + log.address , data=creditlog)
coef_1 <-summary(fit_1)$coef[,1]
coef_2 <-summary(fit_2)$coef[,1]
coef_3 <-summary(fit_3)$coef[,1]
coef_4 <-summary(fit_4)$coef[,1]
> coef_1
(Intercept) log.income log.address log.employed
-14.957037 10.082396 3.353521 1.049130
> coef_2
(Intercept) log.savings log.employed
24.34323 11.28698 1.92655
> coef_3
(Intercept) log.address log.employed
26.115064 3.438382 1.213017
> coef_4
(Intercept) log.income log.address
-13.38037 10.23459 3.58023
如果我尝试 rbind,我会得到
(Intercept) log.income log.address log.employed
coef_1 -14.95704 10.082396 3.353521 1.04913
coef_2 24.34323 11.286978 1.926550 24.34323
coef_3 26.11506 3.438382 1.213017 26.11506
coef_4 -13.38037 10.234590 3.580230 -13.38037
Warning message:
In rbind(coef_1, coef_2, coef_3, coef_4) :
number of columns of result is not a multiple of vector length (arg 2)
>
这不是正确的答案。我需要的是类似的东西,
(Intercept) log.savings log.income log.address log.employed
fit_1 -14.957037 NA 10.082396 3.353521 1.04913
fit_2 24.34323 11.28698 NA NA 1.92655
fit_3 26.115064 NA NA 3.438382 1.213017
fit_4 -13.38037 NA 10.23459 3.58023 NA
提前致谢。