Vít Gabrhel
vit.gabrhel@mail.muni.cz
FSS MU,
14. 11. 2016
Úvod
Představuje řešení situace, kdy je při opakovaných měřeních porušen předpoklad ANOVA či lineární regrese o nezávislosti pozorování
Rozptyl v rámci Repeated Measures ANOVA (dle Field, 2012)
Rozptyl v rámci Repeated Measures ANOVA (dle Field, 2012)
Variabilita mezi měřeními (SSM)
We worked out how much variation could be explained by our experiment (the model SS) by looking at the means for each group and comparing these to the overall mean. So, we measured the variance resulting from the differences between group means and the overall mean
Variabilita mezi subjekty (SSW)
This equation simply means that we are looking at the variation in an individual’s scores and then adding these variances for all the people in the study. The ns simply represent the number of scores on which the variances are based
Celkový rozptyl (SST)
Rozptyl v rámci Repeated Measures ANOVA (dle Field, 2012)
Chybový rozptyl (SSR)
The between-participant sum of squares (SSB)
Rozptyl v rámci Repeated Measures ANOVA (dle Field, 2012)
The mean squares
SSM tells us how much variation the model (e.g. the experimental manipulation) explains and SSR tells us how much variation is due to extraneous factors.
F-ratio
The F-ratio is a measure of the ratio of the variation explained by the model and the variation explained by unsystematic factors.
It can be calculated by dividing the model mean squares by the residual mean squares
Rozptyl v rámci Repeated Measures ANOVA
k - počet podmínek (treatments)
n - počet participantů (pozorování)
df_Total - number of observations (across all levels of the within-subjects factor, n) – 1
Výhody
Vyšší statistická síla
Menší počet potřebných participantů
Nevýhody
Order effect
Missing values
Data: Cognitive training
Data: Cognitive training
setwd()
dir()
install.packages("readxl")
library("readxl")
excel_sheets("RMANOVA.xlsx")
RMANOVA = read_excel("RMANOVA.xlsx", sheet = 1)
View(RMANOVA)
RMANOVA$condition2 = factor(RMANOVA$condition, order = TRUE, levels = c("8 days", "12 days", "17 days", "19 days"))
RMANOVA$subject2 = factor(RMANOVA$subject, order = FALSE)
Statistický popis dat
# Summary statistics by group
library(psych)
describeBy(RMANOVA, group = RMANOVA$condition2)
# Boxplot
library(ggplot2)
bp1 = ggplot(RMANOVA, aes(condition2, iq))
bp1 + geom_boxplot(aes(fill=condition2), alpha=I(0.5)) +
geom_point(position="jitter", alpha=0.5) +
geom_boxplot(outlier.size=0, alpha=0.5) +
theme(
axis.title.x = element_text(face="bold", color="black", size=12),
axis.title.y = element_text(face="bold", color="black", size=12),
plot.title = element_text(face="bold", color = "black", size=12)) +
labs(x="Condition",
y = "IQ gain",
title= "IQ gain by the days of training") + theme(legend.position='none')
F-test a F-Ratio
Funkce aov
# Apply the aov function
model <- aov(iq ~ condition2 + Error(subject2 / condition2), data = RMANOVA)
# Look at the summary table of the result
summary(model)
F-test a F-Ratio
Funkce ezANOVA
# ez package
install.packages("ez")
library("ez")
newModel <- ezANOVA(data = dataFrame, dv = .(outcome variable), wid = .(variable that identifies participants), within = .(repeated measures predictors), between = .(between-group predictors), detailed = TRUE, type = 2)
# Apply the ezANOVA function
model2 <- ezANOVA(data = RMANOVA, dv = .(iq), wid = .(subject2), within = .(condition2), detailed = TRUE, type = 3)
model2
F-test a F-Ratio
Multilevel approach
install.packages("nlme")
library("nlme")
model3 = lme(iq ~ condition2, random = ~1|subject2/condition2, data = RMANOVA, method = "ML")
summary(model3)
ss_cond = 196.1
ss_total = 196.1 + 297.8
eta_sq <- ss_cond / ss_total
dfeffect = 3
MSeffect = 65.36
MSerror = 5.22
SStotal = 196.1 + 297.8
MSsubjects = 9.242
Omega2 = (dfeffect * (MSeffect - MSerror)) / (SStotal + MSsubjects)
Předpoklady použití
Povaha proměnných
Normalita rozložení závislé proměnné
Sféricita
Předpoklady použití
Mauchy's test
# Define the iq data frame
iq <- cbind(RMANOVA$iq[RMANOVA$condition == "8 days"],
RMANOVA$iq[RMANOVA$condition == "12 days"],
RMANOVA$iq[RMANOVA$condition == "17 days"],
RMANOVA$iq[RMANOVA$condition == "19 days"])
# Make an mlm object
mlm <- lm(iq ~ 1)
# Mauchly's test
mauchly.test(mlm, x = ~ 1)
Předpoklady použití
# Normalita rozložení
ggplot(data=RMANOVA, aes(RMANOVA$iq)) +
geom_histogram(breaks=seq(0, 20, by = 2),
col="red",
aes(fill=..count..)) +
scale_fill_gradient("Count", low = "green", high = "red")+
labs(title="Histogram for IQ Gain") +
labs(x="IQ Gain", y="Count") + theme(legend.position='none')
ggplot(RMANOVA, aes(x=iq, fill=condition2)) +
geom_histogram(position="identity", binwidth=1, alpha=0.5)
Friedmanův test
friedman.test(iq ~ condition2 | subject2, data = RMANOVA)
Úvod
Allow for multiple pairwise comparisons without an increase in the probability of a Type I error
Používáme, pokud nemáme dopředu jasné hypotézy
Z principu jsou oboustranné
Je jich mnoho – liší se v několika parametrech:
Doporučení podle Fielda (2012)
Not only does sphericity create problems for the F in repeated-measures ANOVA, but also it causes some amusing complications for post hoc tests
Tukey
# funkce glht
library(multcomp)
posthoc = glht(model3, linfct = mcp(condition2 = "Tukey"))
summary(posthoc)
Bonferroni
# Pairwise t-test
with(RMANOVA, pairwise.t.test(iq, condition, p.adjust.method = "bonferroni", paired = T))
# glht
summary(glht(model3, linfct=mcp(condition2 = "Tukey")), test = adjusted(type = "bonferroni"))
# dunn.test
install.packages("dunn.test")
library("dunn.test")
dunn.test (x = RMANOVA$iq, g=RMANOVA$condition2, method="sidak", kw=TRUE, label=TRUE,
wrap=FALSE, table=TRUE, list=FALSE, rmc=FALSE, alpha=0.05)
Úvod
Umožňují porovnat jednotlivé skupiny v jednom kroku bez nutnosti korigovat hladinu významnosti (bez snížení síly testu)
Každý kontrast srovnává 2 podmínky
# Helmertův kontrast
options(contrasts = c("contr.helmert", "contr.poly"))
contrasts(RMANOVA$condition2) <- "contr.helmert"
model3 = lme(iq ~ condition2, random = ~1|subject2/condition2, data = RMANOVA, method = "ML")
summary(model3)
Field, A., Miles, J., & Field, Z. (2012). Discovering Statistics Using R. Sage: UK.
Navarro, D. J. (2014). Learning statistics with R: A tutorial for psychology students and other beginners. Available online: http://health.adelaide.edu.au/psychology/ccs/teaching/lsr/