One way of speeding that up would be to use `glm.fit` instead of `glm`. It just means you'll have to calculate a few extra variables outside the loop (which `glm` will be calculating every time you call it).<br><br><div class="gmail_quote">
On Fri, Jan 13, 2012 at 2:53 PM, Jason LaCombe <span dir="ltr"><<a href="mailto:jlacombe@naturesourcegenetics.com">jlacombe@naturesourcegenetics.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="blue" vlink="purple" lang="EN-US">
<div>
<p class="MsoNormal">Hi Everyone,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I’m trying to perform the following task more efficiently in Rcpp, and am running into some trouble…<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Here’s a simplified example of the sort of R code I’m trying to optimize, for Y a binary random variable, X a categorical variable with 3 classes:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">For(I in 1:100000)<u></u><u></u></p>
<p class="MsoNormal">{<u></u><u></u></p>
<p class="MsoNormal"> glm(X~Y, family=”binomial”);<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">This seems like an excellent candidate for Rcpp--I simply wish to evaluate the ‘for’ loop in c++ to reduce the computational overhead.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">What I would like to <b>avoid</b> is having to re-write code for explicitly evaluating a generalized linear model in c++. Any quick-and-dirty solution is acceptable. Two approaches that I have tried and been unsuccessful with are:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">-Attempting to expose the C glm methods from the R stats package<u></u><u></u></p>
<p class="MsoNormal">-Working with the RcppModels package [having trouble with this due to my inability to find documentation, not that there isn’t some out there]<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Any thoughts, references, or corrections to my above approaches would be appreciated.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Jason<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<br>_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br></blockquote></div><br>