From b5e21aec58b77cec9a2a6d0354378290a7c6df07 Mon Sep 17 00:00:00 2001 From: Walmes Zeviani Date: Mon, 15 Oct 2018 22:03:35 -0300 Subject: [PATCH] Adiciona o problema da moeda. --- scripts/ce089-08.R | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/scripts/ce089-08.R b/scripts/ce089-08.R index 9f91438..a258b96 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. -- 2.22.0