楼主: Lisrelchen
835 3

Tutorials: Re-thinking How Family Researchers Model Infrequent Outcomes [推广有奖]

  • 0关注
  • 62粉丝

VIP

已卖:4194份资源

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
50288 个
通用积分
83.6306
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

楼主
Lisrelchen 发表于 2016-5-29 05:10:49 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
Tutorials: Re-thinking How Family Researchers Model Infrequent Outcomes

Atkins, D. C., & Gallop, R. J. (2007). Re-thinking how family researchers model infrequent outcomes: A tutorial on count regression and zero-inflated models. Journal of Family Psychology, 21, 726-735.

[Paper]
[Data]
[R code]
[SPSS code]
[SAS code]
[Mplus code]



二维码

扫码加我 拉你入群

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

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

关键词:Researchers Researcher Tutorials Research Tutorial Journal family count

沙发
Lisrelchen 发表于 2016-5-29 05:11:54
Using SPSS
  1. GET DATA  /TYPE = TXT
  2. /FILE = '[INSERT PATH AND FILE NAME]'
  3. /DELCASE = LINE
  4. /DELIMITERS = " "
  5. /ARRANGEMENT = DELIMITED
  6. /FIRSTCASE = 2
  7. /IMPORTCASE = ALL
  8. /VARIABLES =
  9. id F2.0
  10. gender F1.0
  11. msi F2.0
  12. das F3.0
  13. sex F2.0
  14. afc F2.0
  15. infidelity F1.0
  16. .

  17. *** Change sex to be 0/1  .
  18. COMPUTE gender = gender - 1 .
  19. EXECUTE .

  20. *** Set value labels for categorical variables .
  21. VALUE LABELS gender 0 'Wife' 1 'Husband'
  22.   /infidelity 0 'No infidelity' 1 'Infidelity' .

  23. *** Fit Poisson model - requires version 15 of SPSS .
  24. * Generalized Linear Models.
  25. GENLIN
  26.   msi
  27.   BY gender infidelity
  28.   (ORDER=DESCENDING)
  29.   WITH das sex afc
  30. /MODEL
  31.   gender infidelity das sex afc infidelity*das
  32.   INTERCEPT=YES
  33.   DISTRIBUTION=POISSON
  34.   LINK=LOG
  35. /CRITERIA METHOD=FISHER(1) SCALE=1 COVB=MODEL
  36.   MAXITERATIONS=100 MAXSTEPHALVING=5
  37.   PCONVERGE=1E-006(ABSOLUTE)
  38.   SINGULAR=1E-012
  39.   ANALYSISTYPE=3 CILEVEL=95 LIKELIHOOD=FULL
  40. /MISSING CLASSMISSING=EXCLUDE
  41. /PRINT CPS DESCRIPTIVES MODELINFO FIT SUMMARY SOLUTION(EXPONENTIATED).

  42. *** Fit Negative Binomial model - requires version 15 of SPSS .
  43. * Generalized Linear Models.
  44. GENLIN
  45.   msi
  46.   BY gender infidelity
  47.   (ORDER=DESCENDING)
  48.   WITH das sex afc
  49. /MODEL
  50.   gender infidelity das sex afc infidelity*das
  51.   INTERCEPT=YES
  52.   DISTRIBUTION=NEGBIN(1)
  53.   LINK=LOG
  54. /CRITERIA METHOD=FISHER(1) SCALE=1 COVB=MODEL
  55.   MAXITERATIONS=100 MAXSTEPHALVING=5
  56.   PCONVERGE=1E-006(ABSOLUTE)
  57.   SINGULAR=1E-012
  58.   ANALYSISTYPE=3 CILEVEL=95 LIKELIHOOD=FULL
  59. /MISSING CLASSMISSING=EXCLUDE
  60. /PRINT CPS DESCRIPTIVES MODELINFO FIT SUMMARY SOLUTION(EXPONENTIATED).
复制代码

