Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Tom Lane

Posts: 854
Registered: 12/7/04
Re: post hoc power analysis of t-test
Posted: Jan 22, 2013 10:35 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

> 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')




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.