template<class Type>
Type objective_function<Type>::operator() ()
{
Type tau = exp(log_tau);
Type kappa = exp(log_kappa);
Type alpha = exp(log_alpha);
Type nll = 0.0;
H(0,0) = exp(ln_H_input(0));
H(1,0) = ln_H_input(1);
H(0,1) = ln_H_input(1);
H(1,1) = (1+ln_H_input(1)*ln_H_input(1)) / exp(ln_H_input(0));
SparseMatrix<Type> Q =
Q_spde(spde,kappa,H);
if (flag == 0) return nll;
vector<Type> Xbeta = X*beta;
for(int i=0; i<time.size(); i++){
Type eta = Xbeta(i) + x(meshidxloc(i))/tau;
Type lambda = exp(eta);
Type t_alpha = pow(time(i),alpha);
Type S = exp(-lambda*t_alpha);
Type f = lambda*alpha*t_alpha/time(i)*S;
if(notcens(i))
nll -= log(f);
else
nll -= log(S);
}
return nll;
}
License: