散点图与箱线图,aov检验,mu值检验,模拟实验
#录入数据
obs <- c(27,31,29,28,34,36,34,34,28,28,28,26,26,32,37,24,34,41,42,44,26,35,
29,25,39,37,35,40,30,44,40,47,31,30,35,34,38,39,40,31,44,32,34,31,
34,34,37,28,30,28,30,25,32,31,45,28,26,20,21,28)
#建立数据框
treatments <- rep(rep(c("task1","task2","task3","task4","task5","task6"),each=2),5)
pulse <- data.frame(obs, treatments)
names(pulse) <- c("pchange", "task")
#绘制散点图和箱线图
stripchart(pchange~task, vertical=TRUE, pch=1, data=pulse)#vertical表示方向,pch表示散点的样式
boxplot(pchange~task, data=pulse)
#aov检验
fit <- aov(pchange~task, data=pulse) #run ANOVA
summary(fit)
#mu值的计算
mu <- mean(pulse$pchange) #estimate of mu
mu_i <- tapply(pulse$pchange, pulse$task, mean) #estimates of mu_i
tau_i <- mu_i-mu #estimates of tau_i
tau_i #display
#模拟实验
N <- 13
trtmt <- c(rep(1,3),rep(2,5),rep(3,5))
set.seed(123) #to replicate results
rv <- runif(N)
design <- data.frame(trtmt,rv)
design <- design[order(design$rv),]
design$expUnit <- 1:N
design #view