New Contributor
Posts: 2

# Simulated binary repeated measures

Hello,

I would very much like to have some help with a specific simulation I have to do.

I need to simulate a data set with hierarchal structure (HLM) with 2 level (patient and visits) and with binary output (0/1).

For example, I have 100 patients that came 5 times (visits) to the clinic. Each visits resolved with success/failure.

I have tried to use SAS/IML using RANDMULTINOMIAL but didn't come to any solution.

Any help will be very much appreciated.

Thanks!

SAS Super FREQ
Posts: 4,243

## Re: Simulated binary repeated measures

You haven't specified a model that describes how the outcome depends on the patients or visits.  If you just want a random matrix of zeros and ones you can do this (requires SAS/IML 12.1):

proc iml;
p = j(1000, 5, 0.5);    /* probability of success */
y = j(1000, 5, .);      /* outcomes */
call randseed(12345);
call randgen(y, "Bernoulli", p);  /* y = 1 with probability p */

print (y[1:3,]);

Presumably you want the matrix of probabilities to follow some model.

BTW, I discuss simulating correlated multivariate binary data in Chap 9 of Simulating Data with SAS

New Contributor
Posts: 2

## Re: Simulated binary repeated measures

Hi Rick,

Thank you very much for your answer!

You mentioned that I haven’t specified the model, so If I understand you, here is an explanation of my model I'm trying to simulate,

Each patient has 5 visits and at each visit the patient undergo a medical examination.

New result -  is the dependent variable change from visit to visit. The outcome can be 0/1. Once the patient gains a success he’s out of the study (probability of success = 0.2).

Past result – also describes success or failure but this variable doesn’t change from visit to visit (independent variable).

Time - since each visit has a different time point this variable may also change from visit to visit and it’s one of the independents variables. Time is ordinal and divided to 3 groups with overall proportion of 30%, 40%, 30% , respectively.

I attached a small example to describe how 1 patient look like in the data:

 Patient id Age Past result Time New result 15283 24 1 1 0 15283 24 1 1 0 15283 24 1 1 0 15283 24 1 2 0 15283 24 1 2 1

I hope it's more clear now.

Thanks!

SAS Super FREQ
Posts: 4,243

## Re: Simulated binary repeated measures

My definition of model is mnore methematical than what you've provided, but I'll make a few suggestions. Look into the "Proportional Hazards model"  in survival analysis. It sounds like your patients are assumed to have a baseline hazard of 0.2.  You can read about PH models on the web or in the doc for PROC PHREG.

If you decide that the PH model is what you want to simulate, there is a discussion and programs on pp 242-246 of Simulating Data with SAS.  You could also try an internet search for

simulate "proportional hazards" sas

Discussion stats
• 3 replies
• 426 views
• 3 likes
• 2 in conversation