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

Showing results for

Find a Community

- 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
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-02-2016 10:55 AM

My problem is that I should be able to simulate IPD for each studies (5) and each simulation (1000)

Let varying the mean effects in each studies and each simulation. I am simulating three outcomes.

I can do something like this to let varying the mean effects in each studies

proc iml;

N = 5;

NumSamples=1;

Meant = {4, 5, 15};

Cov = {1.2 0.29 0.27, 0.29 1.7 0.32, 0.27 0.32 1.5};

call randseed(100);

M = RandNormal(N, Meant, Cov);

D = colvec(repeat(T(1:NumSamples), 1, N));

Z = M || D;

create work.Mt from Z [c={"x1" "x2" "x3"}]; append from Z;

close work.Mt;

quit;

But my problem is to let vary these mean for each 1000 sims.

Do you understand the question?

Have you got time to help me a little bit or to suggest me the best solution?

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

02-02-2016 11:13 AM

There are two common ways to interpret your question:

1) Each study has a known mean vector that you want to use. (and possible the covariance matrix also varies between studies.) In that case, make a matrix for which each row contains the mean vector (parameters) for the study, like this:

```
proc iml;
N = 3; /* sample size */
Meant = {4 5 15,
3 4 12,
3 5 11,
4 6 10,
4 7 14};
NumStudies = nrow(Meant);
Cov = {1.2 0.29 0.27, 0.29 1.7 0.32, 0.27 0.32 1.5};
call randseed(100);
Z = j(1, ncol(Meant)+2, .);
create work.Mt from Z [c={"x1" "x2" "x3" "Sample" "Study"}];
do i = 1 to NumStudies;
mean = Meant[i,];
M = RandNormal(N, Mean, Cov);
Sample = j(N, 1, 1);
Study = j(N, 1, i);
Z = M || Sample || Study;
append from Z;
end;
close work.Mt;
quit;
proc print; run;
```

2) The other interpretation is that you want the mean vectors to be a random draw from a MVNormal distribution. In this case, you genearte the mean vectors first and then proceed as above.

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

02-02-2016 11:24 AM

Thank you again Rick,

I think that I would like the true study-specific effects to be allowed to be different in each simulation. So i think that the second interpretation is the one that suit for me.

Forthermore In your code I see Cov that I assume to be the within variance-covariance matrix and i would like to consider here also the between study variability.

Do you understand?

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

02-02-2016 11:29 AM

Yes, I understand. I've shown you the basic idea. Now go off and implement your specific design. If you get stuck, you can post your new program and describe what doesn't work.

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

02-05-2016 10:29 AM

To continue this interesting conversation. I am trying to run this code

proc iml; N = 5;

/* N is the number of 5 studies*/

NumSamples=1000;

/* I am performing N = 1000 simulations*/

Meant = {4, 5, 15};

/* Vector of Means */

Cov = {1.2 0.29 0.27, 0.29 1.7 0.32, 0.27 0.32 1.5};

/* Between-Studies Variance-Covariance Matrix */

call randseed(100);

M = RandNormal(N*NumSamples, Meant, Cov);

/* RandNormal function*/

D = colvec(repeat(T(1:NumSamples), 1, N));

/* I create a matrix D*/

Z = M || D; /* I apply Concatenate fucnction*/

create work.Mt from Z [c={"x1" "x2" "x3"}]; append from Z;

/* I create Matrix Mt with all the means for each studies and each simulation*/

close work.Mt; do i= 1 to NumSamples; /* here start the do loop */

MeanT1 = M[i,1:3];

MeanT2 = M[i,1:3];

MeanT3 = M[i,1:3];

MeanT4 = M[i,1:3];

MeanT5 = M[i,1:3];

end; /* here finish the do loop*/

NumSamples1=1000; MeanP = {9, 8, 21};

Cov = {49 7 5.6, 7 25 4, 5.6 4 16};

call randseed(100);

ST1 = RandNormal(N1t*NumSamples1, MeanT1, Cov);

ST2 = RandNormal(N2t*NumSamples1, MeanT2, Cov);

