On May 24, 2011, at 8:44 AM, stocd...@mail.tu-berlin.de wrote:
Dear R-User,
I'm trying to visualize the results of the power calculation with
the function power.t.test(). Therefore I want to plot the related t-
distributions and shade the surfaces indicatingt the type I error,
the type II error and the power. For sample sizes greater 30 I got
results which are very satisfying. For small sample sizes I got
stuck and did'nt find a mistake.
To show you the problem I wrote some lines in R:
par(mfrow = c(4,2))
for(n in c(2,6,10,14,18,22,26,30))
{
temp = power.t.test(n = n, sd = 1, power = 0.5, sig.level =
0.05, # power
calculation --> power is specified with 50%
type = "one.sample", alternative = "one.sided")
s = temp
$
sd
# get
standard deviation out of test distribution
n = temp
$
n
# get
sample size out of test distribution
delta = temp
$
delta
# get
delta (distance between centrality points) out of test ditribution
plot(1:10, xlim = c(-5,10), ylim = c(0, 0.5), type =
"n")
# create plot window
x = seq(-5, 10, length =
400
) # x
-values
y1 = dt(x, df =
n
-1
) # y
-values calculated with related t-distribution (df=n-1)
lines(x, y1, col =
2
) # plot
related t-distribution
lines(x + delta/(s/sqrt(n)),
y1
) # plot
related t-distribution shifted with normalized delta
abline(v = qt(0.95, df =
n
-1
)) # draws
a vertical line at the
abline(v=delta/(s/sqrt(n)),lty=2)
legend("topright",legend=c(paste("n=",n),
paste("bias=",round(qt(0.95, df = n-1)-delta/(s/sqrt(n)),
2)))) # creates legend
}
This code creates some plots with different sample size n. I would
expect the solid vertical line and the dotted vertical line one
above the other. But indeed the space between both of them is
increasing with a decreasing sample size.
Whe re is my mistake? Is it a error in reasoning or is it "just"
not possible to visualize this problem for small sample sizes?
You do realize that you should be using the non-central t distribution
when considering the alternate hypothesis, right? By the time you get
down to sample sizes of 6 there should be a visible skew to the
distribution of "observed" differences.
I look foward to any suggestions and hints. So much thanks in advance.
Étienne
--
David Winsemius, MD
West Hartford, CT
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.