turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Residual deviance using PROC NLMIXED

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-11-2011 01:19 PM

Hi,

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

Thank you.

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

Thank you.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to lk7200

05-13-2011 01:28 AM

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;

run;

Total deviance can then be obtained as:

data _null_;

set deviance end=lastrec;

deviance + resid_dev**2;

if lastrec then put deviance=;

run;

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.

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;

run;

Total deviance can then be obtained as:

data _null_;

set deviance end=lastrec;

deviance + resid_dev**2;

if lastrec then put deviance=;

run;

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Dale

05-13-2011 12:04 PM

Thank you very much!