Week 7
eta_quared()
function in the effectsize
packagelibrary(effectsize)
and omegaSquared()
functioneffectsize
) and cohens_d()
function
pairwise.t.test()
pairwise.t.test()
is a function in base Rpairwise.t.test( x = clin.trial$mood.gain,
g = clin.trial$drug,
p.adjust.method = "none") # we will change this later
Pairwise comparisons using t tests with pooled SD
data: clin.trial$mood.gain and clin.trial$drug
placebo anxifree
anxifree 0.15021 -
joyzepam 3e-05 0.00056
P value adjustment method: none
posthocPairwiseT()
posthocPairwiseT()
is a function from the lsr
packageset.seed(2812)
N <- 10 # sample size
nsims <- 10000 # number of simulated experiments
p.values <- rep(0, nsims) # to store our p-values
F.values <- rep(0, nsims) # to store our F values
decisions <- rep("", nsims) # to store our decisions
for (i in seq(nsims)) {
y1 <- rnorm(n=N, mean=0, sd=1) # sample group 1
y2 <- rnorm(n=N, mean=0, sd=1) # sample group 2
y3 <- rnorm(n=N, mean=0, sd=1) # sample group 3
y <- c(y1,y2,y3)
g <- factor(c(rep("g1",N), rep("g2",N), rep("g3",N))) # construct our group factor
my.df <- tibble(y=y, g=g) # construct our data tibble
my.anova <- aov(y ~ g, data=my.df) # conduct ANOVA
my.anova.summary <- summary(my.anova) # get ANOVA summary
p <- my.anova.summary[[1]]$`Pr(>F)`[1] # extract p-value of omnibus F-test
F <- my.anova.summary[[1]]$`F value`[1] # extract F-value of omnibus F-test
if (p < .05) { # make our decision
decisions[i] = "reject H0" # reject the null hypothesis
} else {
decisions[i] = "accept H0" # or accept the null hypothesis
}
p.values[i] <- p # store the p-value
F.values[i] <- F # store the F-value
}
my.sims <- tibble(p.values, F.values, decisions)
# A tibble: 10,000 × 3
p.values F.values decisions
<dbl> <dbl> <chr>
1 0.668 0.409 accept H0
2 0.878 0.130 accept H0
3 0.950 0.0514 accept H0
4 0.813 0.209 accept H0
5 0.430 0.870 accept H0
6 0.777 0.255 accept H0
7 0.631 0.469 accept H0
8 0.719 0.334 accept H0
9 0.101 2.50 accept H0
10 0.827 0.191 accept H0
# ℹ 9,990 more rows
Fcrit <- sort(F.values)[round(nsims*.95)] # critical F-value
ggplot(data = my.sims, mapping = aes(x = F.values)) +
geom_histogram(bins = 100,
fill = "transparent",
color = "black") +
geom_vline(xintercept = Fcrit, color = "red", size = 1) +
theme_bw() + labs(title = "F values under H0",
subtitle = sprintf("n=%d simulated experiments", nsims))
my.sims <- tibble(p.values, F.values, decisions)
ggplot(data = my.sims, mapping = aes(x = p.values)) +
geom_histogram(breaks = seq(0,1,0.01),
fill = "transparent",
color = "black") +
geom_vline(xintercept = .05, color = "red", size = 1) +
theme_bw() + labs(title = "p-values under H0",
subtitle = sprintf("n=%d simulated experiments", nsims))
# A tibble: 2 × 3
decisions n percent
<chr> <int> <dbl>
1 accept H0 9495 0.950
2 reject H0 505 0.0505
power.anova.test()
will compute power for an ANOVApower.t.test()
will compute power for a t-test
Balanced one-way analysis of variance power calculation
groups = 3
n = 20.30205
between.var = 1
within.var = 4
sig.level = 0.05
power = 0.8
NOTE: n is number in each group
power.anova.test()
tells us we would need n=20 subjects per group to detect a difference between groups with a power of 0.8
Balanced one-way analysis of variance power calculation
groups = 3
n = 20.30205
between.var = 1
within.var = 4
sig.level = 0.05
power = 0.8
NOTE: n is number in each group
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = mood.gain ~ drug, data = clin.trial)
$drug
diff lwr upr p adj
anxifree-placebo 0.2666667 -0.1901184 0.7234518 0.3115006
joyzepam-placebo 1.0333333 0.5765482 1.4901184 0.0000854
joyzepam-anxifree 0.7666667 0.3098816 1.2234518 0.0015284
oneway.test()
if you are concerned about homogeneity of variance due to unequal sample sizes