BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
slea
Calcite | Level 5

Hi,

I am simulating the data for Poisson regression. I want to know how do I simulate the time for Poisson regression model. My assumption is all subjects are followed for 5 years. How do I fit the time in the ETA1 equation that I am using in my program. 

 

%let N = 500;
%let nCont = 5;

data SimPoiReg1;
call streaminit(54321);
array x[&nCont];

array beta[0:5] (1.0034 -0.2115 -0.145 -0.0944 -0.1097 -0.0999);
do i = 1 to &N;
x[1] = Rand("normal", 20, 1.5);
x[2] = rand("normal", 15, 2);
x[3] = rand("normal",10, 0.2);
x[4] = rand("normal", 50, 2);
x[5] = rand("normal", 100, 3);
eta = beta[0];
do j = 1 to &nCont;
eta1 = eta + beta2 * x1 + beta3 * x2 + beta4 * x3 + beta5 * x4 + beta6 * x5;
end;
lambda=exp(eta1);
Y = rand("Poisson",lambda) ;
output;
end;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

The nice thing about simulation is that you don't need to guess if your simulation is correct. Generate 10,000 observations and then run the model through PROC GENMOD. If the parameter estimates are close to the parameters that generated the data, then that is strong evidence that the simulation is correct.

 

Without showing the MODEL statement that you are trying to use, it is hard for us to know whether the simulation is correct. But once you write down the MODEL statement, you don't really need to ask other people's opinions.

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ

> how do I simulate the time for Poisson regression model.

 

I don't understand your question. You simulation shows the simulation of counts, Y, that follow a Poisson rv with expected value exp(eta1). This seems correct. Maybe you should show what you expect the data to look like.

 

Are you saying that you want a rate (counts per year)? This can be added to the model by using an offset. See the Wikipedia article on Poisson regression. If all subjects were observed for 5 years, the Wikipedia formula appears to be 

Y = 5*exp(eta1).

In general, if the i_th subject was observed for t[i] > 0 years, then the equation looks like

Y[i] = t[i] * exp(eta1).

 

For fitting the model, you'll want to include the offset variable in the model.

 

 

slea
Calcite | Level 5

Hello,

 

Thank you for your response. I have further explained what I am looking for.

 

When I simulate the counts dataset I want to account for the time factor in the dataset itself. I wanted to create a simulated dataset which will have simulated counts following poisson distribution accounting for the time factor (generally 5 years of follow-up). I want to use this simulated dataset further in PROC GENMOD. Like I have simulated independent variables with normal distribution, my question is how can we simulate the follow-up time in the dataset? This simulated dataset then can be used in PROC GENMOD. I further built the code as below. I simulated time with a mean of 5 years and a standard deviation of 1.2 years. While simulating counts, in the equation (ETA1) I have added the effect of time as logarithm of time. Can you kindly look into the program and let me know if the equation (ETA1) correct accounting for time factor?

 

%let N = 500;        
%let nCont = 5;    
 
data SimPoiReg1;
call streaminit(54321);      
     
array x[&nCont];        
 
array beta[0:5] (1.0034 0.2115 -0.145 -0.0944 0.1097 -0.0999);
do i = 1 to &N;
        x[1] = Rand("normal", 20, 1.5);
x[2] = rand("normal", 15, 2);              
x[3] = rand("normal",10, 0.2);              
x[4] = rand("normal", 50, 2);
     x[5] = rand("normal", 100, 3);
     time = rand("normal", 5, 1.2);
logt = log(time);
   eta = beta[0];                            
   do j = 1 to &nCont;
   /*eta = eta + beta[j] * x[j];*/
      eta1 = eta + beta2 * x1 + beta3 * x2 + beta4 * x3 + beta5 * x4 + beta6 * x5 + logt;      
   end;
   lambda=exp(eta1);
   Y = rand("Poisson",lambda) ;                
   output;
end;
run;

Regards,

 

Anita

Rick_SAS
SAS Super FREQ

The nice thing about simulation is that you don't need to guess if your simulation is correct. Generate 10,000 observations and then run the model through PROC GENMOD. If the parameter estimates are close to the parameters that generated the data, then that is strong evidence that the simulation is correct.

 

Without showing the MODEL statement that you are trying to use, it is hard for us to know whether the simulation is correct. But once you write down the MODEL statement, you don't really need to ask other people's opinions.

slea
Calcite | Level 5
Thank you for your response.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 696 views
  • 0 likes
  • 2 in conversation