diff --git a/scripts/ce089-08.R b/scripts/ce089-08.R index 9f914386d934cecc1acf216a4c95386aae3aed32..a258b9606a30c294de51006434dfc90ca9a67270 100644 --- a/scripts/ce089-08.R +++ b/scripts/ce089-08.R @@ -1,6 +1,36 @@ #======================================================================= # Testes de hipótese Monte Carlo. +#----------------------------------------------------------------------- +# + +# x <- scan() +# dput(x) + +# Amostra observada. +x <- c(c(1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0), + c(1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0)) + +# Caracterização. +n <- length(x) +p <- mean(x) +d <- sum(abs(diff(x))) + +D <- replicate(9999, { + # Amostras sob a H_0. + r <- rbinom(n = n, size = 1, prob = 0.5) + # Estatística calculada. + sum(abs(diff(r))) +}) + +D <- c(d, D) + +plot(ecdf(D)) +abline(v = d, col = 2) +abline(h = c(0.025, 0.975), col = 2, lty = 2) + +2 * sum(D > d)/length(D) + #----------------------------------------------------------------------- # Teste para independência de processo pontual. @@ -66,7 +96,8 @@ abline(h = c(0.025, 0.975), lty = 2) abline(v = m, col = 2) # P-valor. -2 * sum(M > m)/length(M) +2 * sum(M > m)/length(M) # Faz sentido esse teste ser bilateral? +sum(M > m)/length(M) #----------------------------------------------------------------------- # ATTENTION: dados um tanto patológicos. @@ -125,7 +156,8 @@ abline(h = c(0.025, 0.975), lty = 2) abline(v = m, col = 2) # P-valor. -2 * sum(M > m)/length(M) +# 2 * sum(M > m)/length(M) +sum(M > m)/length(M) #----------------------------------------------------------------------- # Moficando a estatística de teste 2.