Hello all,
I am reading and learning the Simulation book of SAS written by Rick Wicklin. In the book I saw a code for power simulation of the t-test, where the effect size is changing (various effect sizes).
I changed the code so it will do a power simulation for the t-test, where the sample size varies and the effect size is constant.
At the end of the original code, there is a procedure to create a graph, where the points and the line are coming from the power procedure and from the simulation (and therefore being compared), these are the lines:
series x=MeanDiff y=Power;
scatter x=Delta y=p;
after I changed the code to my needs, the line disappeared....when I changed the series parameter to p, I got the simulation lines (connection of the points). I don't understand why in the original code the line was plotted and in mine not. I compared the files, they had the same structure. The simulation results were similar. I don't get it. Where did my line go to ?
My code is attached.
Thank you !
proc power;
twosamplemeans power = .
meandiff = 3
stddev = 2
ntotal=10 to 40 by 10;
plot x=N markers=none;
ods output Output=Power;
run;
data PowerSim(drop=i);
call streaminit(321);
do N = 5 to 20 by 5;
do SampleID = 1 to 10000;
c = 1;
do i = 1 to N;
x1 = rand("Normal", 0, 2);
output;
end;
c = 2;
do i = 1 to N;
x1 = rand("Normal", 3, 2);
output;
end;
end;
end;
run;
proc ttest data=PowerSim;
by N SampleID;
class c;
var x1;
ods output ttests=TTests(where=(method="Pooled"));
run;
data Results;
set TTests;
RejectH0 = (Probt le 0.05);
run;
proc freq data=Results noprint;
by N;
tables RejectH0 / out=SimPower(where=(RejectH0=1));
run;
data Combine;
set SimPower Power;
p = percent / 100;
label p="Power";
run;
proc sgplot data=Combine noautolegend;
title "Power of the t Test";
title2 "Samples are N(0,stdev) and N(delta,stdev)";
series x=N y=Power;
scatter x=N y=p;
xaxis label="Sample size";
run;
Since you mention Rick, You'd better post it at
SAS/IML Software and Matrix Computations
Rick would personally teach you how to do it .
Xia Keshan
Thank you. I was thinking about it, but the code is not really IML so I didn't want to violate any forums rules 🙂
I will post the question there.
Your problem looks like a Graphic problem. Maybe post it at GRAPHIC forum .
Answered at https://communities.sas.com/thread/76117
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.