From e8e4ba7bde2c9b7356fda05ed03b1a480749eda9 Mon Sep 17 00:00:00 2001 From: Walmes Zeviani <walmes@ufpr.br> Date: Wed, 17 Oct 2018 20:16:21 -0300 Subject: [PATCH] =?UTF-8?q?Atualiza=20com=20conte=C3=BAdo=20da=20aula.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ce089-09.R | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/scripts/ce089-09.R b/scripts/ce089-09.R index 6e680d5..535ddf2 100644 --- a/scripts/ce089-09.R +++ b/scripts/ce089-09.R @@ -4,8 +4,6 @@ #----------------------------------------------------------------------- # Cria a função com lista de todos os argumentos e use mapply(). -library(microbenchmark) - # Curva de poder. power_k_groups <- function(k = 3, r = 4, @@ -17,37 +15,59 @@ power_k_groups <- function(k = 3, results <- replicate(simulations, { b <- rnorm(k, mean = 0, sigma_group) y <- rnorm(k * r, mean = X %*% b, sd = 1) - anova(lm(y ~ X))[1, 5] + anova(lm(y ~ trt))[1, 5] }) mean(results <= alpha) } # Criar o grid de condições (prototipar com um grid pequeno). -grid <- expand.grid(k = 3:5, - r = c(3, 5, 8), - sigma_group = seq(0.01, 0.5, length.out = 10), +grid <- expand.grid(k = c(3, 5, 8), + r = c(3, 8), + sigma_group = seq(0.01, 2, length.out = 20), KEEP.OUT.ATTRS = FALSE) nrow(grid) +grid # Aplicar. grid$taxa <- mapply(FUN = power_k_groups, k = grid$k, r = grid$r, sigma_group = grid$sigma_group, - MoreArgs = list(simulations = 10, + MoreArgs = list(simulations = 100, alpha = 0.05), SIMPLIFY = TRUE) +#----------------------------------------------------------------------- + +library(latticeExtra) + +xyplot(taxa ~ sigma_group | ordered(r), + groups = k, + auto.key = TRUE, + data = grid, + type = "o") + +apropos("power") +apropos("write") + #----------------------------------------------------------------------- # Usando purrr. library(purrr) +ls("package:purrr") +grid$taxa <- NULL grid$taxa <- pmap_dbl(.l = grid, .f = power_k_groups, - simulations = 10, + simulations = 100, alpha = 0.05) +xyplot(taxa ~ sigma_group | ordered(r), + groups = k, + auto.key = TRUE, + data = grid, + type = "o") + #----------------------------------------------------------------------- library(microbenchmark) @@ -69,3 +89,5 @@ microbenchmark( alpha = 0.05) }, replications = 20) + +#----------------------------------------------------------------------- -- GitLab