reg|拓端tecdat|R语言基于Bootstrap的线性回归预测置信区间估计方法( 二 )

可以创建一个数据库 , 解释变量是行和列 。 base=data.frame( + y head(base,12) y ai bj 1 3209 2000 0 2 3367 2001 0 3 3871 2002 0 4 4239 2003 0 5 4929 2004 0 6 5217 2005 0 7 1163 2000...


可以创建一个数据库 , 解释变量是行和列 。

  1. > base=data.frame(
  2. + y
  3. > head(base,12)
  4. y ai bj
  5. 1 3209 2000 0
  6. 2 3367 2001 0
  7. 3 3871 2002 0
  8. 4 4239 2003 0
  9. 5 4929 2004 0
  10. 6 5217 2005 0
  11. 7 1163 2000 1
  12. 8 1292 2001 1
  13. 9 1474 2002 1
  14. 10 1678 2003 1
  15. 11 1865 2004 1
  16. 12 NA 2005 1
然后 , 我们可以从基于对数增量付款数据的回归模型开始 , 该模型基于对数正态模型
  1. Coefficients:
  2. Estimate Std. Error t value Pr(>|t|)
  3. (Intercept) 7.9471 0.1101 72.188 6.35e-15 ***
  4. as.factor(ai)2001 0.1604 0.1109 1.447 0.17849
  5. as.factor(ai)2002 0.2718 0.1208 2.250 0.04819 *
  6. as.factor(ai)2003 0.5904 0.1342 4.399 0.00134 **
  7. as.factor(ai)2004 0.5535 0.1562 3.543 0.00533 **
  8. as.factor(ai)2005 0.6126 0.2070 2.959 0.01431 *
  9. as.factor(bj)1 -0.9674 0.1109 -8.726 5.46e-06 ***
  10. as.factor(bj)2 -4.2329 0.1208 -35.038 8.50e-12 ***
  11. as.factor(bj)3 -5.0571 0.1342 -37.684 4.13e-12 ***
  12. as.factor(bj)4 -5.9031 0.1562 -37.783 4.02e-12 ***
  13. as.factor(bj)5 -4.9026 0.2070 -23.685 4.08e-10 ***
  14. ---
  15. Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  16. Residual standard error: 0.1753 on 10 degrees of freedom
  17. (15 observations deleted due to missingness)
  18. Multiple R-squared: 0.9975, Adjusted R-squared: 0.9949
  19. F-statistic: 391.7 on 10 and 10 DF, p-value: 1.338e-11
  20. >
  21. exp(predict(reg1,
  22. + newdata=https://www.sohu.com/a/base)+summary(reg1)$sigma^2/2)
  23. [,1] [,2] [,3] [,4] [,5] [,6]
  24. [1,] 2871.2 1091.3 41.7 18.3 7.8 21.3
  25. [2,] 3370.8 1281.2 48.9 21.5 9.2 25.0
  26. [3,] 3768.0 1432.1 54.7 24.0 10.3 28.0
  27. [4,] 5181.5 1969.4 75.2 33.0 14.2 38.5
  28. [5,] 4994.1 1898.1 72.5 31.8 13.6 37.1
  29. [6,] 5297.8 2013.6 76.9 33.7 14.5 39.3
  30. > sum(py[is.na(y)])
  31. [1] 2481.857
这与链式梯度法的结果略有不同 , 但仍然具有可比性 。 我们也可以尝试泊松回归(用对数链接)
  1. glm(y~
  2. + as.factor(ai)+
  3. + as.factor(bj),data=https://www.sohu.com/a/base,
  4. + family=poisson)
  5. Coefficients:
  6. Estimate Std. Error z value Pr(>|z|)
  7. (Intercept) 8.05697 0.01551 519.426 < 2e-16 ***
  8. as.factor(ai)2001 0.06440 0.02090 3.081 0.00206 **
  9. as.factor(ai)2002 0.20242 0.02025 9.995 < 2e-16 ***
  10. as.factor(ai)2003 0.31175 0.01980 15.744 < 2e-16 ***
  11. as.factor(ai)2004 0.44407 0.01933 22.971 < 2e-16 ***
  12. as.factor(ai)2005 0.50271 0.02079 24.179 < 2e-16 ***
  13. as.factor(bj)1 -0.96513 0.01359 -70.994 < 2e-16 ***
  14. as.factor(bj)2 -4.14853 0.06613 -62.729 < 2e-16 ***
  15. as.factor(bj)3 -5.10499 0.12632 -40.413 < 2e-16 ***
  16. as.factor(bj)4 -5.94962 0.24279 -24.505 < 2e-16 ***
  17. as.factor(bj)5 -5.01244 0.21877 -22.912 < 2e-16 ***
  18. ---
  19. Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  20. (Dispersion parameter for poisson family taken to be 1)
  21. Null deviance: 46695.269 on 20 degrees of freedom
  22. Residual deviance: 30.214 on 10 degrees of freedom
  23. (15 observations deleted due to missingness)
  24. AIC: 209.52
  25. Number of Fisher Scoring iterations: 4
  26. > predict(reg2,
  27. newdata=https://www.sohu.com/a/base,type="response")
  28. > sum(py2[is.na(y)])
  29. [1] 2426.985
预测结果与链式梯度法得到的估计值吻合 。 克劳斯·施密特(Klaus Schmidt)和安吉拉·温什(Angela Wünsche)于1998年在链式梯度法、边际和最大似然估计中建立了与最小偏差方法的联系 。
reg|拓端tecdat|R语言基于Bootstrap的线性回归预测置信区间估计方法
文章图片

最受欢迎的见解
1.R语言多元Logistic逻辑回归 应用案例

特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。