1. A psychologist conducts a study employing a sample of five children to determine whether there is a statistical relationship between the number of ounces of sugar a ten-year-old child eats per week (which will represent the X variable) and the number of cavities in a child’s mouth (which will represent the Y variable).
library(readxl)
Spearman <- read_excel("D:/MARV BS MATH/4th year, 2nd sem/Nonparametric Statistics/Final Exam/Spearman.xlsx")
Spearman
# A tibble: 5 × 3
  Child NumberofOunces NumberofCavities
  <dbl>          <dbl>            <dbl>
1     1             20                7
2     2              0                0
3     3              1                2
4     4             12                5
5     5              3                3
head(Spearman)
# A tibble: 5 × 3
  Child NumberofOunces NumberofCavities
  <dbl>          <dbl>            <dbl>
1     1             20                7
2     2              0                0
3     3              1                2
4     4             12                5
5     5              3                3
summary(Spearman)
     Child   NumberofOunces NumberofCavities
 Min.   :1   Min.   : 0.0   Min.   :0.0     
 1st Qu.:2   1st Qu.: 1.0   1st Qu.:2.0     
 Median :3   Median : 3.0   Median :3.0     
 Mean   :3   Mean   : 7.2   Mean   :3.4     
 3rd Qu.:4   3rd Qu.:12.0   3rd Qu.:5.0     
 Max.   :5   Max.   :20.0   Max.   :7.0     
library(ggplot2)
Warning: package 'ggplot2' was built under R version 4.2.2
ggplot(Spearman, aes(x=NumberofOunces, y=NumberofCavities)) + 
  geom_point(color='#2980B9', size = 4) + 
  geom_smooth(method=lm, se=FALSE, fullrange=TRUE, color='#2C3E50')
`geom_smooth()` using formula = 'y ~ x'

Null Hypothesis: There is no association between the two variables, NumberofOunces and NumberofCavities.

Alternative Hypothesis: There is an association between the two variables, NumberofOunces and NumberofCavities.

Interpretation

corr <- cor.test(x=Spearman$NumberofOunces, y=Spearman$NumberofCavities, method = 'spearman')
corr

    Spearman's rank correlation rho

data:  Spearman$NumberofOunces and Spearman$NumberofCavities
S = 4.4409e-15, p-value = 0.01667
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho 
  1 

Since the p value is 0.01667 which is less than the significance level 0.05, we have enough evidence to reject the null hypothesis. Thus, there is an association between the two variables, NumberofOunces and NumberofCavities.