template<class Type>
Type nll_group(int i, Type p0,Type p1,Type log_lambda, Type log_sigma,
using CppAD::Integer;
int T=y.cols();
int S=N.size();
Type sigma = exp(log_sigma);
Type lambda = exp(log_lambda);
Type e=1e-12;
Type nll=0;
for(int k=0;k<S;k++){
logf(k) = log_lambda*N(k) - (lambda +
lgamma(N(k)+1));
}
Type tmp1,tmp2,tmp3;
for(int k=0;k<S;k++) {
logg(k) = 0;
for(int j=0;j<T;j++) {
if(N(k)>=y(i,j)){
tmp2=log(p(Integer(IDind(i,j)))+e)*y(i,j);
tmp3=log(Type(1.0) + e - p(Integer(IDind(i,j))))*( N(k)-y(i,j));
logg(k)+=tmp1+tmp2+tmp3;
}
else {
logg(k) = -1000;
}
}
}
fg=exp(logf+logg);
return nll;
}
template<class Type>
Type objective_function<Type>::operator() ()
{
Type nll=0;
nll+=Type(.5)*(u*u).
sum();
for(int i=0;i<R;i++){
nll+=nll_group(i, p0,p1,log_lambda,log_sigma,u(idspl(i)),y,N,x,IDind);
}
return nll;
}
License: