我想做一个力量对效果大小的情节。我使用以下方法完成了功率与样本大小之一:
ptab<-cbind(NULL, NULL)
for (i in c(1:4588)){
pwrt<-power.t.test(d=.9,n=c(1:4588),sig.level=.05,type="one.sample",alternative="two.sided")
plot(pwrt$n,pwrt$power,type="b",xlab="sample size",ylab="power")
但无法找到关于功率与效果大小的任何说明。有什么想法吗?
编辑:看看卡拉卡尔的回答(感谢队友)。看起来很棒,但你的编码与我的尝试完全不同:plot(pwrt$d,pwrt$power,type="b",xlab="effect size",ylab="power")
虽然这只是产生一个直接在中间有一个点的图形。我试图将Caracal的编码转换为我的样本大小,虽然它有效但图表却很疯狂!
答案 0 :(得分:7)
编辑:显示具有3组的单向ANOVA以及单样本t检验的功率图。
P <- 3 # number of groups for ANOVA
fVals <- seq(0, 1.2, length.out=100) # effect sizes f for ANOVA
dVals <- seq(0, 3, length.out=100) # effect sizes d for t-Test
nn <- seq(10, 25, by=5) # group sizes
alpha <- 0.05 # test for level alpha
# function to calculate one-way ANOVA power for given group size
getFPow <- function(n) {
critF <- qf(1-alpha, P-1, P*n - P) # critical F-value
# probabilities of exceeding this F-value given the effect sizes f
# P*n*fVals^2 is the non-centrality parameter
1-pf(critF, P-1, P*n - P, P*n * fVals^2)
}
# function to calculate one-sample t-Test power for given group size
getTPow <- function(n) {
critT <- qt(1-alpha, n-1) # critical t-value
# probabilities of exceeding this t-value given the effect sizes d
# sqrt(n)*d is the non-centrality parameter
1-pt(critT, n-1, sqrt(n)*dVals)
}
powsF <- sapply(nn, getFPow) # ANOVA power for for all group sizes
powsT <- sapply(nn, getTPow) # t-Test power for for all group sizes
dev.new(width=10, height=5)
par(mfrow=c(1, 2))
matplot(fVals, powsF, type="l", lty=1, lwd=2, xlab="effect size f",
ylab="Power", main="Power one-way ANOVA", xaxs="i",
xlim=c(-0.05, 1.1), col=c("blue", "red", "darkgreen", "green"))
legend(x="bottomright", legend=paste("Nj =", c(10, 15, 20, 25)), lwd=2,
col=c("blue", "red", "darkgreen", "green"))
matplot(dVals, powsT, type="l", lty=1, lwd=2, xlab="effect size d",
ylab="Power", main="Power one-sample t-Test", xaxs="i",
xlim=c(-0.05, 1.1), col=c("blue", "red", "darkgreen", "green"))
legend(x="bottomright", legend=paste("N =", c(10, 15, 20, 25)), lwd=2,
col=c("blue", "red", "darkgreen", "green"))
答案 1 :(得分:2)
要获得功效与效果大小的关系图,您需要确定样本大小。这是n = 40的快速图(注意:线图会更好,但我坚持你的格式):
pwrt2 <- power.t.test(d=seq(0,3,by=0.1), power=NULL, n=40,
sig.level=.05, type="one.sample", alternative="two.sided")
plot(pwrt2$d, pwrt2$power, type="b", xlab="effect size",ylab="power")