[ADMB Users] MVN Example?

78 views
Skip to first unread message

Chris Gast

unread,
Mar 14, 2012, 5:50:10 PM3/14/12
to ADMB Users Group
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
cmg...@gmail.com

Mollie Brooks

unread,
Mar 14, 2012, 7:39:02 PM3/14/12
to Chris Gast, ADMB Users Group
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
mbr...@ufl.edu
http://people.biology.ufl.edu/mbrooks




_______________________________________________
Users mailing list
Us...@admb-project.org
http://lists.admb-project.org/mailman/listinfo/users

Chris Gast

unread,
Mar 14, 2012, 7:52:33 PM3/14/12
to Mollie Brooks, ADMB Users Group
Thanks, Mollie.  For some reason, ADMB can't seem to find the ln_det() function.

test_mat.obj:test_mat.cpp:(.text+0x13af): undefined reference to `ln_det(df1b2matrix&)'

I'll keep playing with it and see if I can figure it out.


Chris





-----------------------------
Chris Gast
cmg...@gmail.com

Chris Gast

unread,
Mar 14, 2012, 8:55:23 PM3/14/12
to Mollie Brooks, ADMB Users Group
After changing line 1978 in df1b2fun.h to match the correct function header on line 220 of  df1b2ludcmp.cpp, I got your syntax working successfully.

I'm not sure who specifically to address regarding making this correction, but hopefully they're reading this thread already....?

Mollie: I'm interested in what complications you experienced with solve(). Is this related to some speed issues which I found noted on previous admb-users posts?



Thanks Mollie (and Jim Ianelli for an off-list reply).

Chris




-----------------------------
Chris Gast
cmg...@gmail.com

Rubén Roa

unread,
Mar 15, 2012, 6:30:31 AM3/15/12
to Chris Gast, ADMB Users Group


Rubén H. Roa-Ureta, Ph. D.
AZTI Tecnalia, Txatxarramendi Ugartea z/g,
Sukarrieta, Bizkaia, SPAIN

Hi Chris,

I've told the JABES people that the link to sup. mat. is broken, to no avail it seems.
I'll send you the code later.

Ruben

Reply all
Reply to author
Forward
0 new messages