x <- c(5,8,12,12,13,14,17,18,18,18,19,20,20,21,25,26,27,27,27,29)
y <- c(6,4,8,20,10,14,10,15,20,15,14,16,24,8,20,15,13,28,25,29)
t.test(x,y,paired=T)
##
## Paired t-test
##
## data: x and y
## t = 2.5587, df = 19, p-value = 0.0192
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 0.564161 5.635839
## sample estimates:
## mean of the differences
## 3.1
x <- c(5,8,12,12,13,14,17,18,18,18,19,20,20,21,25,26,27,27,27,29)
y <- c(6,4,8,20,10,14,10,15,20,15,14,16,24,8,20,15,13,28,25,29)
t.test(x,y)
##
## Welch Two Sample t-test
##
## data: x and y
## t = 1.4113, df = 37.88, p-value = 0.1663
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1.3471 7.5471
## sample estimates:
## mean of x mean of y
## 18.8 15.7
prob8 = data.frame(x,y)
plot(y ~ x, data = prob8)
model = lm(y ~ x, data = prob8)
abline(model)
###2
y_hat_subj20 = 1.8414+0.7372*29
y_hat_subj20
## [1] 23.2202
residual_subj20 = 29-y_hat_subj20
residual_subj20
## [1] 5.7798
y_hat = 1.8414+0.7372*x
e = y-y_hat
prob8 = data.frame(x,y,y_hat,e)
SSE=sum(e^2)
MSE = SSE/18
MSE
## [1] 27.66848
anova(model)
## Analysis of Variance Table
##
## Response: y
## Df Sum Sq Mean Sq F value Pr(>F)
## x 1 470.17 470.17 16.993 0.0006398 ***
## Residuals 18 498.03 27.67
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
F_critical = pf(0.975, 1, 18, lower.tail = TRUE, log.p = FALSE)
F_critical
## [1] 0.6634755
#F_obtain > F_critical # Reject Ho
x_h = mean(x)
y_hat_h = 1.8414+0.7372*x_h
CI_Lower = y_hat_h - qt(0.975, 19)*(MSE/20)^0.5
CI_Lower
## [1] 13.23897
CI_Upper = y_hat_h + qt(0.975, 19)*(MSE/20)^0.5
CI_Upper
## [1] 18.16255
PI_Lower = y_hat_h - qt(0.975, 19)*(MSE*(21/20))^0.5
PI_Lower
## [1] 4.419399
PI_Upper = y_hat_h + qt(0.975, 19)*(MSE*(21/20))^0.5
PI_Upper
## [1] 26.98212
R_square = 470.17/(19*var(y))
R_square
## [1] 0.4856125