[ADMB Users] MVN Example?
Mollie Brooks
mbrooks at ufl.edu
Wed Mar 14 16:39:02 PDT 2012
Hi Chris,
I'm doing an MVN model. My procedure section looks like this
PROCEDURE_SECTION
for(int i=1; i<=ncoeffs; i++)
{
coeffs(i)=ucoeffs(i)*scale(i);
}
nLL=0;
for(int p=1; p<=nponds; p++)
{
calc_predictions(p);
calc_varcov(p);
dvar_vector diff=predictions(p)-obs(p);
dvar_matrix tmp_varcov=varcov(p);
nLL+=.5*(nobs(p)*log(2*M_PI)+ln_det(tmp_varcov)+ diff*solve2(tmp_varcov,diff));
}
The first for loop scales all my coefficients to make it conditioned better.
Then I have observations of a bunch of ponds and each pond is assumed to be independent of the others.
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.
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.
I hope this helps.
cheers,
Mollie
Mollie Brooks
Ph.D. Candidate
NSF IGERT Fellow
Biology Department
University of Florida
mbrooks at ufl.edu
http://people.biology.ufl.edu/mbrooks
On 14 Mar 2012, at 5:50 PM, Chris Gast wrote:
> Hello,
>
> 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.
>
> I found a link to a previous discussion, indicating such an example would be available in Roa's article "A Likelihood-Based Model of Fish Growth With Multiple Length Frequency Data" in JABES, but I'm having trouble accessing the supplementary material.
>
> 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.
>
> Thanks,
>
> Chris
>
>
>
>
>
>
> -----------------------------
> Chris Gast
> cmgast at gmail.com
> _______________________________________________
> Users mailing list
> Users at admb-project.org
> http://lists.admb-project.org/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/users/attachments/20120314/96bd26e5/attachment.html>
More information about the Users
mailing list