ST3 = RandNormal(N3t*NumSamples1, MeanT3, Cov);

ST4 = RandNormal(N4t*NumSamples1, MeanT4, Cov);

ST5 = RandNormal(N5t*NumSamples1, MeanT5, Cov);

SP1 = RandNormal(N1p*NumSamples1, MeanP, Cov);

SP2 = RandNormal(N2p*NumSamples1, MeanP, Cov);

SP3 = RandNormal(N3p*NumSamples1, MeanP, Cov);

SP4 = RandNormal(N4p*NumSamples1, MeanP, Cov);

SP5 = RandNormal(N5p*NumSamples1, MeanP, Cov);

My questions are three:

1) Is the do-loop in the right position? if not where I should shift the do-loop?

2) Is the start and end of the do-loop in the right position? If not where I should shift the start and the end?

3) If I create a matrix/table Mt with 4 columns and 5000 columns where the last column contain the index that should score for the do loop how could I recall in the correct way only the vector of three means to generate my IPD?

Do you understand the questions?

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

02-05-2016 10:34 AM

It looks like your program is missing the end of several statements (closing brackets and semicolons). Please edit your message, delete the current code, and use the "Insert SAS Code" icon to paste the program into the message.

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

02-05-2016 03:11 PM

Dear Rick according to this proc iml with the do loop that you sent me as example and taking in account the second hypothesis that you were suggested I tried to create another proc iml with two nested do loop but apparently it seems to work only the first do loop.

```
proc iml;
N = 5; /* study sizes */
MeanP = {9, 8, 21}; /* Non treated mean vector, 3 outcomes */
NumSim=1000; /* Number of simulations */
Sizes = {30, 40, 50, 60, 70} /* Total size for each of the 5 study */
Meant = {4, 5, 15}; /* treated mean vector, 3 outcomes */
CovBw = {1.2 0.29 0.27, /*Var-cov between studies */
0.29 1.7 0.32,
0.27 0.32 1.5};
CovWn = {49 7 5.6, /*Var-cov within studies */
7 25 4,
5.6 4 16};
ZT = j(1, 5, .);
ZP = j(1, 5, .);
create work.DT from ZT [c={"x1" "x2" "x3" "Sample" "Study"}];
create work.DP from ZP [c={"x1" "x2" "x3" "Sample" "Study"}];
do i = 1 to NumSim; /* Start main loop */
do n= 1 to N; /* Start simulation loop for each sample size*/
SampleSize = Sizes[n]; call randseed(100); M[i] = RandNormal(1, Meant, CovBw);
ST[i] = RandNormal(SampleSize, M[i], CovWn);
SP[i] = RandNormal(SampleSize, MeanP,CovWn);
Sample = j(SampleSize, 1, N);
Study = j(SampleSize, 1, SampleSize);
ZT = ST[i] || Sample || Study;
append from ZT;
ZP = SP[i] || Sample || Study;
append from ZP;
end;
end;
close work.DT;
close work.DP;
quit;
```

But SAS is returning me these errors.

98 end;

NOTE: Module RANDNORMAL loaded from the storage SASHELP.IMLMLIB.

NOTE: Module ROWVEC loaded from the storage SASHELP.IMLMLIB.

99 close work.DT;

NOTE: The data set WORK.DT has 0 observations and 5 variables.

100 close work.DP;

NOTE: The data set WORK.DP has 60000 observations and 5 variables.

101 quit;

NOTE: Exiting IML.

NOTE: PROCEDURE IML used (Total process time):

real time 19.32 seconds

cpu time 1.18 seconds

Furthermore it seems to work only for work.DP.

Do you understand what could be the error and how could I solve this?

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

02-05-2016 03:20 PM

1) Again, you seem to have problems pasting your program. Your programs are missing portions of code. Please try again. If you are having problems. then use the "Attachements" feature to upload the program.

2) I do not see any errors in the log that you posted. I only see six NOTEs. A NOTE is not an error; it just let's you know that certain events (like writing a data set) occurred.