我需要创建30个单位的样本,计算批次(lote
),批次中的单位(n
),平均值(media
),标准偏差({{ 1}})和幅度(sd
),并创建一个包含单位的所有单个值的分隔表。
我生成第一个样本
amplitud
然后我需要不断添加批次tabla <- c(numeric())
columnas <- c("Lote", "n", "Media", "Dt", "Amplitud")
datos <- data.frame(matrix(c(numeric),ncol = 5,nrow =0, byrow = T ))
colnames(datos) <- columnas
lote <- 0
size <- 30
z <- qt(0.975,df = 30-1)
d <- 10
so <- sqrt(var(tabla))
error <- (so/sqrt(size))
amplitud <- (2* z * error)
fila <- 1
set.seed(37)
matriz <- matrix(c(numeric()),byrow = T, ncol = 1)
# I create the first sample:
for(i in 1:size){
c1 <- rnorm(1,9.5 ,1)
c2 <- rpois(1,(5*c1))
c3 <- rexp(1,7)
c4 <- rexp(1,16)
c <- c1*c2 + c3*c4
matriz <- c(matriz,c)
}
tabla <- c(matriz)
so <- sqrt(var(tabla))
error <- (so/sqrt(size))
amplitud <- (2* z * error)
datos[fila,1] <- lote
datos[fila,2] <- size
datos[fila,3] <- mean(matriz)
datos[fila,4] <- sqrt(var(matriz))
datos[fila,5] <- (2* z * error)
lote <- lote + 1
fila <- fila + 1
size <- round(((2*z)*(so/d))^2)
,并在每次迭代后计算幅度size <- round(((2*z)*(so/d))^2)
。如果幅度为(2* z * error)
,< d
,我需要打破循环。
我写了这个:
(d <- 10)
程序给了我一个输出,但它应该在第5次迭代后停止,但是它一直在继续......
while(condicion){
for(i in 1:size){
matriz <- matrix(c(numeric()),byrow = T, ncol = 1)
for(i in 1:size){
c1 <- rnorm(1,9.5 ,1)
c2 <- rpois(1,(5*c1))
c3 <- rexp(1,7)
c4 <- rexp(1,16)
c <- c1*c2 + c3*c4
matriz <- c(matriz,c)
}
tabla <- c(matriz)
so <- sqrt(var(tabla))
error <- (so/sqrt(size))
size <- round(((2*z)*(so/d))^2)
amplitud <- round((2* z * error))
datos[fila,1] <- lote
datos[fila,2] <- size
datos[fila,3] <- mean(matriz)
datos[fila,4] <- sqrt(var(matriz))
datos[fila,5] <- (2* z * error)
lote <- lote + 1
fila <- fila + 1
}
if(amplitud < d){
condicion <- FALSE
break
}
}
Lote n Media Dt Amplitud
1 0 30 432.9111 90.7863 67.80033
2 1 2177 455.905 114.0621 12.5641
3 2 2197 459.2841 114.5811 10.04514
4 3 2358 455.4 118.7037 10.35908
5 4 2256 458.2974 116.1051 9.780284
6 5 2226 454.3239 115.3553 9.934368
7 6 2313 457.0264 117.5647 10.19263
为什么我的循环在第一次出现[ reached getOption("max.print") -- omitted 3398 rows ]
时没有中断?