-
-
Notifications
You must be signed in to change notification settings - Fork 478
/
22.1_ClassicalANOVA.R
44 lines (37 loc) · 1.31 KB
/
22.1_ClassicalANOVA.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
library(rstan)
library(ggplot2)
## Read the pilots data & define variables
# Data are at http://www.stat.columbia.edu/~gelman/arm/examples/pilots
pilots <- read.table ("pilots.dat", header=TRUE)
attach (pilots)
group.names <- as.vector(unique(group))
scenario.names <- as.vector(unique(scenario))
n.group <- length(group.names)
n.scenario <- length(scenario.names)
successes <- NULL
failures <- NULL
group.id <- NULL
scenario.id <- NULL
for (j in 1:n.group){
for (k in 1:n.scenario){
ok <- group==group.names[j] & scenario==scenario.names[k]
successes <- c (successes, sum(recovered[ok]==1,na.rm=T))
failures <- c (failures, sum(recovered[ok]==0,na.rm=T))
group.id <- c (group.id, j)
scenario.id <- c (scenario.id, k)
}
}
y <- successes/(successes+failures)
y.mat <- matrix (y, n.scenario, n.group)
sort.group <- order(apply(y.mat,2,mean))
sort.scenario <- order(apply(y.mat,1,mean))
group.id.new <- sort.group[group.id]
scenario.id.new <- sort.scenario[scenario.id]
y.mat.new <- y.mat[sort.scenario,sort.group]
scenario.abbr <- c("Nagoya", "B'ham", "Detroit", "Ptsbgh", "Roseln", "Chrlt", "Shemya", "Toledo")
## Define variables
y <- successes/(successes+failures)
treatment <- group.id
airport <- scenario.id
## Classical anova of pilots data
## summary (aov (y ~ factor (treatment) + factor(airport))) FIXME