Commit e8e4ba7b by Walmes Marques Zeviani

### Atualiza com conteúdo da aula.

parent d7264228
 ... ... @@ -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) #-----------------------------------------------------------------------
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!