2011-01-13 32 views
2

我想做一個功率與效果尺寸的關係圖。我已經做了權力的一個使用的樣本大小VS:功率與效果尺寸圖

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

但找不到電源VS作用大小的任何指示。有任何想法嗎?

編輯:剛纔看着Caracal的答案(謝謝隊友)。看起來驚人,但你的代碼是我嘗試完全不同的:

plot(pwrt$d,pwrt$power,type="b",xlab="effect size",ylab="power") 

雖然這只是在中間產生一個點的圖直接。我試圖將Caracal的編碼轉換爲我的樣本大小,儘管它起作用,但圖表很瘋狂!

回答

7

編輯:顯示3組單因素方差分析以及單樣本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")) 

alt text

+0

感謝隊友。有probs試圖插入我的數據。有任何提示? – Archie 2011-01-13 14:30:51

2

中獲得動力VS效應大小的情節,你需要一個固定樣本量。下面是對於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") 

alt text