This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code. When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.
library(plyr)
-------------------------------------------------------------------------------
You have loaded plyr after dplyr - this is likely to cause problems.
If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
library(plyr); library(dplyr)
-------------------------------------------------------------------------------
Attaching package: ‘plyr’
The following object is masked from ‘package:mosaic’:
count
The following objects are masked from ‘package:dplyr’:
arrange, count, desc, failwith, id, mutate, rename, summarise,
summarize
library(fastR)
library(knitr)
library(ggplot2)
library(ez)
raw <- read.csv("/Users/msb/Dropbox (Stanford HCI)/projects/dreamteam/dreamteam_data_raw.csv")
colnames(raw) <- c("condition", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11")
raw$teamid<-rownames(raw)
raw$condition <- factor(raw$condition, levels= c('self-managing', 'self-choosing', 'manager', 'dreamMAB', 'dreamteam'))
raw$improvement <- raw$r11 - raw$r1
raw$aggregate <- rowMeans(subset(raw, select = c("r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11")), na.rm = TRUE)
rawtall<-make.rm(constant=c("teamid", "condition"),repeated=c("r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11"), data=raw)
colnames(rawtall) <- c("teamid","condition","score","round")
rawtall$round <- factor(rawtall$round, levels=c('T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'T8', 'T9', 'T10', 'T11'))
joined<-join(rawtall, raw, by="teamid")
joined<-subset(joined, round!="T1", select = -c(r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, improvement, aggregate) )
head(joined)
Generating means and stdevs:
summary <- ddply(joined, .(condition), summarise,
mean_score=mean(score),
sd_score=sd(score),
se_score=sd(score)/sqrt(length(score)))
kable(summary, caption="Summary statistics")
| condition | mean_score | sd_score | se_score |
|---|---|---|---|
| self-managing | 4.777778 | 2.124114 | 0.2239013 |
| self-choosing | 4.555556 | 2.244149 | 0.2365541 |
| manager | 4.522222 | 2.001279 | 0.2109534 |
| dreamMAB | 4.677778 | 2.192058 | 0.2310632 |
| dreamteam | 6.611111 | 1.304223 | 0.1374772 |
summary_last <- ddply(subset(joined, round="T11"), .(condition), summarise,
mean_score=mean(score),
sd_score=sd(score),
se_score=sd(score)/sqrt(length(score)))
kable(summary_last, caption="Summary statistic for final round")
| condition | mean_score | sd_score | se_score |
|---|---|---|---|
| self-managing | 4.777778 | 2.124114 | 0.2239013 |
| self-choosing | 4.555556 | 2.244149 | 0.2365541 |
| manager | 4.522222 | 2.001279 | 0.2109534 |
| dreamMAB | 4.677778 | 2.192058 | 0.2310632 |
| dreamteam | 6.611111 | 1.304223 | 0.1374772 |
The overall average score per team for rounds R2-R11:
ggplot(joined) + geom_bar(aes(x=joined$condition, y=joined$score, fill=joined$condition), position="dodge", stat="summary", fun.y="mean") + geom_errorbar(data=summary, aes(x=condition, ymin=mean_score-se_score, ymax=mean_score+se_score), width=.1, color="gray") + guides(fill=FALSE) + scale_fill_brewer()
Average score by round:
ggplot(rawtall) + geom_bar(aes(x=rawtall$round, y=rawtall$score), position="dodge", stat="summary", fun.y="mean")
Overall score histogram:
ggplot(rawtall, aes(score)) + geom_histogram()
This model is a repeated measures analysis, with the DV as the score in each round. The subjects identifier is “teamid”. “condition” is a variable manipulated between subjects, and “r1” (round 1 score) is a covariate observed between subjects.
joinedaov <- ezANOVA(joined, score, teamid, between=condition, between_covariates=r1, return_aov=TRUE, detailed=TRUE)
Implementation of ANCOVA in this version of ez is experimental and not yet fully validated. Also, note that ANCOVA is intended purely as a tool to increase statistical power; ANCOVA can not eliminate confounds in the data. Specifically, covariates should: (1) be uncorrelated with other predictors and (2) should have effects on the DV that are independent of other predictors. Failure to meet these conditions may dramatically increase the rate of false-positives.Covariate"r1" is numeric and will therefore be fit to a linear effect.Collapsing data to cell means. *IF* the requested effects are a subset of the full design, you must use the "within_full" argument, else results may be inaccurate.
joinedaov$ANOVA
summary(joinedaov$aov)
Df Sum Sq Mean Sq F value Pr(>F)
condition 4 34.96 8.741 5.664 0.00104 **
Residuals 40 61.73 1.543
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Posthoc tests:
TukeyHSD(joinedaov$aov, "condition", ordered=TRUE)
Tukey multiple comparisons of means
95% family-wise confidence level
factor levels have been ordered
Fit: aov(formula = formula(aov_formula), data = data)
$condition
diff lwr upr p adj
self-choosing-manager 0.13030303 -1.5422454 1.802851 0.9994315
self-managing-manager 0.35252525 -1.3200232 2.025074 0.9739700
dreamMAB-manager 0.41414141 -1.2584070 2.086690 0.9536565
dreamteam-manager 2.39595960 0.7234112 4.068508 0.0017920
self-managing-self-choosing 0.22222222 -1.4503262 1.894771 0.9954160
dreamMAB-self-choosing 0.28383838 -1.3887101 1.956387 0.9883449
dreamteam-self-choosing 2.26565657 0.5931081 3.938205 0.0034273
dreamMAB-self-managing 0.06161616 -1.6109323 1.734165 0.9999710
dreamteam-self-managing 2.04343434 0.3708859 3.715983 0.0099230
dreamteam-dreamMAB 1.98181818 0.3092697 3.654367 0.0131771