{"id":110,"date":"2016-08-26T11:56:03","date_gmt":"2016-08-26T03:56:03","guid":{"rendered":"http:\/\/ayonel.me\/?p=110"},"modified":"2016-12-29T10:08:01","modified_gmt":"2016-12-29T02:08:01","slug":"mixed_effect_logistic_regression","status":"publish","type":"post","link":"https:\/\/ayonel.malash.net\/index.php\/2016\/08\/26\/mixed_effect_logistic_regression\/","title":{"rendered":"\u4f7f\u7528R\u8bed\u8a00\u8fdb\u884c\u591a\u5143\u6df7\u5408\u6548\u5e94\u903b\u8f91\u56de\u5f52"},"content":{"rendered":"<p>\u591a\u5143\u6df7\u5408\u6548\u5e94\u903b\u8f91\u56de\u5f52\uff08Mixed Effects Logistic Regression\uff09\u662f\u4ec0\u4e48\uff1a<br \/>\n\u6df7\u5408\u6548\u5e94\u903b\u8f91\u56de\u5f52\u662f\u4e00\u79cd\u4e8c\u5206\u7c7b\u6a21\u578b\uff0c\u5176\u8f93\u51fa\u662f\u4e00\u7ec4\u9884\u6d4b\u53d8\u91cf(\u81ea\u53d8\u91cf)\u7684\u7ebf\u6027\u7ec4\u5408\uff0c\u4f46\u662f\u6837\u672c\u4e0d\u662f\u7b80\u5355\u5730\u72ec\u7acb\u7684\uff0c\u800c\u662f\u96c6\u7fa4\u5f0f\u5206\u5e03\uff0c\u4e5f\u5373\u67d0\u4e2a\u7fa4\u4f53\u4e4b\u95f4\u5b58\u5728\u5185\u90e8\u5173\u8054\u3002<br \/>\n\uff08Mixed effects logistic regression is used to model binary outcome variables, in which the log odds of the outcomes are modeled as a linear combination of the predictor variables when data are clustered or there are both fixed and random effects.\uff09<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff1a<br \/>\n A large HMO wants to know what patient and physician factors are most related to whether a patient&#8217;s lung cancer goes into remission after treatment as part of a larger study of treatment outcomes and quality of life in patients with lunger cancer.<br \/>\n\u4e00\u4e2a\u533b\u7597\u673a\u6784\u60f3\u8981\u77e5\u9053\u5bf9\u4e8e\u9aa8\u7624\u662f\u5426\u6700\u7ec8\u6cbb\u6108\uff0c\u533b\u751f\u548c\u75c5\u4eba\u4e4b\u95f4\u54ea\u79cd\u5c5e\u6027\u662f\u5f71\u54cd\u6700\u5927\u7684\u3002\u6bd4\u5982\u533b\u751f\u7684\u5c5e\u6027\uff1a\u4ece\u4e1a\u7ecf\u9a8c\uff0c\u5b66\u5386\u7b49\u7b49\u3002\u75c5\u4eba\u7684\u5c5e\u6027\u6709\u9aa8\u7624\u5927\u5c0f\uff0c\u60a3\u75c5\u65f6\u95f4\uff0c\u6027\u522b\u7b49\u7b49\u3002<br \/>\n\u6211\u4eec\u73b0\u5728\u5c31\u4f1a\u6709\u4e00\u7ec4\u6837\u672c\uff1a<\/p>\n<div class=\"codecolorer-container text railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"text codecolorer\">is_cured &nbsp; &nbsp;doctor &nbsp;experience &nbsp; &nbsp;education &nbsp; &nbsp;patient &nbsp; &nbsp;tumour_size &nbsp; &nbsp;tumour_time &nbsp; &nbsp;patient_sex<br \/>\n&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; Bob &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;jav &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp;<br \/>\n&nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; Bob &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hex &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1<br \/>\n&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; Bob &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lancy &nbsp; &nbsp; &nbsp; &nbsp;6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0<br \/>\n&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; Jack &nbsp; &nbsp; 5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;joogh &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp;<br \/>\n&nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; Jack &nbsp; &nbsp; 5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;silla &nbsp; &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1<br \/>\n&nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; Jack &nbsp; &nbsp; 5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;grecy &nbsp; &nbsp; &nbsp; &nbsp;6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0<br \/>\n&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; Jack &nbsp; &nbsp; 5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lori &nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp;<br \/>\n&nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; Bob &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;carl &nbsp; &nbsp; &nbsp; &nbsp; 5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1<br \/>\n&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; Bob &nbsp; &nbsp; &nbsp;10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sharun &nbsp; &nbsp; &nbsp; 6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0<\/div><\/div>\n<p>\u6211\u4eec\u73b0\u5728\u6709\u8fd9\u7ec4\u6570\u636e\uff0c\u6211\u4eec\u73b0\u5728\u8981\u9884\u6d4b\u4e00\u4e2a\u9aa8\u7624\u75c5\u4eba\u80fd\u5426\u6cbb\u6108\u3002<\/p>\n<p>\u666e\u901a\u7684\u591a\u5143\u7ebf\u6027\u903b\u8f91\u56de\u5f52\u4f1a\u628a\u6bcf\u4e00\u7ec4\u6837\u672c\u770b\u6210\u72ec\u7acb\u7684\uff0c\u4e5f\u5c31\u662f\u6837\u672c\u4e4b\u95f4\u662f\u5b8c\u5168\u72ec\u7acb\u7684\uff0c\u4f46\u662f\u5b9e\u9645\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u8fd9\u4e9b\u6837\u672c\u4e4b\u95f4\u5176\u5b9e\u662f\u805a\u96c6\u5206\u5e03\u7684\uff0c\u5b83\u4eec\u5e76\u4e0d\u662f\u5b8c\u5168\u72ec\u7acb\u3002\u540c\u4e3aBob\u533b\u751f\u7684\u6837\u672c\u4e4b\u95f4\u80af\u5b9a\u5b58\u5728\u67d0\u79cd\u5173\u8054\uff0c\u540c\u4e3aJack\u533b\u751f\u7684\u6837\u672c\u4e4b\u95f4\u4e5f\u80af\u5b9a\u5b58\u5728\u5173\u8054\u3002\u591a\u5143\u6df7\u5408\u6548\u5e94\u903b\u8f91\u56de\u5f52\u5c31\u662f\u52a0\u5165\u4e00\u4e2a\u968f\u673a\u6548\u5e94(\u4e0a\u9762\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\u5c31\u662fdoctor),\u5f25\u8865\u4e86\u666e\u901a\u7ebf\u6027\u56de\u5f52\u89c6\u6837\u672c\u4e4b\u95f4\u5e76\u4e0d\u5b58\u5728\u5173\u8054\u7684\u4e0d\u8db3\u3002<\/p>\n<p>\u6df7\u5408\u6548\u5e94\u7ebf\u6027\u56de\u5f52\u66f4\u52a0\u8d34\u8fd1\u4e8e\u771f\u5b9e\u7684\u4e16\u754c\u73af\u5883\u3002UCLA\u6709\u5341\u5206\u68d2\u7684<a href=\"http:\/\/www.ats.ucla.edu\/stat\/r\/dae\/melogit.htm\">\u6559\u7a0b<\/a>\uff0c\u5927\u5bb6\u53ef\u4ee5\u53bb\u8bfb\u4e00\u8bfb\u3002<\/p>\n<p>\u90a3\u4e48\u5982\u4f55\u5728R\u91cc\u9762\u4f7f\u7528\u6df7\u5408\u6548\u5e94\u56de\u5f52\u5462\uff1f\u6211\u4ee5\u6df7\u5408\u6548\u5e94\u903b\u8f91\u4e3a\u4f8b\u3002<br \/>\n\u8bfb\u5165\u6570\u636e\uff1a<\/p>\n<div class=\"codecolorer-container text railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"text codecolorer\">&gt;data &lt;- csv.read(&quot;data.csv&quot;)<\/div><\/div>\n<p>\u5bf9\u6570\u636e\u4e2d\u7684\u8ba1\u6570\u7c7b\u578b\uff08\u6bd4\u5982\u5e74\u9f84\u554a\uff0c\u4ece\u4e1a\u7ecf\u9a8c\u554a\u7b49\u7b49\uff09\u8fdb\u884c\u6b63\u89c4\u5316\u3002\u4e3a\u4ec0\u4e48\u9700\u8981\u6b63\u89c4\u5316\uff0c\u8bf7\u81ea\u884c\u8c37\u6b4c\u3002<\/p>\n<div class=\"codecolorer-container text railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"text codecolorer\">&gt;pvar &lt;- c(&quot;experience&quot;,&quot;education&quot;,&quot;tumour_size,tumour_time&quot;)<br \/>\n&gt;datsc -&lt; data<br \/>\n&gt;datasc[pvar] &lt;- lapply(datasc[pvar], scale) \/\/\u6b63\u89c4\u5316<\/div><\/div>\n<p>\u5f15\u5165\u6211\u4eec\u7684\u6838\u5fc3\u8ba1\u7b97\u5305lme4:<\/p>\n<div class=\"codecolorer-container text railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"text codecolorer\">&gt;require(lme4)<\/div><\/div>\n<p>\u8fdb\u884c\u8ba1\u7b97\uff1a<\/p>\n<div class=\"codecolorer-container text railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"text codecolorer\">&gt;result &lt;- glmer(is_cured ~ experience+education+tumour_size+tumour_time+(1|doctor),data=datsc,family=binomial,control=glmerControl(optimizer=&quot;bobyqa&quot;)) \/\/\u968f\u673a\u53d8\u91cfdoctor\u653e\u5728(1|doctor),\u5176\u4f59\u53d8\u91cf\u4e3a\u56fa\u5b9a\u53d8\u91cf\uff0coptimizer\u9700\u8981\u52a0\u4e0a\uff0c\u9632\u6b62\u4e0d\u6536\u655b<\/div><\/div>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<div class=\"codecolorer-container text railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"text codecolorer\">&gt;summary(result)<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u591a\u5143\u6df7\u5408\u6548\u5e94\u903b\u8f91\u56de\u5f52\uff08Mixed Effects Logistic Regression\uff09\u662f\u4ec0\u4e48\uff1a \u6df7\u5408\u6548\u5e94\u903b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-110","post","type-post","status-publish","format-standard","hentry","category-machine-learning"],"_links":{"self":[{"href":"https:\/\/ayonel.malash.net\/index.php\/wp-json\/wp\/v2\/posts\/110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ayonel.malash.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ayonel.malash.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ayonel.malash.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ayonel.malash.net\/index.php\/wp-json\/wp\/v2\/comments?post=110"}],"version-history":[{"count":3,"href":"https:\/\/ayonel.malash.net\/index.php\/wp-json\/wp\/v2\/posts\/110\/revisions"}],"predecessor-version":[{"id":249,"href":"https:\/\/ayonel.malash.net\/index.php\/wp-json\/wp\/v2\/posts\/110\/revisions\/249"}],"wp:attachment":[{"href":"https:\/\/ayonel.malash.net\/index.php\/wp-json\/wp\/v2\/media?parent=110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ayonel.malash.net\/index.php\/wp-json\/wp\/v2\/categories?post=110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ayonel.malash.net\/index.php\/wp-json\/wp\/v2\/tags?post=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}