Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Fw: appling a gamma distribution random effects model. SAS to Stata


From   "Brent McSharry" <[email protected]>
To   <[email protected]>
Subject   Re: st: Fw: appling a gamma distribution random effects model. SAS to Stata
Date   Thu, 8 Dec 2011 10:53:56 +1300

Thanks for the suggestion. the entire SAS code is:

proc nlmixed data=LOS_2009;
parms b0=2.6 b1=0.005 b2=-0.7 b3=-0.3 b4=0.3 b5=0.6 b6=1.17 b7=-0.2 b8=-0.2 b9=-0.1 b10=-.01 b11=0.01 b12=-0.18 b13=0.07 b14=0.2 b16=-0.02 b17=0 b19=0 b20=0.25 b21=0.1 s2u=1 a=2; eta=b0 + b1*rs_hr124 + b2*_Ipdxcat_1 + b3*_Ipdxcat_2 + b4*_Ipdxcat_4 + b5*_Ipdxcat_5 + b6*pupils + b7*elective + b8*_Irecovbyp_1 + b9*_Irecovbyp_2 + b10*agey + b11*_Iiadm_sc_1 + b12*_Iiadm_sc_2 + b13*_Iiadm_sc_3 + b14*_Iiadm_sc_4 + b16*sbpa + b17*sbpasq + b19*_Iprev_ad_1 + b20*_Iprev_ad_2 + b21*retriev + u;
mu=exp(eta);
b=mu/a;
model los_days ~ gamma(a,b);
random u ~ normal(0,s2u) subject=PCODE out=random;
predict mu out=predout;
run;

PCODE is a variable representing the post (zip) code for each patient, which I do not believe is being used as any kind of independant variable, but seems to be somehow assisting in the generation of random normally distributed numbers.

It has more of a flavour of fitting a model than of generating random deviates

I am relieved to hear you say that (as a non-mathematician used to applying logistic regression models to generate proabilities of dying - ie a relatively simple & logical task), the addition of random numbers to a model already calibrated to a large external data set, in order to predict an expected outcome (in this case length of stay in days) seems counter-intuitive. However random effects modeling is completely outside my field of expertise!

Thank you Maarten - I will look up the STATA random number functions & any SAS functions with a few more useful keywords.

----- Original Message ----- From: "Nick Cox" <[email protected]>
To: <[email protected]>
Sent: Thursday, December 08, 2011 12:30 AM
Subject: RE: st: Fw: appling a gamma distribution random effects model. SAS to Stata


I suspect that Brent would be better off showing the whole of the SAS code so that someone bilingual (emphatically not me) can translate. It has more of a flavour of fitting a model than of generating random deviates to me, but no amount of speculation can replace expertise.

Nick
[email protected]

Maarten Buis

On Wed, Dec 7, 2011 at 10:31 AM, Brent McSharry wrote:

I have some SAS code to apply a model to patient data, and I would like to apply this to our local data (the model is externally validated to predict
length of ICU stay in days).
Unfortunately I have no idea about SAS syntax, and exclusively use stata.

the first part of the SAS code obviously generates a linear coefficient &
applies an exp link
ie in Stata:

scalar s2u = 1
scalar a = 2
generate linCoef = 0.2 + varA * 0.4 + varB*-0.02 ...
generate mu= exp(linCoef)
gen b = mu/a

and then i am affraid I am lost (particularly as the = signs stop and the
tildas ~ begin)

model los_days ~ gamma(a,b);
random u ~ normal(0,s2u) subject=varY out=random;
predict mu out=predout;
run;

I have no idea about the syntax in Some Alternative Software either,
but the tilde is often used for "distributed as", which makes sense in
your case. I guess you want to create a random variables from that
validated model. Now you need to figure out where exactly the random
term enters the model. I guess it is added to the linear predictor,
but you need to check that in the documentation of that model. You
also need to check the exact parameterization of the gamma
distribution used in that model and possibly translate that to the
parameterization used in -rgamma()-. After that it will be a couple of
-generate- commands calling the -normal()- and -rgamma()- functions,
see -help random_number_functions-.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index