-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththetalog.cpp
More file actions
32 lines (31 loc) · 748 Bytes
/
thetalog.cpp
File metadata and controls
32 lines (31 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Theta logistic population model from Pedersen et al 2012, Ecol. Modelling.
#include <TMB.hpp>
template<class Type>
Type objective_function<Type>::operator() ()
{
/* Data section */
DATA_VECTOR(Y);
/* Parameter section */
PARAMETER_VECTOR(X);
PARAMETER(logr0);
PARAMETER(logtheta);
PARAMETER(logK);
PARAMETER(logQ);
PARAMETER(logR);
/* Procedure section */
Type r0=exp(logr0);
Type theta=exp(logtheta);
Type K=exp(logK);
Type Q=exp(logQ);
Type R=exp(logR);
int timeSteps=Y.size();
Type ans=0;
for(int i=1;i<timeSteps;i++){
Type m=X[i-1]+r0*(1.0-pow(exp(X[i-1])/K,theta));
ans-=dnorm(X[i],m,sqrt(Q),true);
}
for(int i=0;i<timeSteps;i++){
ans-=dnorm(Y[i],X[i],sqrt(R),true);
}
return ans;
}