Почему результаты x
anc y
отличаются?
[1] 0 0 0 1
[1] 0.06 0.06 0.22 0.19
Вот код (от здесь ):
rands <- list()
set.seed(1)
rands[[1]] <- rnorm(10) + c(1,0,2,0,1)
rands[[2]] <- rnorm(100) + c(1,0,2,0,1)
rands[[3]] <- rnorm(1000) + c(1,0,2,0,1)
rands[[4]] <- rnorm(5000) + c(1,0,2,0,1)
x <- replicate(100, { # generates 100 different tests on each distribution
c(shapiro.test(rands[[1]])$p.value,
shapiro.test(rands[[2]])$p.value,
shapiro.test(rands[[3]])$p.value,
shapiro.test(rands[[4]])$p.value)}) # rnorm gives a random draw from the normal distribution
set.seed(1)
y <- replicate(100, { # generates 100 different tests on each distribution
c(shapiro.test(rnorm(10) + c(1,0,2,0,1))$p.value,
shapiro.test(rnorm(100) + c(1,0,2,0,1))$p.value,
shapiro.test(rnorm(1000) + c(1,0,2,0,1))$p.value,
shapiro.test(rnorm(1000) + c(1,0,2,0,1))$p.value)}) # rnorm gives a random draw from the normal distribution
print(rowMeans(x < 0.05)) # the proportion of significant deviations
print(rowMeans(y < 0.05)) # the proportion of significant deviations
Я также проверил:
class(rands[[1]]) # [1] "numeric"
class(rnorm(10) + c(1,0,2,0,1)) # [1] "numeric"
и, например,
rands[[1]]
# [1] 0.3735462 0.1836433 1.1643714 1.5952808 1.3295078 0.1795316 0.4874291 2.7383247 0.5757814 0.6946116
set.seed(1)
rnorm(10) + c(1,0,2,0,1)
# [1] 0.3735462 0.1836433 1.1643714 1.5952808 1.3295078 0.1795316 0.4874291 2.7383247 0.5757814 0.6946116
Боюсь, я совершил глупую ошибку?