###################################################################### # CPT data # # # ###################################################################### ###################################################################### #Create data time0 <- c(47, 34, 60, 59, 63, 44, 49, 53, 46, 41) time4 <- c(45, 32, 58, 57, 60, 38, 47, 51, 42, 38) cpt <- data.frame(time0, time4) cpt ###################################################################### #Plots boxplot(x = time0 - time4, data = cpt, main = "Box and dot plot", ylab = "Difference in hits", xlab = "", ylim = c(0,8), pars = list(outpch=NA)) stripchart(x = cpt$time0 - cpt$time4, lwd = 2, col = "red", method = "jitter", vertical = TRUE, pch = 1, main = "Dot plot", add = TRUE) hist(x = cpt$time0 - cpt$time4, main = "CPT data", xlab = "Difference in hits", freq = FALSE, xlim = c(0,6), col = NA) curve(expr = dnorm(x = x, mean = mean(cpt$time0 - cpt$time4), sd = sd(cpt$time0 - cpt$time4)), col = "red", add = TRUE) #What if we looked at separate plots for each time? set1 <- rbind(data.frame(hits = cpt$time0, time = 0), data.frame(hits = cpt$time4, time = 4)) boxplot(formula = hits ~ time, data = set1, main = "Box and dot plot", ylab = "Difference in hits", xlab = "", pars = list(outpch=NA), col = NA) stripchart(x = set1$hits ~ set1$time, lwd = 2, col = "red", method = "jitter", vertical = TRUE, pch = 1, main = "Dot plot", add = TRUE) ###################################################################### #Analysis d <- cpt$time0 - cpt$time4 dbar <- mean(d) s.d <- sd(d) alpha <- 0.01 n <- length(d) qt(p = 1 - alpha/2, df = n-1) #Interval lower <- dbar - qt(p = 1 - alpha/2, df = n-1) * s.d / sqrt(n) upper <- dbar + qt(p = 1 - alpha/2, df = n-1) * s.d / sqrt(n) data.frame(lower, upper) #Easiest way with t.test() - The first uses the original objects created by c(), # and the second uses the data frame. Unfortunaley, the data argument # in t.test() can not be used when the x and y arguments are present. t.test(x = time0, y = time4, conf.level = 0.99, paired = TRUE) t.test(x = cpt$time0, y = cpt$time4, conf.level = 0.99, paired = TRUE) #Using the differences directly t.test(x = d, conf.level = 0.99) #Independent sample analysis method - not the best way to analyze this data t.test(x = time0, y = time4, conf.level = 0.99, paired = FALSE) #Right tail test t.test(x = time0, y = time4, conf.level = 0.99, paired = TRUE, alternative = "greater") #Here's a different way that the data could have been arranged cpt.long <- data.frame(Person = c(1:10, 1:10), Time = c(rep(x = 1, times = 10), rep(x = 4, times = 10)), Hits = c(time0, time4)) cpt.long # The cpt.long data frame can now be used with t.test() using the formula argument t.test(formula = Hits ~ Time, data = cpt.long, conf.level = 0.99, paired = TRUE) ###################################################################### #Nonparametric analysis wilcox.test(x = time0, y = time4, data = cpt, alternative = "two.sided", paired = TRUE, mu = 0)