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

Hi all.how can i simulate data for repeated measures with auto regressive covariance structure.

appreciate any help.

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Thanks for writing. The code matches the matrix at the top of the page. However you are correct that the subscripts are confusing. According to my colleague, the symbol that I denote as \sigma_R^2 is usually called the "common covariance" and the symbol that I denote as \sigma^2_{CS} is usually called the "residual covariance." Sorry for the confusion.

View solution in original post

8 REPLIES 8
Rick_SAS
SAS Super FREQ

Not clear if you are talking about time series or mixed models.

 

Simulating time series with various AR or MA structures is the topic of Chapter 13 of Simulating Data with SAS (Wicklin, 2013). 

The easy way is to use the ARMASIM function in SAS/IML software.  If you don't have SAS/IML licensed, you can simulate it by using the definition of the AR series in the DATA step (see p. 252).

 

 

Mixed models (regression models with correlated errors) are covered in Chapter 12, pp 230-241. For mixed models, you can use PROC IML to set up the covariance structure, The "R" matrix is block diagonal, with each block corresponding to the repeated measurements for each subject. 

fatemeh
Quartz | Level 8

Thanks Dr.Wicklin for your reply .My data is responses of subjects that are measured several times over time in experimental designs of clinical trial. therefore ,since this measures are measures of same subjects that are considered over different times ,that is why they are dependent with each other which leads to having specific covariance structre for example auto regressive or compound symmetry .does the book simulating data with sas contains simulation method for this kind of data? 

 

thanks ,

Fatemeh

Rick_SAS
SAS Super FREQ

That sounds like the 10 pages on linear mixed models in Chapter 12. The code for the examples in the book is free and available in a ZIP file from the book's web site.

 

fatemeh
Quartz | Level 8

Hello ,Dr.Wicklin

I purchased your book simulating data with sas it is wonderful book, helped me to learn how to simulate repeated measures data with fixed and random effects .i have a question in constructing R matrix as variance_covariance matrix of random errors in page 233 chapter12 .I appreciate you help me to solve my problem.why are the non-diagonal elements in R matrix, sigma2_R ? should not they be sigma2_CS ? because when i change the place of sigma2_R  and sigma2_CS with each other in proc iml , the R matrix becomes exactly the R matrix that i get when i apply the proc mixed. also in do loop i put k instead of  because i want  k*k  matrix for R .is it the right way or not?. below is my sas code :


proc mixed data=mydata;
 class  Subject time treatment ;
 model response=time | treatment/ solution outpm=outpm;
 random Subject(treatment);
 repeated time / type=CS subject=Subject(treatment)  R ;
  ods select  R  ;
  ods output  R=R ;
 quit;  

 

proc iml;

k=15;
s=17;
sigma2_R=0.02491;
sigma2_CS=-0.00001;
B=sigma2_CS * j(k,k,1 )+sigma2_R * I(k);
R=B;
do i=2 to k;
R=block(R,b);
end;
R = I(k) @ B;

Rick_SAS
SAS Super FREQ

Thanks for writing. The code matches the matrix at the top of the page. However you are correct that the subscripts are confusing. According to my colleague, the symbol that I denote as \sigma_R^2 is usually called the "common covariance" and the symbol that I denote as \sigma^2_{CS} is usually called the "residual covariance." Sorry for the confusion.

fatemeh
Quartz | Level 8

Hello.Dr.Wicklin,

I want to construct block diagonal matrix as covariance matrix for errors. Is there  any way to create this matrix directly by using the R matrix that is in ods output ?below is my code .it gives me error. appreciate for any help.

 


proc mixed data=mydata ;
 class  Subject times responder ;
 model response=times|responder/ solution outpm=outpm;
 repeated times / type=CS subject=Subject(Responder)  R;
  ods select    R ;
  ods output  R=R ;
 quit;

 

proc iml;
k=3;
s=5;

R=/*first block*/
do i=2 to s;
R=block(R,R);
end;
R = I(s) @ R;

 

 

 

 

Rick_SAS
SAS Super FREQ

The error is because you haven't read R from the data set into a matrix:

 

use R;

read all var {PUT VAR NAMES HERE} into R;

close;

fatemeh
Quartz | Level 8

Dr.Wicklin appreciate for your great answer.it helped me to solve my problem.again thanks a lot for sharing your knowledge with us.

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 2320 views
  • 3 likes
  • 2 in conversation