We have 4 sections
DatasetB <- read_excel(“/Users/ha113ab/Desktop/datasets/DatasetA.xlsx”)—- we are reading the datasets from the folder that it was saved in accessing it through path.
In The First Section We are doing a Descriptive Statistics: here we are calculating means and standard deviations.
mean(DatasetA\(ScreenTime) ---- finds the average study hours sd(DatasetA\)SleepingHour) —- finds how spread out the study hours are. The same concepts follows for ExamScore
Then we displayed it through
hist(DatasetA$ScreenTime, main = “ScreenTime”, breaks = 20, col = “orange”, border = “black”, cex.main = 1, cex.axis = 1, cex.lab = 1)
AND
hist(DatasetA$SleepingHour, main = “SleepingHour”, breaks = 20, col = “grey”, border = “white”, cex.main = 1, cex.axis = 1, cex.lab = 1)
In The Second Section We are doing a Normality Tests: here we are checking if the data is normally distributed, or bell-shaped. shapiro_study <- shapiro.test(DatasetA$ScreenTime) tests if study hours follow a normal distribution. The same test is used for exam scores.
In The Third Section We are doing a Correlational Analysis: here we are checking relationships between variables. cor.test(DatasetA\(ScreenTime, DatasetA\)SleepingHour, method = “spearman”) checks the same but does not assume a straight-line relationship.
In The Fourth and Finak Sectionwe are basucally visualizing where hist() creates bar charts to show distributions. The first histogram displays how many students studied different amounts of hours. The second histogram shows how many students received different exam scores. ggscatter() creates a scatterplot with dots for each student and a trend line.
library(readxl)
library(ggpubr)
## Loading required package: ggplot2
DatasetB <- read_excel("/Users/ha113ab/Desktop/datasets/DatasetB.xlsx")
mean(DatasetB$ScreenTime)
## [1] 5.063296
sd(DatasetB$ScreenTime)
## [1] 2.056833
mean(DatasetB$SleepingHours)
## [1] 6.938459
sd(DatasetB$SleepingHours)
## [1] 1.351332
hist(DatasetB$ScreenTime,
main = "ScreenTime",
breaks = 20,
col = "navyblue",
border = "white",
cex.main = 1,
cex.axis = 1,
cex.lab = 1)
hist(DatasetB$SleepingHours,
main = "SleepingHours",
breaks = 20,
col = "green",
border = "white",
cex.main = 1,
cex.axis = 1,
cex.lab = 1)
shapiro.test(DatasetB$ScreenTime)
##
## Shapiro-Wilk normality test
##
## data: DatasetB$ScreenTime
## W = 0.90278, p-value = 1.914e-06
shapiro.test(DatasetB$SleepingHours)
##
## Shapiro-Wilk normality test
##
## data: DatasetB$SleepingHours
## W = 0.98467, p-value = 0.3004
cor.test(
DatasetB$ScreenTime,
DatasetB$SleepingHours,
method = "spearman"
)
##
## Spearman's rank correlation rho
##
## data: DatasetB$ScreenTime and DatasetB$SleepingHours
## S = 259052, p-value = 3.521e-09
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.5544674
ggscatter(
DatasetB,
x ="ScreenTime",
y ="SleepingHours",
add = "reg.line",
xlab = "ScreenTime",
ylab = "SleepingHours",
)