<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Power Simulation for a Two Proportions Test in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Power-Simulation-for-a-Two-Proportions-Test/m-p/364302#M3528</link>
    <description>&lt;P&gt;Unfortunately, I do not know PROC POWER well enough to advise you. But you could try posting just that question to the SAS Statistical Procedures Community.&lt;/P&gt;</description>
    <pubDate>Mon, 05 Jun 2017 15:38:23 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2017-06-05T15:38:23Z</dc:date>
    <item>
      <title>Power Simulation for a Two Proportions Test</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Power-Simulation-for-a-Two-Proportions-Test/m-p/363943#M3525</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to make a power analysis for a future clinical trial in which two proportions are to be compared. The analysis to be done is a non-inferiority analysis, i.e., it will be a one sided test for proportions difference, and the difference of proportions will be compared to a non-inferiority margin. The null hypothesis is P1-P2=-0.02, while the alternative hypothesis will be P1-P2&amp;gt;-0.02. The proportion in the first group (control) is assumed to be 8% while in the treatment group 6% (a smaller proportion is better).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote this simulation, very much based on Rick Wicklin's example which I read in his book (that's why I publish this on this board, hoping that Rick will see this). The simulation ran and I got results, however, three problems occurred:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. The results differ significantly from the results obtained from a sample size software, which used a formula rather than a simulation. The sample size in my simulation turned out to be much higher (about 300 subjects more overall).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. I saved not only the P-Values of the non-inferiority test, but also the lower limit of the corresponding CI, which is a common practice which I saw in several articles. I expected the two methods to give the exact same results. But they don't. Not exactly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. I tried using PROC POWER to comapre the simulation results, but I keep getting an error saying: "NTOTAL is not available as a result option for TEST=." despite copying my code from the SAS documentation examples and changing the numbers only.&lt;/P&gt;&lt;P&gt;Can you kindly assist me in figuring out what is wrong with my simulation ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ODSOff(); 
	ods graphics off;
	ods exclude all;
	ods noresults;
%mend;

%macro ODSOn(); 
	ods graphics on;
	ods exclude none;
	ods results;
%mend;

/* Macro Variables */
%let NumSamples = 10000;  
%let nimargin = 0.02; /* Non-inferiority margin */
%let negnimargin = -0.02; /* Negative non-inferiority margin */
%let P_SOC = 0.08;    
%let P_Treatment = 0.06;  

/* 1. Simulating N samples of EACH group (Total = 2N) for each sample */
data PowerSizeSim(drop = i);
	call streaminit(321);
	Pc = &amp;amp;P_SOC;                                                        
	Pt = &amp;amp;P_Treatment;                                                      
	do N =  200 to 500 by 25 ;    /* N - sample size per group */
   		do SampleID = 1 to &amp;amp;NumSamples;
      		do i = 1 to N;
         		c = 1; x1 = rand("BERNOULLI", Pc); output;
         		c = 2; x1 = rand("BERNOULLI", Pt); output;
      		end;
   		end;
	end;
run;

data SimulatedData;
	set PowerSizeSim;
	if x1 = 0 then x2 = 1; else if x1=1 then x2 = 0;
	drop Pc Pt;
run;

/* 2. Compute Statistics */
%ODSOff 
proc freq data = SimulatedData;
	by N SampleID;
	table c*x2 / riskdiff(noninf margin=&amp;amp;nimargin method=fm) alpha=0.025;
	ods output PdiffNoninf = NITESTS;
run;
%ODSOn  


/* 3. Construct indicator var for obs that reject H0 */ 
data ResultsSize; 
	set NITESTS; 
	RejectH0 = (PValue &amp;lt;= 0.05);
	LowerCI = (LowerCL &amp;gt;= &amp;amp;negnimargin);
run; 

proc freq data=ResultsSize noprint; 
   by N; 
   tables RejectH0 / out = SimPower(where = (RejectH0 = 1));
   tables LowerCI /  out = SimPowerCI(where = (LowerCI = 1));
run;


/* 4. Output */
title2 'Simulated Power by Sample Size';
proc report data = SimPower;     
   column N PERCENT;
   define N / display 'Sample Size Per Group';            
   define PERCENT / display 'Simulated Power';
run;
title2;


/* PROC Power Validation */
proc power;
    twosamplefreq test = FM groupproportions = (0.08 0.06) nullproportiondiff = -0.02 alpha = 0.025
                  sides = U  power = 0.8 /*ntotal = .*/ NPERGROUP=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 21:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Power-Simulation-for-a-Two-Proportions-Test/m-p/363943#M3525</guid>
      <dc:creator>BlueNose</dc:creator>
      <dc:date>2017-06-02T21:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: Power Simulation for a Two Proportions Test</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Power-Simulation-for-a-Two-Proportions-Test/m-p/363974#M3526</link>
      <description>&lt;P&gt;The simulation part looks okay, so I would review the PROC FREQ / RISKDIFF(...) doc to make sure it is doing what you want. Also, why are you using alpha=0.025 in&amp;nbsp;some places and PVALUE&amp;nbsp;&amp;lt;= 0.05 in another?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2017 00:49:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Power-Simulation-for-a-Two-Proportions-Test/m-p/363974#M3526</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-06-03T00:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Power Simulation for a Two Proportions Test</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Power-Simulation-for-a-Two-Proportions-Test/m-p/363996#M3527</link>
      <description>&lt;P&gt;Rick, thank you. I think you solved the mystery, well, one of them anyway. I specified alpha=0.025 in order to get a 95% CI, but I forgot to test the P-Value vs 0.025. I changed it now and the results of both the CI and the hypothesis testing are identical. The only thing that is still a mystery is why proc power doesn't want to work, but I guess that with a good simulation in hand, I don't really need it.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2017 09:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Power-Simulation-for-a-Two-Proportions-Test/m-p/363996#M3527</guid>
      <dc:creator>BlueNose</dc:creator>
      <dc:date>2017-06-03T09:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Power Simulation for a Two Proportions Test</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Power-Simulation-for-a-Two-Proportions-Test/m-p/364302#M3528</link>
      <description>&lt;P&gt;Unfortunately, I do not know PROC POWER well enough to advise you. But you could try posting just that question to the SAS Statistical Procedures Community.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 15:38:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Power-Simulation-for-a-Two-Proportions-Test/m-p/364302#M3528</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-06-05T15:38:23Z</dc:date>
    </item>
  </channel>
</rss>