藤椅
Lisrelchen 发表于 2016-5-29 05:12:36
Using SAS
  1. ********************************************************************************************
  2. * The following SAS code accompanies the article:
  3. * Atkins, D. C., & Gallop, R. J. (2007). Re-thinking how family researchers model infrequent
  4. * outcomes: A tutorial on count regression and zero-inflated models.  Journal of Family
  5. * Psychology.
  6. *                                                                                          *
  7. ********************************************************************************************
  8. ;



  9. options formdlim=' ' ls=90 ps=50 ;



  10. data mardas;
  11. input id gender msi das sex afc infidelity;
  12. cards;
  13. 1 1 4 70 61 65 0
  14. 1 2 3 92 64 69 0
  15. 2 1 7 45 69 69 0
  16. 2 2 4 49 68 69 0
  17. 3 1 4 79 49 49 0
  18. 3 2 0 90 56 57 0
  19. 4 1 8 92 66 56 0
  20. 4 2 2 70 68 67 0
  21. 5 1 2 87 42 65 0
  22. 5 2 3 75 56 59 0
  23. 6 1 6 67 49 69 0
  24. 6 2 5 66 64 72 0
  25. 7 1 0 81 73 69 0
  26. 7 2 0 91 61 65 0
  27. 8 1 2 102 58 54 1
  28. 8 2 0 75 61 63 1
  29. 9 1 6 71 35 63 1
  30. 9 2 2 110 56 67 1
  31. 10 1 0 112 42 49 0
  32. 10 2 0 91 54 57 0
  33. 11 1 4 88 64 62 0
  34. 11 2 2 98 61 63 0
  35. 12 1 7 95 69 63 0
  36. 12 2 2 109 56 61 0
  37. 13 1 1 92 69 58 0
  38. 13 2 0 102 56 61 0
  39. 14 1 3 103 79 52 0
  40. 14 2 0 85 64 61 0
  41. 15 1 3 92 55 69 0
  42. 15 2 2 108 46 54 0
  43. 16 1 1 113 73 60 0
  44. 16 2 1 91 56 65 0
  45. 17 1 5 90 61 69 0
  46. 17 2 3 92 56 61 0
  47. 18 1 6 88 73 60 1
  48. 18 2 4 71 54 72 1
  49. 19 1 3 88 73 58 0
  50. 20 1 5 95 61 62 0
  51. 20 2 6 70 75 72 0
  52. 21 1 0 59 66 74 0
  53. 21 2 1 71 52 72 0
  54. 22 1 6 71 58 69 0
  55. 22 2 6 40 75 69 0
  56. 23 1 9 68 73 65 1
  57. 23 2 11 59 75 76 1
  58. 24 1 7 71 73 74 0
  59. 24 2 2 87 64 57 0
  60. 25 1 2 84 66 65 0
  61. 25 2 1 89 64 65 0
  62. 26 1 1 76 66 74 0
  63. 26 2 3 86 64 65 0
  64. 27 1 6 79 73 69 0
  65. 27 2 2 82 50 65 0
  66. 28 1 6 72 35 62 0
  67. 28 2 5 91 40 65 0
  68. 29 1 6 89 66 69 0
  69. 29 2 4 82 40 69 0
  70. 30 1 6 95 73 49 0
  71. 30 2 1 113 56 65 0
  72. 31 1 4 95 46 62 0
  73. 31 2 4 63 48 57 0
  74. 32 1 3 75 51 65 0
  75. 32 2 0 93 40 54 0
  76. 33 1 0 82 69 62 0
  77. 33 2 4 96 68 76 0
  78. 34 1 4 56 61 69 0
  79. 34 2 5 57 68 69 0
  80. 35 1 8 76 64 63 0
  81. 35 2 0 100 52 54 0
  82. 36 1 4 62 66 62 1
  83. 36 2 0 88 68 57 1
  84. 37 1 1 97 58 54 0
  85. 37 2 3 87 75 76 0
  86. 38 1 1 83 64 52 0
  87. 38 2 2 94 58 63 0
  88. 39 1 0 98 55 56 0
  89. 39 2 0 89 44 57 0
  90. 40 1 0 94 46 54 0
  91. 40 2 0 99 50 63 0
  92. 41 1 0 81 79 60 0
  93. 41 2 1 91 54 52 0
  94. 42 1 0 94 55 62 0
  95. 42 2 0 83 56 57 0
  96. 43 1 5 70 61 74 0
  97. 43 2 2 56 61 76 0
  98. 44 1 1 101 35 63 0
  99. 44 2 8 93 44 65 0
  100. 45 1 4 77 55 63 0
  101. 45 2 2 83 61 72 0
  102. 46 1 2 93 69 54 0
  103. 46 2 2 82 75 54 0
  104. 47 1 3 85 58 58 1
  105. 47 2 7 96 75 76 1
  106. 48 1 5 82 51 65 0
  107. 48 2 1 78 50 69 0
  108. 49 1 5 72 49 63 0
  109. 49 2 5 70 54 63 0
  110. 50 1 0 94 42 62 0
  111. 50 2 0 87 54 67 0
  112. 51 1 0 103 66 52 0
  113. 51 2 0 81 58 65 0
  114. 52 1 2 70 66 62 1
  115. 52 2 4 49 68 67 1
  116. 53 1 6 81 58 58 0
  117. 53 2 4 96 58 69 0
  118. 54 1 8 68 69 69 0
  119. 54 2 4 79 61 76 0
  120. 55 1 9 97 58 74 1
  121. 55 2 7 98 56 76 1
  122. 56 1 3 94 55 54 0
  123. 56 2 3 102 68 57 0
  124. 57 1 7 105 61 65 1
  125. 57 2 8 86 75 72 1
  126. 58 1 6 93 55 46 1
  127. 58 2 6 57 61 65 1
  128. 59 1 5 69 61 52 0
  129. 59 2 7 92 61 67 0
  130. 60 1 4 93 66 63 0
  131. 60 2 3 80 64 72 0
  132. 61 1 0 101 61 56 0
  133. 61 2 4 86 68 72 0
  134. 62 1 2 98 64 52 0
  135. 62 2 2 93 68 65 0
  136. 63 1 0 95 42 62 0
  137. 63 2 0 89 52 65 0
  138. 64 1 9 74 73 62 1
  139. 64 2 0 88 56 57 1
  140. 65 1 4 70 66 49 1
  141. 65 2 4 47 64 67 1
  142. 66 1 0 97 66 63 0
  143. 66 2 2 87 46 54 0
  144. 67 1 7 64 69 69 0
  145. 67 2 1 99 56 69 0
  146. 68 1 0 52 61 65 1
  147. 68 2 0 63 68 76 1
  148. 69 1 7 69 66 74 1
  149. 69 2 9 77 61 69 1
  150. 70 1 6 88 69 65 1
  151. 70 2 5 91 61 57 1
  152. 71 2 0 74 58 63 0
  153. 72 1 4 89 49 63 0
  154. 72 2 7 96 58 67 0
  155. 73 1 5 76 79 65 0
  156. 73 2 6 95 75 72 0
  157. 74 1 5 95 64 46 0
  158. 74 2 3 95 52 63 0
  159. 75 1 0 105 61 60 0
  160. 75 2 2 93 48 54 0
  161. 76 1 0 102 49 58 0
  162. 76 2 1 78 40 52 0
  163. 77 1 1 94 64 63 0
  164. 77 2 0 88 44 45 0
  165. 78 1 6 87 73 58 0
  166. 78 2 1 100 58 61 0
  167. 79 1 4 81 79 65 0
  168. 79 2 4 95 68 59 0
  169. 80 1 0 97 46 58 0
  170. 80 2 0 95 34 52 0
  171. 81 1 4 85 49 54 0
  172. 81 2 0 93 61 59 0
  173. 82 1 7 49 66 74 0
  174. 82 2 1 74 75 72 0
  175. 83 1 2 70 69 69 0
  176. 83 2 2 89 68 65 0
  177. 84 1 0 107 53 62 0
  178. 84 2 0 91 64 54 0
  179. 85 1 8 81 73 74 0
  180. 85 2 5 83 52 61 0
  181. 86 1 0 78 73 60 0
  182. 86 2 0 107 52 61 0
  183. 87 1 0 96 64 62 0
  184. 87 2 3 106 61 52 0
  185. 88 1 5 74 79 65 0
  186. 88 2 0 109 68 52 0
  187. 89 1 0 91 55 69 0
  188. 89 2 0 84 68 72 0
  189. 90 1 10 68 64 60 0
  190. 90 2 4 64 54 63 0
  191. 91 1 1 92 55 58 0
  192. 91 2 2 108 58 57 0
  193. 92 1 0 103 58 46 0
  194. 92 2 2 88 68 63 0
  195. 93 1 0 96 69 62 0
  196. 93 2 2 74 61 65 0
  197. 94 1 3 90 73 69 0
  198. 95 1 1 86 55 69 0
  199. 95 2 2 84 58 57 0
  200. 96 1 3 79 66 69 0
  201. 96 2 0 99 56 63 0
  202. 97 1 0 72 58 60 0
  203. 97 2 3 72 68 67 0
  204. 98 1 3 91 69 69 0
  205. 98 2 4 83 68 65 0
  206. 99 1 6 57 64 69 0
  207. 99 2 5 69 56 69 0
  208. 100 1 6 101 61 58 0
  209. 100 2 8 96 68 63 0
  210. 101 1 0 84 51 60 0
  211. 101 2 5 83 46 57 0
  212. 102 1 6 85 53 62 0
  213. 102 2 7 76 64 76 0
  214. 103 1 3 77 61 65 0
  215. 103 2 0 88 68 72 0
  216. 104 1 0 93 53 62 0
  217. 104 2 4 80 54 65 0
  218. 105 1 3 84 42 63 0
  219. 105 2 5 97 54 69 0
  220. 106 1 0 89 61 63 0
  221. 106 2 0 91 75 69 0
  222. 107 1 4 87 49 74 0
  223. 107 2 1 87 64 65 0
  224. 108 1 0 103 53 56 0
  225. 108 2 6 94 44 45 0
  226. 109 1 4 93 35 58 0
  227. 109 2 2 94 68 67 0
  228. 110 1 5 53 55 65 0
  229. 110 2 4 79 68 72 0
  230. 111 1 7 92 61 65 0
  231. 111 2 7 87 46 59 0
  232. 112 1 0 76 42 54 0
  233. 112 2 4 92 58 65 0
  234. 113 1 1 89 64 63 0
  235. 113 2 1 62 64 69 0
  236. 114 1 2 74 61 62 0
  237. 114 2 5 66 68 72 0
  238. 115 1 8 67 79 74 1
  239. 115 2 5 75 64 72 1
  240. 116 1 3 70 64 74 1
  241. 116 2 4 71 75 72 1
  242. 117 1 0 90 55 58 0
  243. 117 2 1 94 58 67 0
  244. 118 1 6 83 55 63 1
  245. 118 2 5 54 75 72 1
  246. 119 1 8 74 58 74 0
  247. 119 2 6 70 68 67 0
  248. 120 1 1 63 58 65 0
  249. 120 2 1 72 58 65 0
  250. 121 1 3 93 61 63 0
  251. 121 2 2 102 61 65 0
  252. 122 1 8 95 73 60 0
  253. 122 2 6 55 64 63 0
  254. 123 1 7 103 69 60 0
  255. 123 2 2 94 68 69 0
  256. 124 1 3 99 61 65 0
  257. 124 2 7 85 34 54 0
  258. 125 1 0 90 66 56 0
  259. 125 2 0 103 68 69 0
  260. 126 1 5 75 66 63 0
  261. 126 2 3 71 68 63 0
  262. 127 1 0 115 64 49 0
  263. 127 2 1 83 52 69 0
  264. 128 1 4 93 73 65 0
  265. 128 2 0 99 52 54 0
  266. 129 1 4 93 55 63 0
  267. 129 2 0 100 34 61 0
  268. 130 1 2 93 73 62 0
  269. 130 2 3 86 58 67 0
  270. 131 1 5 95 58 69 1
  271. 131 2 9 62 58 67 1
  272. 132 1 2 103 35 62 0
  273. 132 2 6 85 44 61 0
  274. 133 1 8 58 61 65 0
  275. 133 2 8 58 64 76 0
  276. ;
  277. run;

  278. proc contents data=mardas position short;
  279. quit;



  280. proc ttest data=mardas;
  281. class gender;* infidelity;
  282. var msi;
  283. quit;
  284. proc ttest data=mardas;
  285. class infidelity;
  286. var msi;
  287. quit;

  288. proc freq data=mardas;
  289. quit;

  290. proc means data=mardas;
  291. var das sex afc;
  292. output out=o mean=mndas mnsex mnafc;
  293. quit;


  294. proc sql;
  295. create table mardas as
  296. select a.*, b.*
  297. from  mardas a left join o b
  298. on a.id and a.gender;
  299. quit;


  300. proc means data=mardas;
  301. quit;



  302. data mardas;
  303. set mardas;
  304. genderl = (gender=2);
  305. infidelityTRUE = (infidelity=1);



  306. das_c = das - mndas;
  307. sex_c = sex - mnsex;
  308. afc_c = afc - mnafc;

  309. das_c_inf = das_c* infidelityTrue;
  310. run;



  311. proc means data=mardas;
  312. quit;



  313. ods pdf file='D:\Smstat\Datkins\zip and zinb in sas.pdf';

  314. proc genmod data=mardas;
  315. title 'Poisson Regression';
  316.       model msi = das_c infidelityTRUE genderl afc_c sex_c das_c_inf
  317.         / link=log dist=poisson;
  318. quit;title;





  319. proc genmod data=mardas;
  320. title 'Negative Binomial Model';
  321.       model msi = das_c infidelityTRUE genderl afc_c sex_c das_c_inf
  322.         / link=log dist=negbin;
  323. quit;title;



  324. data mardas;
  325. set mardas;
  326. RESPONSE = MSI;
  327. run;



  328. proc nlmixed data=mardas ;
  329. title 'ZIP Model';

  330. /* a0 = intercept of the logistic model of the inflation prob, a1 is that slope, b0-b1 are the regression coefficients for the Poisson mean */

  331. parameters a0=0 a1=0 a2=0 a3=0 a4=0 a5=0 a6=0
  332.         b0=0 b1=0 b2=0 b3=0 b4=0 b5=0 b6=0;

  333. /* linear predictor for the inflation probability       */

  334. linpinfl = a0 +a1*das_c+ a2*infidelityTRUE
  335.         +a3*genderl+a4*afc_c+a5*sex_c+a6*das_c_inf ;

  336. /* infprob = inflation probability for zeros            */

  337. /*         = logistic transform of the linear predictor */

  338. infprob  = 1/(1+exp(-linpinfl));

  339. /* Poisson mean */

  340. lambda   = exp(b0 +b1*das_c+ b2*infidelityTRUE
  341.         +b3*genderl+b4*afc_c+b5*sex_c+b6*das_c_inf  );

  342. /* Build the ZIP log likelihood */

  343. if response=0 then

  344.       ll = log(infprob + (1-infprob)*exp(-lambda));

  345. else ll = log((1-infprob)) + RESPONSE*log(lambda) - lgamma(response+1) - lambda;

  346. model RESPONSE  ~ general(ll);

  347. /*  predict statement to get the predicted number of RESPONSES given the Poisson mean and the inflation probability */

  348. predict (1-infprob)*lambda out = PREDICTED_RESPONSE;

  349. quit;title;







  350. data mardas;
  351. set mardas;
  352. density = MSI;
  353. run;


  354. proc nlmixed data=mardas;
  355. title 'ZINB Model';
  356. parameters a0=0 a1=0 a2=0 a3=0 a4=0 a5=0 a6=0
  357.         b0=0 b1=0 b2=0 b3=0 b4=0 b5=0 b6=0;


  358. linpinfl = a0 +a1*das_c+ a2*infidelityTRUE
  359.         +a3*genderl+a4*afc_c+a5*sex_c+a6*das_c_inf;

  360.   psi = 1 / (1 + exp(linpinfl));

  361.   eta_nb = (b0 +b1*das_c+ b2*infidelityTRUE
  362.         +b3*genderl+b4*afc_c+b5*sex_c+b6*das_c_inf);

  363.   lambda = exp(eta_nb);

  364.   p0 = psi + (1-psi)*exp(-(density+(1/k))*log(1+k*lambda));

  365.   p_else = (1-psi)* exp(lgamma(density+(1/k)) - lgamma(density+1) - lgamma(1/k) +

  366.                density*log(k*lambda) - (density+(1/k))*log(1+k*lambda));

  367.   if density=0 then loglike = log(p0); else  loglike = log(p_else);

  368.   model density ~ general(loglike);

  369. quit;title;



  370. ods pdf close;


  371. proc nlmixed data=mardas qpoints=12;                                                                                                         

  372. title 'ZINB Model with Random Effects';                                                                                                      

  373. footnote 'We fit only a Random Intercept in Zero only';                                                                                    

  374. parameters a0=-1.5 a1=0.05 a2=-0.57 a3=-0.03 a4=-0.06 a5=-0.02 a6=-0.08                                                                       

  375.         b0=1.38 b1=-0.01 b2=0.39 b3=-0.20 b4=0.01 b5=0 b6=0.01                                                                                

  376.           v1=0.3;

  377.   *v2=1.0;   ***variance for second random effect if fitted***;                                                                                                              

  378.   u2=0;     ****random effect 2 set to 0 since it is not fitted***;                                                                                                                                 

  379. linpinfl = a0+u1 +a1*das_c+ a2*infidelityTRUE                                                                                                

  380.         +a3*genderl+a4*afc_c+a5*sex_c+a6*das_c_inf;                                                                                          

  381.                                                                                                                                              

  382.   psi = 1 / (1 + exp(linpinfl));                                                                                                              

  383.                                                                                                                                              

  384.   eta_nb = (b0+u2 +b1*das_c+ b2*infidelityTRUE                                                                                                

  385.         +b3*genderl+b4*afc_c+b5*sex_c+b6*das_c_inf);                                                                                          

  386.                                                                                                                                              

  387.   lambda = exp(eta_nb);                                                                                                                       

  388.                                                                                                                                              

  389.   p0 = psi + (1-psi)*exp(-(density+(1/k))*log(1+k*lambda));                                                                                   

  390.                                                                                                                                              

  391.   p_else = (1-psi)* exp(lgamma(density+(1/k)) - lgamma(density+1) - lgamma(1/k) +                                                            

  392.                                                                                                                                              

  393.                density*log(k*lambda) - (density+(1/k))*log(1+k*lambda));                                                                     

  394.                                                                                                                                              

  395.   if density=0 then loglike = log(p0); else  loglike = log(p_else);                                                                           

  396.                                                                                                                                              

  397.   model density ~ general(loglike);                                                                                                           

  398. * random u1 u2 ~normal([0,0],[v1,0,v2]) subject=ID;    ***Use this line if we wanted to fit both random effects***;                                                                                       

  399. random u1 ~normal(0,v1) subject=ID;                                                                                                         

  400.                                                                                                                                              

  401. quit;title; footnote   
复制代码

板凳
Lisrelchen 发表于 2016-5-29 05:13:26
Using Mplus
  1. ! The following code will run the zero-inflated Poisson (ZIP) model (assuming
  2. ! data has been renamed to NegOutcomeData.dat).  MPLUS can do the random effects
  3. ! model, but this requires a reconstruction of the data set.  There's a video on
  4. ! the UCLA Stat support website that is quite clear:
  5. !
  6. ! http://www.ats.ucla.edu/stat/mplus/seminars/lzip/default.htm
  7. !
  8.                                                                                                                
  9. DATA:
  10.         FILE is NegOutcomeData.dat;
  11. VARIABLE:
  12.         NAMES ARE MSI  das_c infidelityTRUE   genderl afc_c sex_c das_c_inf ;
  13.         COUNT is MSI (i);
  14. MODEL:
  15.         MSI ON das_c infidelityTRUE   genderl afc_c sex_c das_c_inf ;
  16.         MSI#1 ON das_c infidelityTRUE   genderl afc_c sex_c das_c_inf ;


  17.                                                                                                                         
  18.                                     
复制代码

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

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