【发布时间】:2021-11-18 16:10:19
【问题描述】:
我正在尝试使用 plot 绘制矩阵列,但看起来我在某处犯了错误。我在网上找到了示例代码,所以我不完全确定如何解决它。
d <- seq(from = 0.3, to = 0.5, by = 0.01)
nd <- length(d)
p <- seq(from = 0.6, to = 0.8, by = 0.1)
np <- length(p)
samplesizes <- data.frame(matrix(data=0, nrow=nd, ncol=np))
names(samplesizes) <- p
rownames(samplesizes) <- d
for (i in 1:np){
for (j in 1:nd){
result <- power.t.test(n=NULL, d = d[j], sig.level = .05,
power = p[i], alternative = "one.sided")
samplesizes[j,i] <- result$n
}
}
#-----------------------------------------------------
xrange <- range(d)
yrange <- round(range(samplesizes))
colors <- rainbow(length(p))
plot(samplesizes, xrange, yrange, type="n", xlab="Sample size (n)",
ylab="Effect Size (d)", las = 1)
for (i in 1:np){
lines(s, effectsizes[,i], type="l", lwd=2, col=colors[i])
}
legend("topright", title="Power", as.character(p), fill=colors)
我正在尝试获得与此示例图类似的内容,但 Y 轴为样本,X 轴为效果大小。
【问题讨论】: