set.seed(1234) n <- 9 pre <- round(rnorm(n,50,2)) pre
## [1] 48 51 52 45 51 51 49 49 49
post <- pre+1+round(rnorm(n)) post
## [1] 48 52 52 45 52 53 50 49 49
Tuesday, January 13, 2015
set.seed(1234) n <- 9 pre <- round(rnorm(n,50,2)) pre
## [1] 48 51 52 45 51 51 49 49 49
post <- pre+1+round(rnorm(n)) post
## [1] 48 52 52 45 52 53 50 49 49
d <- post-pre (X <- cbind(pre,post,d))
## pre post d ## [1,] 48 48 0 ## [2,] 51 52 1 ## [3,] 52 52 0 ## [4,] 45 45 0 ## [5,] 51 52 1 ## [6,] 51 53 2 ## [7,] 49 50 1 ## [8,] 49 49 0 ## [9,] 49 49 0
(xbar <- round(apply(X,2,mean),2))
## pre post d ## 49.44 50.00 0.56
(sd <- round(apply(X,2,sd),2))
## pre post d ## 2.13 2.55 0.73
(se <- round(sd/sqrt(n),2))
## pre post d ## 0.71 0.85 0.24
sqrt(sum(se[1:2]^2)) # se of difference
## [1] 1.10752
t.test(d)
## ## One Sample t-test ## ## data: d ## t = 2.2942, df = 8, p-value = 0.05093 ## alternative hypothesis: true mean is not equal to 0 ## 95 percent confidence interval: ## -0.002868833 1.113979944 ## sample estimates: ## mean of x ## 0.5555556
t.test(pre,post)
## ## Welch Two Sample t-test ## ## data: pre and post ## t = -0.5019, df = 15.504, p-value = 0.6228 ## alternative hypothesis: true difference in means is not equal to 0 ## 95 percent confidence interval: ## -2.908271 1.797160 ## sample estimates: ## mean of x mean of y ## 49.44444 50.00000