DATA Step, Macro, Functions and more

Ttest simulation

Reply
Regular Contributor
Posts: 180

Ttest simulation

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;

Super User
Posts: 10,044

Re: Ttest simulation

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

Regular Contributor
Posts: 180

Re: Ttest simulation

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.

Super User
Posts: 10,044

Re: Ttest simulation

Your problem looks like a Graphic problem. Maybe post it at GRAPHIC forum .

SAS Super FREQ
Posts: 3,755

Re: Ttest simulation

Ask a Question
Discussion stats
  • 4 replies
  • 249 views
  • 3 likes
  • 3 in conversation