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

I am doing a sample size calculation for two proportions (alpha=0.05, beta=0.2 (i.e. power=0.8)). Group proportions are fixed at 0.05 and 0.0375, respectively. If I decide on N=4555 subjects in one group how many subjects do I need to include in the other group ?

 

proc power;
	ods output Power.TwoSampleFreq.Output=out;
	twosamplefreq
	GROUPPROPORTIONS = (0.05 0.0375)
	groupns=(4555 .)
	power = 0.80
	alpha = .05;
run;

fails me. Any suggestions ?

1 ACCEPTED SOLUTION

Accepted Solutions
JacobSimonsen
Barite | Level 11

I suggest to simulate with different numbers, and find the right N for which the probability for rejecting becomes 80%. I assume it is a two side test, so we can test the hypothesis of equal proportions with a likelihood test.

 

The calculation of p-values so simple here that it can be calculated within a datastep. It turns out that about 3865 should be in the other group in order to get a probability of rejecting=80% (that is the power).

 

data simulation;
  array n{2} _temporary_ (4555,3865);
  array p{2} _temporary_ (0.05,0.0375);
  array y_{2} _temporary_;
  do i=1 to 1000000;
    l0=0;
    do k=1 to 2;
	  outcome=1;y=rand('binomial',p[k],n[k]);y_[k]=y;l0+y*log(y/n[k]);
      outcome=0;y=n[k]-y; l0+y*log(y/n[k]);
	end;
	l1=(y_[1]+y_[2])*log((y_[1]+y_[2])/(n[1]+n[2]))+
	   (n[1]+n[2]-y_[1]-y_[2])*log(1-(y_[1]+y_[2])/(n[1]+n[2]));
	minus2logQ=-2*(l1-l0);
	pvalue=sdf('chisquare',minus2logQ,1);
	reject=(pvalue<0.05);
	output;
  end;
  keep minus2logQ reject;
run;
proc means data=simulation mean;
  var reject;
run;

 

(I edited a bit, as first I said about 4000 in the other group. Increasing the number of simulations shows that 3865 is more accurate).

View solution in original post

2 REPLIES 2
JacobSimonsen
Barite | Level 11

I suggest to simulate with different numbers, and find the right N for which the probability for rejecting becomes 80%. I assume it is a two side test, so we can test the hypothesis of equal proportions with a likelihood test.

 

The calculation of p-values so simple here that it can be calculated within a datastep. It turns out that about 3865 should be in the other group in order to get a probability of rejecting=80% (that is the power).

 

data simulation;
  array n{2} _temporary_ (4555,3865);
  array p{2} _temporary_ (0.05,0.0375);
  array y_{2} _temporary_;
  do i=1 to 1000000;
    l0=0;
    do k=1 to 2;
	  outcome=1;y=rand('binomial',p[k],n[k]);y_[k]=y;l0+y*log(y/n[k]);
      outcome=0;y=n[k]-y; l0+y*log(y/n[k]);
	end;
	l1=(y_[1]+y_[2])*log((y_[1]+y_[2])/(n[1]+n[2]))+
	   (n[1]+n[2]-y_[1]-y_[2])*log(1-(y_[1]+y_[2])/(n[1]+n[2]));
	minus2logQ=-2*(l1-l0);
	pvalue=sdf('chisquare',minus2logQ,1);
	reject=(pvalue<0.05);
	output;
  end;
  keep minus2logQ reject;
run;
proc means data=simulation mean;
  var reject;
run;

 

(I edited a bit, as first I said about 4000 in the other group. Increasing the number of simulations shows that 3865 is more accurate).

karlbang
Fluorite | Level 6
More complicated than I hoped for, but thanks

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
  • 2 replies
  • 1328 views
  • 1 like
  • 2 in conversation