Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: post hoc power analysis of t-test
Replies: 2   Last Post: Jan 22, 2013 10:35 AM

 Messages: [ Previous | Next ]
 Tom Lane Posts: 858 Registered: 12/7/04
Re: post hoc power analysis of t-test
Posted: Jan 22, 2013 10:35 AM

> This function doesn't help since it addresses only t-tests of one normal
> distributed data set and not comparing between two data sets using ttest2
> for instance...

Keren, the script below calculates the two-sample t-test as a function of
the size of the two samples and the magnitude of the difference between
their means. It verifies by comparing the calculated result against the
observed power in a simulation.

I hope this is what you need.

-- Tom

delta = linspace(0,2,21);
pwrcalc = zeros(size(delta));
pwrobs = zeros(size(delta));
for k=1:length(delta)

sigma = 1;
d = delta(k) ; % difference in means as a multiple of sigma
mu1 = 10;
mu2 = mu1 + d*sigma;
n1 = 20;
n2 = 30;
alpha = 0.05;
crit = tinv(alpha/2, n1+n2-2);
p = nctcdf([crit,-crit], n1+n2-2, d/sqrt(1/n1+1/n2));
pwrcalc(k) = p(1) + 1-p(2)

numout = 0;
n = 10000;
for j=1:n
x1 = normrnd(mu1,sigma,n1,1);
x2 = normrnd(mu2,sigma,n2,1);
numout = numout + ttest2(x1,x2);
end
pwrobs(k) = numout/n
end
plot(delta,pwrcalc,'b-', delta,pwrobs,'ro')

Date Subject Author
1/18/13 Tom Lane
1/22/13 Tom Lane