{"id":129,"date":"2011-02-21T01:31:00","date_gmt":"2011-02-21T09:31:00","guid":{"rendered":"http:\/\/zhanxw.com\/blog\/?p=129"},"modified":"2011-02-22T03:23:01","modified_gmt":"2011-02-22T11:23:01","slug":"exact-logistic-regression","status":"publish","type":"post","link":"https:\/\/zhanxw.com\/blog\/2011\/02\/exact-logistic-regression\/","title":{"rendered":"Exact Logistic Regression"},"content":{"rendered":"<p>We will briefly explain why we would be interested in implementing exact logistic regression, then provides C++ and R codes.<\/p>\n<p><strong>1. Why exact test? <\/strong><\/p>\n<p>Since we want to have a clear mind of how likely\/unlikely the realization we observed. In the classic example of 2&#215;2 table without covariates, especially the 2&#215;2 table has very few (&lt;5) occurrence, Fisher exact tests are often applied, and large sample theory cannot give an accurate estimation.<\/p>\n<p><strong>2. Why exact logistic regression?<\/strong><\/p>\n<p>Fisher&#8217;s exact test cannot applied to logistic model. For example, when we have covariates in the model, we want BOTH estimate the effect size and get its exact p-value. In this case, only exact logistic regression provides solution.The theoretical background is provided in reference [1].<\/p>\n<p><strong>My implementation:<\/strong><\/p>\n<p>Download: <a href=\"http:\/\/zhanxw.com\/blog\/wp-content\/uploads\/2011\/02\/exactLogisticRegression.tar.gz\">exactLogisticRegression.tar<\/a><\/p>\n<p>1. I verified the results with SAS.<br \/>\n2. The speed is comparable to, or faster than SAS.<\/p>\n<p>Cons:<br \/>\n1. Only 1 interested parameter conditioning on all other parameter is supported for now.<br \/>\n2. I have not implemented the confidence limit parts, as it&#8217;s a bit more tedious.<\/p>\n<p>R binding : <a href=\"http:\/\/zhanxw.com\/blog\/wp-content\/uploads\/2011\/02\/mypackage_1.0.tar.gz\">mypackage_1.0.tar<\/a><\/p>\n<p>See mypackage\/R\/rcpp_hello_world.R, I wrote a R function to wrap the C++ function.<\/p>\n<p>R binding is helped by RCpp package. It greatly reduced the workload of exchanging date (in the form of matrix, list, vector) between C++ and R. A quick tutorial can be found from RCpp homepage(http:\/\/dirk.eddelbuettel.com\/code\/rcpp.html). For experienced Rcpp user, the quick-ref documentation (http:\/\/dirk.eddelbuettel.com\/code\/rcpp\/Rcpp-quickref.pdf) is helpful.<\/p>\n<p>\u30101\u3011 Exact Logistic Regression, Robert E. Derr, SAS Institute Inc., Cary, NC http:\/\/support.sas.com\/rnd\/app\/da\/new\/daexactlogistic.html<\/p>\n<p>\u30102\u3011Rcpp: <a href=\"http:\/\/dirk.eddelbuettel.com\/code\/rcpp.html\"><em>Rcpp<\/em>: Seamless R and C++ Integration<\/a> <cite>dirk.eddelbuettel.com\/code\/<strong>rcpp<\/strong>.html<\/cite><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We will briefly explain why we would be interested in implementing exact logistic regression, then provides C++ and R codes. 1. Why exact test? Since we want to have a clear mind of how likely\/unlikely the realization we observed. In the classic example of 2&#215;2 table without covariates, especially the 2&#215;2 table has very few [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,15],"tags":[21,19],"class_list":["post-129","post","type-post","status-publish","format-standard","hentry","category-code","category-statistics","tag-regression","tag-statistics-2"],"_links":{"self":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts\/129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/comments?post=129"}],"version-history":[{"count":0,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts\/129\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/media?parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/categories?post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/tags?post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}