// Fitting MGLMM Beta #include template Type objective_function::operator() () { using namespace density; DATA_VECTOR(Y1); DATA_VECTOR(Y2); DATA_VECTOR(Y3); DATA_VECTOR(Y4); DATA_VECTOR(Y5); DATA_MATRIX(X); PARAMETER_VECTOR(beta1); PARAMETER_VECTOR(beta2); PARAMETER_VECTOR(beta3); PARAMETER_VECTOR(beta4); PARAMETER_VECTOR(beta5); PARAMETER_MATRIX(U); PARAMETER_VECTOR(rho); PARAMETER_VECTOR(sigma); PARAMETER_VECTOR(phi); // Preparing vector rho_temp(10); rho_temp = rho; vector sigma_temp(5); sigma_temp = sigma; vector mu1(Y1.size()); vector mu2(Y2.size()); vector mu3(Y3.size()); vector mu4(Y4.size()); vector mu5(Y5.size()); vector phi_temp(5); phi_temp = phi; // Configuration for beta density vector shapeA1(Y1.size()); vector shapeA2(Y2.size()); vector shapeA3(Y3.size()); vector shapeA4(Y4.size()); vector shapeA5(Y5.size()); vector shapeB1(Y1.size()); vector shapeB2(Y2.size()); vector shapeB3(Y3.size()); vector shapeB4(Y4.size()); vector shapeB5(Y5.size()); // Linear predictor for mean model mu1 = exp(X*beta1 + U.col(0).array())/(1 + exp(X*beta1 + U.col(0).array())); mu2 = exp(X*beta2 + U.col(1).array())/(1 + exp(X*beta2 + U.col(1).array())); mu3 = exp(X*beta3 + U.col(2).array())/(1 + exp(X*beta3 + U.col(2).array())); mu4 = exp(X*beta4 + U.col(3).array())/(1 + exp(X*beta4 + U.col(3).array())); mu5 = exp(X*beta5 + U.col(4).array())/(1 + exp(X*beta5 + U.col(4).array())); // Shape A (Beta) shapeA1 = mu1*exp(phi(0)); shapeA2 = mu2*exp(phi(1)); shapeA3 = mu3*exp(phi(2)); shapeA4 = mu4*exp(phi(3)); shapeA5 = mu5*exp(phi(4)); // Shape B (Beta) shapeB1 = (1-mu1)*exp(phi(0)); shapeB2 = (1-mu2)*exp(phi(1)); shapeB3 = (1-mu3)*exp(phi(2)); shapeB4 = (1-mu4)*exp(phi(3)); shapeB5 = (1-mu5)*exp(phi(4)); // Full log-likelihood Type nll1 = 0; for(int i=0; i Cor(5,5); Cor = UNSTRUCTURED_CORR(rho_temp).cov(); REPORT(Cor); REPORT(sigma_temp); REPORT(exp(phi)); return nll1 + nll2 + nll3 + nll4 + nll5 + nll; }