Thanks, Mollie. For some reason, ADMB can't seem to find the ln_det() function.<div><br></div><div>test_mat.obj:test_mat.cpp:(.text+0x13af): undefined reference to `ln_det(df1b2matrix&)'</div><div><br></div><div>
I'll keep playing with it and see if I can figure it out.</div><div><br></div><div><br></div><div>Chris</div><div><br></div><div><br></div><div><br></div><div><br clear="all"><br>-----------------------------<br>Chris Gast<br>
<a href="mailto:cmgast@gmail.com">cmgast@gmail.com</a><br>
<br><br><div class="gmail_quote">On Wed, Mar 14, 2012 at 4:39 PM, Mollie Brooks <span dir="ltr"><<a href="mailto:mbrooks@ufl.edu">mbrooks@ufl.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Hi Chris,<div>I'm doing an MVN model. My procedure section looks like this</div><div><div>PROCEDURE_SECTION</div><div><span style="white-space:pre-wrap"> </span>for(int i=1; i<=ncoeffs; i++)</div>
<div><span style="white-space:pre-wrap"> </span>{</div><div><span style="white-space:pre-wrap"> </span>coeffs(i)=ucoeffs(i)*scale(i);</div><div><span style="white-space:pre-wrap"> </span>}<span style="white-space:pre-wrap"> </span></div>
<div><span style="white-space:pre-wrap"> </span>nLL=0;</div><div><span style="white-space:pre-wrap"> </span>for(int p=1; p<=nponds; p++)</div><div><span style="white-space:pre-wrap"> </span>{</div><div><span style="white-space:pre-wrap"> </span>calc_predictions(p);</div>
<div><span style="white-space:pre-wrap"> </span>calc_varcov(p);</div><div><span style="white-space:pre-wrap"> </span>dvar_vector diff=predictions(p)-obs(p);</div><div><span style="white-space:pre-wrap"> </span>dvar_matrix tmp_varcov=varcov(p);</div>
<div><span style="white-space:pre-wrap"> </span></div><div><span style="white-space:pre-wrap"> </span>nLL+=.5*(nobs(p)*log(2*M_PI)+ln_det(tmp_varcov)+ diff*solve2(tmp_varcov,diff));</div><div><span style="white-space:pre-wrap"> </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><span class="HOEnZb"><font color="#888888"><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" target="_blank">mbrooks@ufl.edu</a><br><a href="http://people.biology.ufl.edu/mbrooks" target="_blank">http://people.biology.ufl.edu/mbrooks</a><br>
<br><br><br>
</div>
<br></font></span><div><div><div class="h5"><div>On 14 Mar 2012, at 5:50 PM, Chris Gast wrote:</div><br></div></div><blockquote type="cite"><div><div class="h5">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>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" target="_blank">cmgast@gmail.com</a><br>
</div></div></div><div class="im">
_______________________________________________<br>Users mailing list<br><a href="mailto:Users@admb-project.org" target="_blank">Users@admb-project.org</a><br><a href="http://lists.admb-project.org/mailman/listinfo/users" target="_blank">http://lists.admb-project.org/mailman/listinfo/users</a><br>
</div></blockquote></div><br></div></div></blockquote></div><br></div>