Loading required packages

Loading Data

C1Mice <- read.csv("P:/SUNY-Brockport/SUNY Brockport_1/teaching/Staitstical Methods/Fall2019/Chapter1RLab/C1Mice.csv")
View(C1Mice)

Descriptive Stats on the four groups

names(C1Mice)
## [1] "Female.Trt" "Female.Ctl" "Male.Trt"   "Male.Ctl"
a<-favstats(~Female.Trt,data=C1Mice)
b<-favstats(~Female.Ctl,data=C1Mice)
c<-favstats(~Male.Trt,data=C1Mice)
d<-favstats(~Male.Ctl,data=C1Mice)
data_descriptive<-rbind(a,b,c,d)
kable(data_descriptive)
min Q1 median Q3 max mean sd n missing
1 2 2 7 10 4.4 3.911521 5 0
1 7 10 10 16 17 12.0 4.301163 5 0
2 3 5 6 9 10 6.6 2.880972 5 0
3 13 26 28 31 47 29.0 12.186058 5 0

Create Dotplot

stripchart(C1Mice,vertical=TRUE,method="jitter",col=c("red","blue","green","purple"))

Randomisation Test via simulation

reps <- 10
# ctl.fem <- c(16,10,10,7,17) #Literally typing data
ctl.fem<-C1Mice$Female.Ctl

#trt.fem <- c(1,2,2,10,7)
trt.fem<-C1Mice$Female.Trt

results <- numeric(reps) # establish a vector of the right length
# all 0s initially
x <- c(trt.fem, ctl.fem)
for (i in 1:reps) {
  temp <- sample(x)
  results[i] <- mean(temp[1:5])-mean(temp[6:10])
}
p.value <- sum(results >= 7.6) / reps
p.value
## [1] 0
hist(results,xlab="Control Mean - Treatment Mean")

p.value <- (sum(results <= -7.6)+sum(results >= 7.6)) / reps
p.value
## [1] 0
#Number of simulations resulting in a difference greater than or equal to 7.6:
  sum(results >= 7.6)
## [1] 0
#Number of simulations resulting in a difference less than or equal to -7.6:
  sum(results <= -7.6)
## [1] 0