library(tidyverse)
library(effectsize)
library(readxl)
library(janitor)
library(broom)
library(emmeans)
library(car)
library(WebPower)
library(agricolae)
datos <- read_excel("experimento_ratones.xlsx")
datos
\[H_0: \mu_1 = \mu_2 = \mu_3 = \mu_4 \\ H_1: \mu_i \neq \mu_j\]
datos %>%
group_by(Strain) %>%
summarise(promedio = mean(GST),
desviacion = sd(GST),
mediana = median(GST),
minimo = min(GST),
maximo = max(GST))
datos %>%
ggplot(aes(x = Strain, y = GST)) +
geom_boxplot()
datos %>%
group_by(Strain) %>%
summarise(promedio = mean(GST),
mediana = median(GST),
desviacion = sd(GST)) %>%
ggplot(aes(x = Strain, y = promedio,
ymin = promedio - desviacion,
ymax = promedio + desviacion)) +
geom_pointrange() +
geom_point(aes(y = mediana), color = "red")
modelo_dca <- aov(GST ~ Strain, data = datos)
modelo_dca %>% tidy()
422076.50 + 28613.25
## [1] 450689.8
media_total <- mean(datos$GST)
sc_total <- sum((datos$GST - media_total)^2)
sc_total
## [1] 450689.8
r_nih <- datos %>% filter(Strain == "NIH")
r_balbc <- datos %>% filter(Strain == "BALB/C")
r_aj <- datos %>% filter(Strain == "A/J")
r_129 <- datos %>% filter(Strain == "129/Ola")
sc_nih <- ((mean(r_nih$GST) - media_total)^2) * 4
sc_balbc <- ((mean(r_balbc$GST) - media_total)^2) * 4
sc_aj <- ((mean(r_aj$GST) - media_total)^2) * 4
sc_129 <- ((mean(r_129$GST) - media_total)^2) * 4
sc_ttos <- sc_nih + sc_balbc + sc_aj + sc_129
sc_ttos
## [1] 28613.25
sc_total - sc_ttos
## [1] 422076.5
modelo_dca %>%
emmeans(specs = "Strain") %>%
as.data.frame()
pairwise.t.test(x = datos$GST,
g = datos$Strain)
##
## Pairwise comparisons using t tests with pooled SD
##
## data: datos$GST and datos$Strain
##
## 129/Ola A/J BALB/C
## A/J 1 - -
## BALB/C 1 1 -
## NIH 1 1 1
##
## P value adjustment method: holm
modelo_dca %>%
TukeyHSD()
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = GST ~ Strain, data = datos)
##
## $Strain
## diff lwr upr p adj
## A/J-129/Ola 84.25 -309.4684 477.9684 0.9185996
## BALB/C-129/Ola -30.50 -424.2184 363.2184 0.9954768
## NIH-129/Ola 28.75 -364.9684 422.4684 0.9962012
## BALB/C-A/J -114.75 -508.4684 278.9684 0.8223712
## NIH-A/J -55.50 -449.2184 338.2184 0.9742353
## NIH-BALB/C 59.25 -334.4684 452.9684 0.9689979
modelo_dca %>%
eta_squared()
modelo_dca %>%
cohens_f()
par(mfrow = c(2, 2))
plot(modelo_dca)
modelo_dca %>%
residuals() %>%
shapiro.test()
##
## Shapiro-Wilk normality test
##
## data: .
## W = 0.96966, p-value = 0.8331
datos %>%
bartlett.test(data = ., GST ~ Strain)
##
## Bartlett test of homogeneity of variances
##
## data: GST by Strain
## Bartlett's K-squared = 1.4085, df = 3, p-value = 0.7035
\[ H_0: \mu_1 = \mu_2 \\ H_1: \mu_1 \neq \mu_2 \\ \]
\[ H_0: \beta_1 = \beta_2 \\ H_A: \beta_1 \neq \beta_2 \]
datos %>%
count(Block, Treatment)
datos %>%
ggplot(aes(x = Treatment, y = GST)) +
facet_wrap(~Block) +
geom_boxplot()
modelo_dbca <- aov(GST ~ Treatment + Block, data = datos)
modelo_dbca %>% tidy()
modelo_dbca %>%
emmeans(specs = "Treatment") %>%
as.data.frame()
pairwise.t.test(x = datos$GST,
g = datos$Treatment)
##
## Pairwise comparisons using t tests with pooled SD
##
## data: datos$GST and datos$Treatment
##
## Control
## Treated 0.002
##
## P value adjustment method: holm
modelo_dbca %>%
TukeyHSD()
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = GST ~ Treatment + Block, data = datos)
##
## $Treatment
## diff lwr upr p adj
## Treated-Control 238.5 144.2819 332.7181 0.0001077
##
## $Block
## diff lwr upr p adj
## B-A 176.25 82.03193 270.4681 0.001399
modelo_dbca %>%
eta_squared()
modelo_dbca %>%
cohens_f()
par(mfrow = c(2, 2))
plot(modelo_dbca)
modelo_dbca %>%
residuals() %>%
shapiro.test()
##
## Shapiro-Wilk normality test
##
## data: .
## W = 0.84408, p-value = 0.01116
datos %>%
leveneTest(data = ., GST ~ Treatment)
datos %>%
leveneTest(data = ., GST ~ Block)
wp.anova(k = 4,
n = 16,
f = 0.26,
alpha = 0.01,
type = "two.sided")
## Power for One-way ANOVA
##
## k n f alpha power
## 4 16 0.26 0.01 0.0476529
##
## NOTE: n is the total sample size (contrast, two.sided)
## URL: http://psychstat.org/anova
wp.anova(k = 6,
n = 16,
f = 1.52,
alpha = 0.01,
type = "two.sided")
## Power for One-way ANOVA
##
## k n f alpha power
## 6 16 1.52 0.01 0.9921112
##
## NOTE: n is the total sample size (contrast, two.sided)
## URL: http://psychstat.org/anova
tratamientos <- c("A", "B", "C", "D")
repeticiones <- 15
dis_dca <- design.crd(
trt = tratamientos,
r = repeticiones,
seed = 2023,
randomization = TRUE
)
dis_dca$book
wp.anova(
k = 4,
power = 0.8,
f = 0.25, # tamaño de efecto medio
alpha = 0.01,
type = "two.sided"
)
## Power for One-way ANOVA
##
## k n f alpha power
## 4 190.243 0.25 0.01 0.8
##
## NOTE: n is the total sample size (contrast, two.sided)
## URL: http://psychstat.org/anova
tratamientos <- c("A", "B", "C", "D")
bloques <- 3
dis_dbca <- design.rcbd(
trt = tratamientos,
r = bloques,
seed = 2023,
randomization = TRUE
)
dis_dbca$book
wp.anova(k = 7,
power = 0.8,
f = 1.25, # tamaño de efecto medio
alpha = 0.01,
type = "two.sided")
## Power for One-way ANOVA
##
## k n f alpha power
## 7 13.58406 1.25 0.01 0.8
##
## NOTE: n is the total sample size (contrast, two.sided)
## URL: http://psychstat.org/anova