#to enter data from "treatment" group and "control" group:
trt<-c(25, 29, 34, 27, 31)
trt
## [1] 25 29 34 27 31
ctl<-c(37,28,28,25,31)
ctl
## [1] 37 28 28 25 31
#to combine data from treatment and control groups into one group
combine<-c(trt,ctl)
combine
## [1] 25 29 34 27 31 37 28 28 25 31
#to make a histogram of the data:
hist(combine, main="Histogram of Shapesplosion Game Data for Class",
xlab="Response Time (Number of Seconds to Complete Game)")

#to make a boxplot of the data:
boxplot(combine, main="Boxplot of Shapesplosion Game Data for Class",
ylab="Response Time (seconds)")

#t-test to evaluate hypothesis
#null: mean of treatment group = mean of control group
#alternative: mean of treatment group > mean of control group
t.test(trt, ctl)
##
## Welch Two Sample t-test
##
## data: trt and ctl
## t = -0.2339, df = 7.4994, p-value = 0.8213
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -6.584686 5.384686
## sample estimates:
## mean of x mean of y
## 29.2 29.8
#conclusion: based on the large p-value of 0.8213, we do not have enough
#evidence to reject the null hypothesis
#to check assumptions for t-test:
#need to check if have constant variance for two groups--use an F-test
#null hypothesis: variances are equal for both groups
#alternative hypothesis: variances are not equal for both groups
#first, calculate the variance of each group:
vartrt<-var(trt)
vartrt
## [1] 12.2
varctl<-var(ctl)
varctl
## [1] 20.7
#next, calculate the f-statistic:
f_value<-varctl/vartrt
f_value
## [1] 1.696721
#then, find the 95th quantile of F-distribution
#(degrees of freedom for each group is n-1):
quantile<-qf(.95, df1=4, df2=4)
quantile
## [1] 6.388233
#lastly, compare the f-statistic with the upper tail of F-distribution (quantile):
ifelse(f_value>quantile,"reject null hypothesis", "fail to reject null hypothesis")
## [1] "fail to reject null hypothesis"
#since "fail to reject null hypothesis", assumption of constant variance is met
#to check working directory
getwd()
## [1] "C:/Users/Diana/Desktop/Stat Methods-Fall 2015/R-Files"
#to be able to knit file together
library(knitr)