dt <- read.csv("dt.csv", h = T)
str(dt)
## 'data.frame': 21 obs. of 5 variables:
## $ 嚜磨d : int 1 2 3 4 5 6 7 8 9 10 ...
## $ gender: int 2 2 2 2 2 2 2 2 2 2 ...
## $ T1 : int 13 13 11 14 7 13 8 15 13 15 ...
## $ T2 : int 9 8 7 9 6 10 7 11 9 9 ...
## $ T3 : int 13 12 7 10 5 11 8 15 8 13 ...
names(dt) <-c("ID", "gender", "T1", "T2", "T3")
ldta <- pivot_longer(dt, cols = c(, 3:5), names_to = "time", values_to = "number")
str(dt)
## 'data.frame': 21 obs. of 5 variables:
## $ ID : int 1 2 3 4 5 6 7 8 9 10 ...
## $ gender: int 2 2 2 2 2 2 2 2 2 2 ...
## $ T1 : int 13 13 11 14 7 13 8 15 13 15 ...
## $ T2 : int 9 8 7 9 6 10 7 11 9 9 ...
## $ T3 : int 13 12 7 10 5 11 8 15 8 13 ...
boxplot(number ~ time, data = ldta,
frame.plot = FALSE)
we can see from the plot that there are outliers in T2 and T3
plotmeans(number ~ time, data = ldta, frame = F)
aggregate(number ~ time, data = ldta, mean)
## time number
## 1 T1 11.857143
## 2 T2 8.285714
## 3 T3 9.333333
aggregate(number ~ time, data = ldta, sd)
## time number
## 1 T1 3.054271
## 2 T2 2.552310
## 3 T3 3.022141
#ANOVA
summary(aov(number ~ time, data = ldta))
## Df Sum Sq Mean Sq F value Pr(>F)
## time 2 141.6 70.78 8.501 0.000561 ***
## Residuals 60 499.5 8.33
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Conclusion: As the p-value is less than the significance level 0.05, we can conclude that there are significant differences among those groups.(有足夠的信心拒絕虛無假設)
#ANOVA for repeated measures
summary(aov(number ~ time + Error(ID), data = ldta))
##
## Error: ID
## Df Sum Sq Mean Sq F value Pr(>F)
## Residuals 1 25.14 25.14
##
## Error: Within
## Df Sum Sq Mean Sq F value Pr(>F)
## time 2 141.6 70.78 8.803 0.000451 ***
## Residuals 59 474.4 8.04
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1