楼主: fan19889017
2554 1

[R] 用ffbase包里的bigglm建模 [推广有奖]

  • 1关注
  • 1粉丝

大专生

23%

还不是VIP/贵宾

-

威望
0
论坛币
41 个
通用积分
0
学术水平
5 点
热心指数
6 点
信用等级
5 点
经验
454 点
帖子
34
精华
0
在线时间
47 小时
注册时间
2009-11-4
最后登录
2023-12-15

楼主
fan19889017 发表于 2015-3-3 12:33:30 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
  1. library(ff)
  2. library(ffbase)
  3. library(biglm)
  4. data(Affairs, package = "AER")
  5. Affairs$ynaffair[Affairs$affairs > 0] <- 1
  6. Affairs$ynaffair[Affairs$affairs == 0] <- 0

  7. gender <- as.ff(c(Affairs$gender),vmode="integer")
  8. age <- as.ff(c(Affairs$age),vmode="double")
  9. yearsmarried <- as.ff(c(Affairs$yearsmarried),vmode="double")
  10. children <- as.ff(c(Affairs$children),vmode="integer")
  11. religiousness <- as.ff(c(Affairs$religiousness),vmode="integer")
  12. education <- as.ff(c(Affairs$education),vmode="integer")
  13. occupation <- as.ff(c(Affairs$occupation),vmode="integer")
  14. rating <- as.ff(c(Affairs$rating),vmode="integer")
  15. ynaffair <- as.ff(c(Affairs$ynaffair),vmode="integer")

  16. ts <- ffdf(ynaffair,gender,age,yearsmarried,children,religiousness,education,occupation,rating)


  17. full <- bigglm.ffdf(ynaffair ~ gender + age + yearsmarried +
  18.     children + religiousness + education + occupation + rating,
  19.     data=ts,family=binomial(),chunksize=5,sandwich=)
  20. summary(full)
  21. Large data regression model: bigglm(ynaffair ~ gender + age + yearsmarried + children + religiousness +
  22.     education + occupation + rating, data = ts, family = binomial(),
  23.     chunksize = 5)
  24. Sample size =  601
  25.                  Coef    (95%     CI)     SE      p
  26. (Intercept)    0.6993 -1.2040  2.6026 0.9517 0.4624
  27. gender         0.2803 -0.1979  0.7585 0.2391 0.2411
  28. age           -0.0443 -0.0808 -0.0078 0.0182 0.0153
  29. yearsmarried   0.0948  0.0303  0.1592 0.0322 0.0033
  30. children       0.3977 -0.1853  0.9807 0.2915 0.1725
  31. religiousness -0.3247 -0.5042 -0.1452 0.0898 0.0003
  32. education      0.0211 -0.0800  0.1221 0.0505 0.6769
  33. occupation     0.0309 -0.1126  0.1745 0.0718 0.6666
  34. rating        -0.4685 -0.6503 -0.2866 0.0909 0.0000


  35. fit.full <- glm(ynaffair ~ gender + age + yearsmarried +
  36.     children + religiousness + education + occupation + rating,
  37.     data = Affairs, family = binomial())
  38. summary(fit.full)
  39. Call:
  40. glm(formula = ynaffair ~ gender + age + yearsmarried + children +
  41.     religiousness + education + occupation + rating, family = binomial(),
  42.     data = Affairs)

  43. Deviance Residuals:
  44.     Min       1Q   Median       3Q      Max  
  45. -1.5713  -0.7499  -0.5690  -0.2539   2.5191  

  46. Coefficients:
  47.               Estimate Std. Error z value Pr(>|z|)   
  48. (Intercept)    1.37726    0.88776   1.551 0.120807   
  49. gendermale     0.28029    0.23909   1.172 0.241083   
  50. age           -0.04426    0.01825  -2.425 0.015301 *  
  51. yearsmarried   0.09477    0.03221   2.942 0.003262 **
  52. childrenyes    0.39767    0.29151   1.364 0.172508   
  53. religiousness -0.32472    0.08975  -3.618 0.000297 ***
  54. education      0.02105    0.05051   0.417 0.676851   
  55. occupation     0.03092    0.07178   0.431 0.666630   
  56. rating        -0.46845    0.09091  -5.153 2.56e-07 ***
  57. ---
  58. Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

  59. (Dispersion parameter for binomial family taken to be 1)

  60.     Null deviance: 675.38  on 600  degrees of freedom
  61. Residual deviance: 609.51  on 592  degrees of freedom
  62. AIC: 627.51

  63. Number of Fisher Scoring iterations: 4
复制代码




该段程序引用自《R语言实战》第十三章,分别使用用bigglm建模,与glm建模


广义线性模型(generalized linear model, GLM)是简单最小二乘回归(OLS)的扩展,在OLS的假设中,响应变量是连续数值数据且服从正态分布,而且响应变量期望值与预测变量之间的关系是线性关系。而广义线性模型则放宽其假设,首先响应变量可以是正整数或分类数据,其分布为某指数分布族。其次响应变量期望值的函数(连接函数)与预测变量之间的关系为线性关系。因此在进行GLM建模时,需要指定分布类型和连接函数



在R中通常使用glm函数构造广义线性模型,其中分布参数包括了binomaial(两项分布)、gaussian(正态分布)、gamma(伽马分布)、poisson(泊松分布)等。和lm函数类似,glm的建模结果可以通过下述的泛型函数进行二次处理,如summary()、coef()、confint()、residuals()、anova()、plot()、predict()




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:FFBASE包 BIGGLM ffbase Base Affairs GLM BIGGLM FFBASE包

已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
niuniuyiwan + 60 + 60 + 5 + 5 + 5 精彩帖子

总评分: 经验 + 60  论坛币 + 60  学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

本帖被以下文库推荐

沙发
niuniuyiwan 在职认证  发表于 2015-9-26 17:41:54
好帖,感谢分享。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-31 01:59