Skip to content

Instantly share code, notes, and snippets.

@jcquiroz
Created January 16, 2012 14:53
Show Gist options
  • Save jcquiroz/1621215 to your computer and use it in GitHub Desktop.
Save jcquiroz/1621215 to your computer and use it in GitHub Desktop.
likelihoodStats.cxx
#include <admodel.h>
//=================================================================================
// Likelihoods for abundance indices or catch
//=================================================================================
dvar_vector nlikelihood(dvector observed, dvar_vector expected, dvector cv, int LikeType)
{
RETURN_ARRAYS_INCREMENT();
dvar_vector logLike;
switch (LikeType)
{
case 0: //not used
break;
case 1: //normal
logLike=elem_div(square(observed-expected), 2*square(elem_prod(cv,observed)));
break;
case 2: //lognormal
logLike=elem_div(square(log(observed)-log(expected)),2*square(cv));
break;
default:
cout<<"No such likelihood: "<<LikeType<<" /n";
break;
}
RETURN_ARRAYS_DECREMENT();
return(logLike);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment