Problem 17
hb1 <- c(7.2, 7.7, 8, 8.1, 8.3, 8.4, 8.4, 8.5, 8.6, 8.7, 9.1, 9.1, 9.1, 9.8, 10.1,10.3)
hb2 <- c(8.1, 9.2, 10, 10.4, 10.6, 10.9, 11.1, 11.9, 12, 12.1)
h0_1 <- 10
t.test(hb2, mu = h0_1 , conf.level = 1-(0.05/2))
##
## One Sample t-test
##
## data: hb2
## t = 1.5514, df = 9, p-value = 0.1552
## alternative hypothesis: true mean is not equal to 10
## 97.5 percent confidence interval:
## 9.539674 11.720326
## sample estimates:
## mean of x
## 10.63
In this case we would asume our hypothesis since 10 is in the CI / the p-value > alpha.
.————————————————————————————
#Since the two datasets have differing lenghts, we will define a new RV's.
µ1 <- mean(hb2)
µ2 <- mean(hb1)
t.test(hb2, mu=µ2, conf.level = 0.999)
##
## One Sample t-test
##
## data: hb2
## t = 4.722, df = 9, p-value = 0.001086
## alternative hypothesis: true mean is not equal to 8.7125
## 99.9 percent confidence interval:
## 8.688573 12.571427
## sample estimates:
## mean of x
## 10.63
We conclude from our t-test, that we will assume H0 , since p-value > alpha / µ2 in in the CI.
.————————————————————————————
#One-sided tests allow for the possibility of an effect in one direction. Two-sided tests test for the possibility of an effect in two directions—positive and negative. A one-sided test will test either if the mean is significantly greater than x or if the mean is significantly less than x, but not both. A one-sided test can be interpreted also as a CI with only the right-sided intervall with a greater (alpha) then the two sided one.
Problem 18
library("MASS")
?anorexia
data <- anorexia
# Treatment group
cbt <- subset(data, Treat== "CBT")
pre <- subset(cbt, select = Prewt)
pre_num <- as.numeric(unlist(pre))
post <- subset(cbt, select = Postwt)
post_num <- as.numeric(unlist(post))
# Lets assume the following Hypothesis. H0 assumes there is "no difference" (mean difference = ~0) whereas H0 is rejected, H1 would assume an effect of the treatment
t.test(pre_num,post_num, paired = T, var.equal = T, conf.level = 0.95 )
##
## Paired t-test
##
## data: pre_num and post_num
## t = -2.2156, df = 28, p-value = 0.03502
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -5.7869029 -0.2268902
## sample estimates:
## mean of the differences
## -3.006897
Given alpha = 5% this t.test reveals that there seems so be a significant effect of the CBT-treatment.
.————————————————————————————