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), #Milk intake (in liter)
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), #Weight (in kilogram)
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)) #Age (in years)
data
cor.test(data$x,data$y)
##
## Pearson's product-moment correlation
##
## data: data$x and data$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
cor.test(data$x,data$z)
##
## Pearson's product-moment correlation
##
## data: data$x and data$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
cor.test(data$y,data$z)
##
## Pearson's product-moment correlation
##
## data: data$y and data$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
Based on the results, milk intake (in liter) and body weight (in kg) has a strong positive linear relationship just like the milk intake (in liter) and age (in years) of a person , while body weight (in kg) and age (in years) of a person has a moderate positive linear association.
a. Between Milk intake (in liter) and Body weight (in kg).
\(H_0:\rho=0\) (There is no linear
relationship between milk intake and body weight)
\(H_1:\rho\neq0\) (There is a linear
relationship between milk intake and body weight)
\(\alpha=0.05\)
Test Statistic: T-test
\[\begin{aligned}t_c&=\frac{r}{\sqrt{\frac{1-r^2}{n-2}}}\\
&=\frac{0.6136956}{\sqrt{\frac{1-0.6136956^2}{24-2}}}\\
&\approx3.65\end{aligned}\]
Decision Rule: Reject \(H_0\)
if \(|t_c|\ge t_{0.025,22}=2.07\);
otherwise, do not reject \(H_0\).
Decision: Reject \(H_0\) since
3.65>2.07.
Conclusion: At \(\alpha=0.05\), there is a sufficient
evidence to conclude that milk intake (in liter) and body weight (in kg)
has a linear association.
b. Between Milk intake (in liter) and age (in years).
\(H_0:\rho=0\) (There is no linear
relationship between milk intake and age of a person)
\(H_1:\rho\neq0\) (There is a linear
relationship between milk intake and age of a person)
\(\alpha=0.05\)
Test Statistic: T-test
\[\begin{aligned}t_c&=\frac{r}{\sqrt{\frac{1-r^2}{n-2}}}\\
&=\frac{0.767911}{\sqrt{\frac{1-0.767911^2}{24-2}}}\\
&\approx5.62\end{aligned}\]
Decision Rule: Reject \(H_0\)
if \(|t_c|\ge t_{0.025,22}=2.07\);
otherwise, do not reject \(H_0\).
Decision: Reject \(H_0\) since
5.62>2.07.
Conclusion: At \(\alpha=0.05\), there is a sufficient
evidence to conclude that milk intake (in liter) and age (in years) of a
person has a linear association.
c. Between weight (in kg) and age (in years) of a person.
\(H_0:\rho=0\) (There is no linear
relationship between weight and age of a person)
\(H_1:\rho\neq0\) (There is a linear
relationship between weight and age of a person)
\(\alpha=0.05\)
Test Statistic: T-test
\[\begin{aligned}t_c&=\frac{r}{\sqrt{\frac{1-r^2}{n-2}}}\\
&=\frac{ 0.509803}{\sqrt{\frac{1- 0.509803^2}{24-2}}}\\
&\approx2.78\end{aligned}\]
Decision Rule: Reject \(H_0\)
if \(|t_c|\ge t_{0.025,22}=2.07\);
otherwise, do not reject \(H_0\).
Decision: Reject \(H_0\) since
2.78>2.07.
Conclusion: At \(\alpha=0.05\), there is a sufficient
evidence to conclude that weight (in kg) and age (in years) of a person
has a linear association.
pcor.test(data$x,data$y,data$z, method = "pearson")
Based on the results, the correlation between milk intake and body weight while controlling for age is 0.40324146 which shows a moderate positive correlation. As milk intake increases, body weight also increases while the age is controlled.
Hypothesis testing at 𝛼=0.05.
a. Between Milk intake (in liter) and Body weight (in kg) controlling for age.
\(H_0:\rho_{xy.z}=0\)
\(H_1:\rho_{xy.z}\neq0\)
\(\alpha=0.05\)
Test Statistic: T-test
\[\begin{aligned}t_c&=\frac{r_p\sqrt{n-v}}{\sqrt{1-r_p^2}}\\
&=\frac{0.40324146\sqrt{24-3}}{\sqrt{1-0.40324146^2}}\\
&\approx2.02\end{aligned}\]
Decision Rule: Reject \(H_0\)
if \(|t_c|\ge t_{0.025,21}=2.08\);
otherwise, do not reject \(H_0\).
Decision: Do not reject \(H_0\) since 2.02<2.08.
Conclusion: At \(\alpha=0.05\), there is no sufficient
evidence to conclude that milk intake (in liter) and body weight (in kg)
has a linear association controlling for age.
model <- lm(y~ x + z, data = data)
summary(model)
##
## Call:
## lm(formula = y ~ x + z, data = 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
rsquared=(summary(model)$r.squared)
rsquared
## [1] 0.3802422
radjsquared=(summary(model)$adj.r.squared)
radjsquared
## [1] 0.3212177
R=sqrt(summary(model)$r.squared)
R
## [1] 0.6166378
Based on the results,\(R_{y.xz}\approx0.62\) is the multiple correlation coefficient between weight and the linear combination of milk intake and age. The linear combination of milk intake and age explained approximately 38% variance in the weight.
\[\begin{aligned}\bar{R}^2&=1-\frac{(1-R^2)(n-1)}{n-k-1}\\ &=1-\frac{(1-0.3802)(24-1)}{24-2-1}\\ &\approx0.3212\end{aligned}\]
Hypothesis Testing
\(H_0:\rho^2=0\)
\(H_1:\rho^2\neq0\)
\(\alpha=0.05\)
Test Statistic: F-test
\[\begin{aligned}F_c&=\frac{(n-k-1)\bar{R}^2}{k(1-\bar{R}^2)}\\
&=\frac{(24-2-1)0.3212}{2(1-0.3212)}\\
&\approx4.97\end{aligned}\]
Decision Rule: Reject \(H_0\)
if \(F_c \ge
F_{0.05,(2,21)}\approx3.47\); otherwise, do not reject \(H_0\).
Decision: Reject \(H_0\) since
4.97>3.47.
Conclusion: At \(\alpha=0.05\), there is A sufficient
evidence that there is significant association between weight and the
linear combination of milk intake and age.