问题1
我有一个接受p
和n
的功能。我需要绘制p=c(0.05,0.1,0.25,0.5,0.9,0.95)
和n=c(5,10,30,50,100)
的每个组合的图表。总共6 * 5 = 30个图。我尝试使用mapply
返回下面显示的图表(编辑:上传img的声誉太低,但我显示我只获得6个图)。根据我的ablines
所在的位置,我认为它只在p
的单个值上尝试n
的所有值!
问题2
我正在尝试使用n
将p
和paste0()
的值放入图中,以跟踪哪个图块属于n
和p
的哪个组合,但是当我使用mapply
时它似乎不起作用(它适用于我手动绘制的单个图形)
ci.auto <- function(p,n,alpha){
# Repeat the process nsim times
nsim <- 10000
ci.mat <- replicate(nsim, conf.int(p, n, alpha))
# Graphing the first 100 intervals
matplot(rbind(1:100, 1:100), ci.mat[, 1:100], type = "l", lty = 1,
xlab = paste0("sample number n=",n), ylab = "confidence interval")
abline(h = p)
text(2.5, 0.8, paste0("p=",p), col = "red")
# Proportion of times the interval is correct
mean( (p >= ci.mat[1,])*(p <= ci.mat[2,]) )
}
par(mfrow = c(5,6))
mapply(ci.auto, p = c(0.05,0.1,0.25,0.5,0.9,0.95), n = c(5,10,30,50,100), alpha)
答案 0 :(得分:0)
df<-expand.grid(p,n)
mapply(Fun = ci.auto, df$Var1,df$Var2,alpha)