<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Chris,<div>I'm doing an MVN model. My procedure section looks like this</div><div><div>PROCEDURE_SECTION</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>for(int i=1; i<=ncoeffs; i++)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>coeffs(i)=ucoeffs(i)*scale(i);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}<span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>nLL=0;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>for(int p=1; p<=nponds; p++)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>calc_predictions(p);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>calc_varcov(p);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>dvar_vector diff=predictions(p)-obs(p);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>dvar_matrix tmp_varcov=varcov(p);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>nLL+=.5*(nobs(p)*log(2*M_PI)+ln_det(tmp_varcov)+ diff*solve2(tmp_varcov,diff));</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div>The first for loop scales all my coefficients to make it conditioned better.</div><div>Then I have observations of a bunch of ponds and each pond is assumed to be independent of the others.</div><div>I defined functions calc_predictions() and calc_varcov() to fill in those objects; the code in these is pretty specific to my problem. The important thing fir efficiency is that my covariates are in a design matrix created using model.matrix() in R.</div><div><br></div><div>Try using solve() where I have solve2(). If you have a problem with solve, I'll explain the complications of why I used this version.</div><div><br></div><div>I hope this helps.</div><div>cheers,</div><div>Mollie</div><div><br></div><div>
Mollie Brooks<br>Ph.D. Candidate<br>NSF IGERT Fellow<br>Biology Department<br>University of Florida<br><a href="mailto:mbrooks@ufl.edu">mbrooks@ufl.edu</a><br>http://people.biology.ufl.edu/mbrooks<br><br><br><br>
</div>
<br><div><div>On 14 Mar 2012, at 5:50 PM, Chris Gast wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hello,<div><br></div><div>Does anyone have some code to compute the log-likelihood for a multivariate normal model that they're willing to share? I'm having trouble getting matrix determinants and inverses to work.</div>
<div><br></div><div>I found a link to a previous discussion, indicating such an example would be available in Roa's article "<span style="background-color:rgb(255,255,255)">A Likelihood-Based Model of Fish Growth With Multiple Length Frequency Data" in JABES, but I'm having trouble accessing the supplementary material.</span></div>
<div><br></div><div>If I can get this working (a weighted LMM with autocorrelated residuals and spatially-correlated random effects), I'd be happy to add it to the examples list, since I can't seem to find a MVN likelihood example there either.</div>
<div><br></div><div>Thanks,</div><div><br></div><div>Chris</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br><br>-----------------------------<br>Chris Gast<br><a href="mailto:cmgast@gmail.com">cmgast@gmail.com</a><br>
</div>
_______________________________________________<br>Users mailing list<br><a href="mailto:Users@admb-project.org">Users@admb-project.org</a><br>http://lists.admb-project.org/mailman/listinfo/users<br></blockquote></div><br></div></body></html>