mydata <- read.table("C:/Users/pauli/OneDrive/Desktop/BootcampR/R Take Home Exam/R Take Home Exam/Task 2/Body mass.csv", header = TRUE, sep = ";", dec = ",")
head(mydata)
##   ID Mass
## 1  1 62.1
## 2  2 64.5
## 3  3 56.5
## 4  4 53.4
## 5  5 61.3
## 6  6 62.2

Description: - ID: ID of a student - Mass: bodymass in kg

library(psych)
describe(mydata[,2])
##    vars  n  mean   sd median trimmed  mad  min  max range skew kurtosis   se
## X1    1 50 62.88 6.01   62.8   62.56 3.34 49.7 83.2  33.5 0.85     2.11 0.85

Based on the results, we can see that the skew is 0.85, that means the distribution is a little asymmetric to the right.

library(pastecs)
round(stat.desc(mydata[,-1]), 2)
##      nbr.val     nbr.null       nbr.na          min          max        range 
##        50.00         0.00         0.00        49.70        83.20        33.50 
##          sum       median         mean      SE.mean CI.mean.0.95          var 
##      3143.80        62.80        62.88         0.85         1.71        36.14 
##      std.dev     coef.var 
##         6.01         0.10

Explanation: The average body mass of the students in the 9th grade is 62.88kg, standard deviation is 6.01. Half of the students in the 9th grade have 62.80kg or less, the other half more than 62.80kg. The minimum body mass is 49.70kg and the maximum is 83.20kg, the difference between the min and max body mass is 33.5kg.

summary(mydata[,-1])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   49.70   60.23   62.80   62.88   64.50   83.20
hist(mydata$Mass,
     main="Distribution of the body mass",
     xlab = "Body mass in kg",
     ylab = "Frequency",
     breaks= seq(from=40, to=90, by=1))

Based on the histogram, we can not conclude, that the body mass distributes normally.

Hypothesis testing: H0:mu=59.9 H1:mu=/=59.9

t.test(mydata$Mass,
       mu=59.5,
       alternative = "two.sided")
## 
##  One Sample t-test
## 
## data:  mydata$Mass
## t = 3.9711, df = 49, p-value = 0.000234
## alternative hypothesis: true mean is not equal to 59.5
## 95 percent confidence interval:
##  61.16758 64.58442
## sample estimates:
## mean of x 
##    62.876

Explanation: It is extremely unlikely that average body mass in kg of the 9th grade students in 2021/2022 is the same as it was in 2018/2019. We reject H0 at p<0.05.

t <- 3.9711
r <- sqrt((t^2) / (t^2 + 49))
r
## [1] 0.4934295

Effect size: r is 0.49, so is a medium effect.