Systolic blood pressure of 5 patients assessed at baseline and at 2 weeks follow-up, after being adminstered a blood-pressure lowering drug.
SBP_data <- data.frame("SBP" = c(140,138,150,148,135,132,135,151,146,130),"group"=as.factor(c(rep(1,5),rep(2,5))),"ID"=as.factor(c(rep(1:5,2))))
library(ggplot2)
g <- ggplot(SBP_data, aes(x=group, y=SBP, group=factor(ID)))
g + geom_point() + geom_line(size=1, aes(col=ID))
perform two-sided paired t-test (utilising within-subject variance)
with(SBP_data, t.test(SBP[group == 2], SBP[group ==1], alternative="two.sided", paired= TRUE))
##
## Paired t-test
##
## data: SBP[group == 2] and SBP[group == 1]
## t = -2.2616, df = 4, p-value = 0.08652
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -7.5739122 0.7739122
## sample estimates:
## mean of the differences
## -3.4
Fail to reject the null hypothesis (p = 0.087) at significance level .05. Mean difference of 3.4 with confidence interval (-7.58, 0.77).
g1 <- SBP_data$SBP[SBP_data$group == 1]
g2 <- SBP_data$SBP[SBP_data$group == 2]
dif <- g2-g1
sample_mn <- mean(dif)
sample_sd <- sd(dif)
n <- 5
sample_mn + c(-1,1)*qt(.975,df=n-1)*sample_sd/sqrt(n)
## [1] -7.5739122 0.7739122