Programming the statistical procedures from SAS

Residual deviance using PROC NLMIXED

New Contributor
Posts: 2

Residual deviance using PROC NLMIXED


Is it possible to estimate the residual deviance of a Poisson model with random effects using PROC NLMIXED?

Thank you.
Regular Contributor
Posts: 169

Re: Residual deviance using PROC NLMIXED

It is possible to generate deviance residuals from the NLMIXED procedure. But the deviance residuals have to be written to an output data set where they can be examined and the total deviance generated. For a Poisson response, code for computing deviance residuals and writing them to an output data set would be:

proc nlmixed data=mydata;
  eta = b0 + b1*x1 + b2*x2 + ... + u;
  lambda = exp(eta);
  ll_model = -lambda + y*log(lambda) - lgamma(y+1);
  if y>0 then ll_sat = -y + y*log(y) - lgamma(y+1);
  else ll_sat = 0;
  resid_dev = sign(y - lambda) * sqrt(2*(ll_sat - ll_model));
  model y ~ general(ll_model);
  random u ~ normal(0, V_u) subject=id;
  predict resid_dev out=deviance;

Total deviance can then be obtained as:

data _null_;
  set deviance end=lastrec;
  deviance + resid_dev**2;
  if lastrec then put deviance=;

Of course, you don't have to use the GENERAL log likelihood specification on the MODEL statement. You could specify that the distribution is POISSON. But it is necessary to construct the model log likelihood along with the saturated log likelihood in order to obtain the deviance residual. Once you have computed the model log likelihood, you have already done a lot of the work which the NLMIXED procedure would do if you specified a POISSON model. So, it would be computationally efficient to indicate that you want to maximize the likelihood that you have already constructed.
New Contributor
Posts: 2

Re: Residual deviance using PROC NLMIXED

Thank you very much!
Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation