1.
x <- c(10, 13, 19, 16, 13, 21, 23, 29, 27, 16, 13, 14, 21, 18, 17, 23, 22, 19, 11, 17, 19, 21, 25, 22)
y <- c(29, 33, 41, 47, 51, 43, 31, 49, 71, 42, 31, 35, 62, 55, 58, 72, 68, 60, 41, 42, 54, 57, 62, 54)
z <- c(17, 23, 21, 29, 37, 41, 39, 47, 43, 18, 16, 17, 26, 24, 25, 32, 35, 31, 28, 26, 33, 42, 45, 36)
test1 <- cor.test(x, y)
test2 <- cor.test(x, z)
test3 <- cor.test(y, z)
test1
##
## Pearson's product-moment correlation
##
## data: x and y
## t = 3.6458, df = 22, p-value = 0.001425
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.2794903 0.8152634
## sample estimates:
## cor
## 0.6136956
test2
##
## Pearson's product-moment correlation
##
## data: x and z
## t = 5.623, df = 22, p-value = 1.183e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.5281076 0.8942831
## sample estimates:
## cor
## 0.767911
test3
##
## Pearson's product-moment correlation
##
## data: y and z
## t = 2.7795, df = 22, p-value = 0.01093
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.1339544 0.7574317
## sample estimates:
## cor
## 0.509803
Correlation between x and y: r = 0.6136956, there is a strong positive linear association between milk intake(in liter) and body weight(in kg) of a person.
Correlation between x and z: r = 0.767911, there is a strong positive linear association between milk intake(in liter) and age(in years) of a person.
Correlation between y and z: r = 0.509803, there is a moderate positive linear association between body weight(in kg) and age(in years) of a person.
2.
n <- 24
r1 <- 0.6136956
t1 <- r1/(sqrt((1-r1^{2})/(n-2))) # calculating the test statistic
t1
## [1] 3.645765
\(H_o: \rho = 0\)
\(H_a: \rho \neq 0\)
\(\alpha = 0.05\)
Test statistic: t = 3.645765
Decision Rule: Reject Ho if \(|t_c|\geq\) \(t_{0.025}=2.074\); otherwise, do not reject Ho.
Decision: Reject Ho since 3.645765 > 2.074 and p-value=0.001425 < \(\alpha\)
Conclusion: At \(\alpha = 0.05\), there is sufficient evidence to conclude that milk intake(in liter) and weight(in kg) of a person are positively related.
n <- 24
r2 <- 0.767911
t2 <- r2/(sqrt((1-r2^{2})/(n-2))) # calculating the test statistic
t2
## [1] 5.622957
\(H_o: \rho = 0\)
\(H_a: \rho \neq 0\)
\(\alpha = 0.05\)
Test statistic: t = 5.622957
Decision Rule: Reject Ho if \(|t_c|\geq\) \(t_{0.025}=2.074\); otherwise, do not reject Ho.
Decision: Reject Ho since 5.622957 > 2.074 and p-value= 0.00001183 < \(\alpha\)
Conclusion: At \(\alpha = 0.05\), there is sufficient evidence to conclude that milk intake(in liter) and age(in years) of a person are positively related.
n <- 24
r3 <- 0.509803
t3 <- r3/(sqrt((1-r3^{2})/(n-2))) # calculating the test statistic
t3
## [1] 2.77951
\(H_o: \rho = 0\)
\(H_a: \rho \neq 0\)
\(\alpha = 0.05\)
Test statistic: t = 2.77951
Decision Rule: Reject Ho if \(|t_c|\geq\) \(t_{0.025}=2.074\); otherwise, do not reject Ho.
Decision: Reject Ho since 2.77951 > 2.074 and p-value= 0.01093 < \(\alpha\)
Conclusion: At \(\alpha = 0.05\), there is sufficient evidence to conclude that body weight(in kg) and age(in years) of a person are positively related.
3.
library(ppcor)
## Loading required package: MASS
sample_data <- data.frame(x=c(10, 13, 19, 16, 13, 21, 23, 29, 27, 16, 13, 14, 21, 18, 17, 23, 22, 19, 11, 17, 19, 21, 25, 22),y=c(29, 33, 41, 47, 51, 43, 31, 49, 71, 42, 31, 35, 62, 55, 58, 72, 68, 60, 41, 42, 54, 57, 62, 54),z=c(17, 23, 21, 29, 37, 41, 39, 47, 43, 18, 16, 17, 26, 24, 25, 32, 35, 31, 28, 26, 33, 42, 45, 36))
pcor(sample_data)
## $estimate
## x y z
## x 1.0000000 0.40324146 0.66993901
## y 0.4032415 1.00000000 0.07620291
## z 0.6699390 0.07620291 1.00000000
##
## $p.value
## x y z
## x 0.0000000000 0.0563976 0.0004702747
## y 0.0563975998 0.0000000 0.7296590106
## z 0.0004702747 0.7296590 0.0000000000
##
## $statistic
## x y z
## x 0.000000 2.0193393 4.1352095
## y 2.019339 0.0000000 0.3502239
## z 4.135209 0.3502239 0.0000000
##
## $n
## [1] 24
##
## $gp
## [1] 1
##
## $method
## [1] "pearson"
n <- 24
rp <- 0.40324146
v <- 3
t4 <- (rp*sqrt(n-v))/(sqrt(1-rp^{2})) # calculating the test statistic
t4
## [1] 2.019339
\(H_o: \rho_{xy.z} = 0\)
\(H_a: \rho_{xy.z} \neq 0\)
\(\alpha = 0.05\)
Test statistic: t = 2.019339
Decision Rule: Reject Ho if \(|t_c|\geq\) \(t_{0.025, 24-3}=2.08\); otherwise, do not reject Ho.
Decision: Do not reject Ho since 2.019339 < 2.08 and p-value=0.056 > \(\alpha\)
Conclusion: At \(\alpha = 0.05\), there is no sufficient evidence that there is a linear association between milk intake(in liter) and body weight(in kg) while controlling for age of a person.
4.
model <- lm(y ~ x + z, data = sample_data)
summary(model)
##
## Call:
## lm(formula = y ~ x + z, data = sample_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -25.645 -6.748 1.635 8.329 16.252
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 19.2210 8.7153 2.205 0.0387 *
## x 1.4097 0.6981 2.019 0.0564 .
## z 0.1282 0.3661 0.350 0.7297
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.63 on 21 degrees of freedom
## Multiple R-squared: 0.3802, Adjusted R-squared: 0.3212
## F-statistic: 6.442 on 2 and 21 DF, p-value: 0.006582
r.squared <- summary(model)$r.squared
multiple.R <- sqrt(r.squared)
multiple.R
## [1] 0.6166378
r.squared
## [1] 0.3802422
r.adjsquared <- summary(model)$adj.r.squared
multiple.Radj <- sqrt(r.adjsquared)
multiple.Radj
## [1] 0.5667607
r.adjsquared
## [1] 0.3212177
\(R_{y.xz} = 0.6166378\), this means that the multiple correlation coefficient between a person’s body weight(in kg.) and the linear combination of milk intake(in liter) and age(in years) is 0.6166378.
\(R^{2}=0.3802422\); The linear combination of milk intake(in liter) and age(in years) explained approximately 38% variance in the body weight(in kg) of a person.
\(\tilde{R}^{2}=0.3212177\)
5.
n=24
k= 2
r2=0.3212177
F=((n-k-1)*r2)/(k*(1-r2)) # computing for the test statistic
F
## [1] 4.968877
qf(0.05, 2,21, lower.tail=FALSE)
## [1] 3.4668
\(H_o: \rho^2_{y.xz} = 0\)
\(H_a: \rho^2_{y.xz} \neq 0\)
\(\alpha = 0.05\)
Test statistic: F = 4.968877
Decision Rule: Reject Ho if \(F_c\geq\) \(t_{0.05(2,21)}=3.4668\); otherwise, do not reject Ho.
Decision: Reject Ho since 4.968877 > 3.4668.
Conclusion: At \(\alpha = 0.05\), there is sufficient evidence that there is a significant association between a person’s body weight(in kg) and the linear combination of milk intake(in liter) and age(in years). Moreover, the linear combination of milk intake and age can only explain over 32%(using the adjusted value of \(R^2\)) variation in the body weight of a person.