Ziyuan Huang
Last Updated: 2026-02-12
## 'data.frame': 15 obs. of 3 variables:
## $ person: num 1 2 3 4 5 6 7 8 9 10 ...
## ..- attr(*, "label")= chr "Participant"
## ..- attr(*, "format.spss")= chr "F8.0"
## $ dose : num 1 1 1 1 1 2 2 2 2 2 ...
## ..- attr(*, "label")= chr "Dose of Viagra"
## ..- attr(*, "format.spss")= chr "F8.0"
## ..- attr(*, "labels")= Named num [1:3] 1 2 3
## .. ..- attr(*, "names")= chr [1:3] "Placebo" "Low Dose" "High Dose"
## $ libido: num 3 2 1 1 4 5 2 4 2 3 ...
## ..- attr(*, "label")= chr "Libido"
## ..- attr(*, "format.spss")= chr "F8.0"
Before running ANOVA, we must check if our data is suitable:
ezANOVA)ez package, which makes ANOVA easy.wid).library(ez)
## Create a participant ID if you don't have one
master$partno <- 1:nrow(master)
options(scipen = 20)
ezANOVA(data = master,
dv = libido,
between = dose,
wid = partno,
type = 3,
detailed = T)## Coefficient covariances computed by hccm()
## $ANOVA
## Effect DFn DFd SSn SSd F p p<.05 ges
## 1 (Intercept) 1 12 180.26667 23.6 91.661017 0.0000005720565 * 0.8842381
## 2 dose 2 12 20.13333 23.6 5.118644 0.0246942895382 * 0.4603659
##
## $`Levene's Test for Homogeneity of Variance`
## DFn DFd SSn SSd F p p<.05
## 1 2 12 0.1333333 6.8 0.1176471 0.8900225
Levene’s Test:
ezANOVA(data = master, dv = libido, between = dose, wid = partno, type = 3, detailed = T)$`Levene's Test for Homogeneity of Variance`## DFn DFd SSn SSd F p p<.05
## 1 2 12 0.1333333 6.8 0.1176471 0.8900225
ANOVA Results:
## Effect DFn DFd SSn SSd F p p<.05 ges
## 1 (Intercept) 1 12 180.26667 23.6 91.661017 0.0000005720565 * 0.8842381
## 2 dose 2 12 20.13333 23.6 5.118644 0.0246942895382 * 0.4603659
pairwise.t.test(master$libido,
master$dose,
p.adjust.method = "bonferroni",
paired = F,
var.equal = T)##
## Pairwise comparisons using t tests with pooled SD
##
## data: master$libido and master$dose
##
## Placebo Low Dose
## Low Dose 0.845 -
## High Dose 0.025 0.196
##
## P value adjustment method: bonferroni
library(MOTE)
# Calculate Omega Squared
effect <- omega.F(dfm = 2, dfe = 12, Fvalue = 5.12, n = 15, a = .05)
effect$omega## [1] 0.3545611
master$dose2 <- master$dose
contrasts(master$dose2) <- contr.poly(3)
output <- aov(libido ~ dose2, data = master)
summary.lm(output)##
## Call:
## aov(formula = libido ~ dose2, data = master)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.0 -1.2 -0.2 0.9 2.0
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.4667 0.3621 9.574 0.000000572 ***
## dose2.L 1.9799 0.6272 3.157 0.00827 **
## dose2.Q 0.3266 0.6272 0.521 0.61201
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.402 on 12 degrees of freedom
## Multiple R-squared: 0.4604, Adjusted R-squared: 0.3704
## F-statistic: 5.119 on 2 and 12 DF, p-value: 0.02469
library(ggplot2)
cleanup <- theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(color = "black"))
ggplot(master, aes(dose, libido)) +
cleanup +
stat_summary(fun.y = mean, geom = "bar", fill = "White", color = "Black") +
stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width = .2) +
xlab("Dosage") + ylab("Libido")