Introduction

This project examines smartphone use and student sleep using two synthetic datasets. Dataset 1 contains between-subjects data from 100 fictional students. Dataset 2 contains within-subjects data from 50 fictional students measured before and after a phone-reduction program.

library(readxl)
library(effsize)

Dataset1 <- read_excel("Dataset1_Between_Subjects.xlsx")
Dataset2 <- read_excel("Dataset2_Within_Subjects.xlsx")

Analysis 1: Chi-Square Test of Independence

Research Question

Is there an association between students’ study mode and sleep quality?

Variables

  • Study mode: Online or In-Person
  • Sleep quality: Good or Poor

Hypotheses

Null hypothesis: Study mode and sleep quality are not associated.

Alternative hypothesis: Study mode and sleep quality are associated.

Statistical Test

A Chi-Square Test of Independence was used because both variables are categorical.

Chi_Table <- table(
  Dataset1$Study_Mode,
  Dataset1$Sleep_Quality
)

Chi_Table
##            
##             Good Poor
##   In-Person   36   15
##   Online      28   21
barplot(
  Chi_Table,
  beside = TRUE,
  col = c("lightblue", "lightgreen"),
  legend.text = rownames(Chi_Table),
  main = "Study Mode and Sleep Quality",
  xlab = "Sleep Quality",
  ylab = "Number of Students"
)

Chi_Result <- chisq.test(Chi_Table)
Chi_Result
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  Chi_Table
## X-squared = 1.4206, df = 1, p-value = 0.2333
Cramers_V <- sqrt(
  as.numeric(Chi_Result$statistic) /
    sum(Chi_Table)
)

Cramers_V
## [1] 0.1191905

Results

The Chi-Square Test of Independence did not show a statistically significant association between study mode and sleep quality, X²(1) = 1.42, p = .233. Cramer’s V was 0.12, indicating a weak association.

Interpretation

Sleep quality was not significantly associated with whether students studied online or in person. Therefore, the null hypothesis was not rejected.

Analysis 2: Pearson Correlation

Research Question

Is there a relationship between daily phone-use hours and nightly sleep hours?

Variables

  • Daily phone-use hours
  • Nightly sleep hours

Hypotheses

Null hypothesis: There is no relationship between daily phone-use hours and nightly sleep hours.

Alternative hypothesis: There is a relationship between daily phone-use hours and nightly sleep hours.

Statistical Test

A Pearson correlation was used because both variables are continuous and approximately normally distributed.

# Descriptive statistics for phone-use hours
mean(Dataset1$Phone_Hours)
## [1] 5.102
sd(Dataset1$Phone_Hours)
## [1] 1.860052
median(Dataset1$Phone_Hours)
## [1] 5.2
# Descriptive statistics for sleep hours
mean(Dataset1$Sleep_Hours)
## [1] 7.296
sd(Dataset1$Sleep_Hours)
## [1] 1.018408
median(Dataset1$Sleep_Hours)
## [1] 7.35
# Scatterplot
plot(
  Dataset1$Phone_Hours,
  Dataset1$Sleep_Hours,
  main = "Phone Use and Sleep Duration",
  xlab = "Daily Phone Use in Hours",
  ylab = "Nightly Sleep in Hours",
  pch = 19,
  col = "blue"
)

abline(
  lm(Sleep_Hours ~ Phone_Hours, data = Dataset1),
  col = "red",
  lwd = 2
)

# Histograms
hist(
  Dataset1$Phone_Hours,
  main = "Distribution of Phone Use",
  xlab = "Daily Phone Use in Hours"
)

hist(
  Dataset1$Sleep_Hours,
  main = "Distribution of Sleep Duration",
  xlab = "Nightly Sleep in Hours"
)

# Normality tests
shapiro.test(Dataset1$Phone_Hours)
## 
##  Shapiro-Wilk normality test
## 
## data:  Dataset1$Phone_Hours
## W = 0.98925, p-value = 0.6044
shapiro.test(Dataset1$Sleep_Hours)
## 
##  Shapiro-Wilk normality test
## 
## data:  Dataset1$Sleep_Hours
## W = 0.97994, p-value = 0.1315
# Pearson correlation
Correlation_Result <- cor.test(
  Dataset1$Phone_Hours,
  Dataset1$Sleep_Hours,
  method = "pearson"
)

Correlation_Result
## 
##  Pearson's product-moment correlation
## 
## data:  Dataset1$Phone_Hours and Dataset1$Sleep_Hours
## t = -8.0175, df = 98, p-value = 2.328e-12
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.7349369 -0.4940249
## sample estimates:
##        cor 
## -0.6293717

Results

Daily phone use had a mean of 5.10 hours (SD = 1.86), and nightly sleep had a mean of 7.30 hours (SD = 1.02). Both variables were approximately normally distributed because their Shapiro-Wilk test p-values were greater than .05.

There was a statistically significant strong negative relationship between daily phone use and nightly sleep, r(98) = -.63, p < .001.

Interpretation

Students who used their phones for more hours tended to sleep for fewer hours. Therefore, the null hypothesis was rejected.

Analysis 3: Independent t-Test

Research Question

Is there a difference in nightly sleep hours between students in the high phone-use group and students in the low phone-use group?

Variables

  • Phone-use group: High Use or Low Use
  • Nightly sleep hours

Hypotheses

Null hypothesis: There is no difference in mean sleep hours between the high-use and low-use groups.

Alternative hypothesis: There is a difference in mean sleep hours between the high-use and low-use groups.

Statistical Test

An independent t-test was used because two different groups were compared on a continuous outcome.

# Number of students in each group
table(Dataset1$Phone_Group)
## 
## High Use  Low Use 
##       55       45
# Group means
aggregate(
  Sleep_Hours ~ Phone_Group,
  data = Dataset1,
  FUN = mean
)
##   Phone_Group Sleep_Hours
## 1    High Use    6.858182
## 2     Low Use    7.831111
# Group standard deviations
aggregate(
  Sleep_Hours ~ Phone_Group,
  data = Dataset1,
  FUN = sd
)
##   Phone_Group Sleep_Hours
## 1    High Use   0.9990164
## 2     Low Use   0.7591329
# Group medians
aggregate(
  Sleep_Hours ~ Phone_Group,
  data = Dataset1,
  FUN = median
)
##   Phone_Group Sleep_Hours
## 1    High Use         6.8
## 2     Low Use         7.8
# Boxplot
boxplot(
  Sleep_Hours ~ Phone_Group,
  data = Dataset1,
  main = "Sleep Duration by Phone-Use Group",
  xlab = "Phone-Use Group",
  ylab = "Nightly Sleep in Hours",
  col = c("lightblue", "lightgreen")
)

# Test normality separately for each group
by(
  Dataset1$Sleep_Hours,
  Dataset1$Phone_Group,
  shapiro.test
)
## Dataset1$Phone_Group: High Use
## 
##  Shapiro-Wilk normality test
## 
## data:  dd[x, ]
## W = 0.96772, p-value = 0.1453
## 
## ------------------------------------------------------------ 
## Dataset1$Phone_Group: Low Use
## 
##  Shapiro-Wilk normality test
## 
## data:  dd[x, ]
## W = 0.97406, p-value = 0.4026
# Conduct the independent t-test
Independent_Result <- t.test(
  Sleep_Hours ~ Phone_Group,
  data = Dataset1,
  na.action = na.omit
)

Independent_Result
## 
##  Welch Two Sample t-test
## 
## data:  Sleep_Hours by Phone_Group
## t = -5.5301, df = 97.511, p-value = 2.68e-07
## alternative hypothesis: true difference in means between group High Use and group Low Use is not equal to 0
## 95 percent confidence interval:
##  -1.3220841 -0.6237745
## sample estimates:
## mean in group High Use  mean in group Low Use 
##               6.858182               7.831111
# Calculate Cohen's d
Independent_Effect <- cohen.d(
  Sleep_Hours ~ Phone_Group,
  data = Dataset1,
  na.rm = TRUE
)

Independent_Effect
## 
## Cohen's d
## 
## d estimate: -1.081917 (large)
## 95 percent confidence interval:
##     lower     upper 
## -1.508724 -0.655110

Results

Students in the high phone-use group slept an average of 6.86 hours, while students in the low phone-use group slept an average of 7.83 hours. The sleep scores in both groups were approximately normally distributed because both Shapiro-Wilk test p-values were greater than .05.

The independent t-test showed a statistically significant difference in sleep duration between the two groups, t(97.51) = -5.53, p < .001. The effect size was large, Cohen’s d = 1.08.

Interpretation

Students in the high phone-use group slept significantly fewer hours than students in the low phone-use group. Therefore, the null hypothesis was rejected.

Analysis 4: Dependent t-Test

Research Question

Is there a difference in students’ sleep duration before and after they followed a phone-reduction program?

Variables

  • Sleep hours before the phone-reduction program
  • Sleep hours after the phone-reduction program

Hypotheses

Null hypothesis: There is no mean difference in sleep duration before and after the phone-reduction program.

Alternative hypothesis: There is a mean difference in sleep duration before and after the phone-reduction program.

Statistical Test

A dependent t-test was used because the same students were measured before and after the program.

# Descriptive statistics before the program
mean(Dataset2$Sleep_Before)
## [1] 6.142
sd(Dataset2$Sleep_Before)
## [1] 0.7494461
median(Dataset2$Sleep_Before)
## [1] 6.1
# Descriptive statistics after the program
mean(Dataset2$Sleep_After)
## [1] 6.9
sd(Dataset2$Sleep_After)
## [1] 0.9299989
median(Dataset2$Sleep_After)
## [1] 6.7
# Calculate the difference scores
Dataset2$Sleep_Difference <-
  Dataset2$Sleep_Before - Dataset2$Sleep_After

# Histogram of difference scores
hist(
  Dataset2$Sleep_Difference,
  main = "Distribution of Sleep Difference Scores",
  xlab = "Sleep Before Minus Sleep After"
)

# Boxplot of difference scores
boxplot(
  Dataset2$Sleep_Difference,
  main = "Sleep Difference Scores",
  ylab = "Sleep Before Minus Sleep After",
  col = "lightblue"
)

# Test normality of difference scores
shapiro.test(Dataset2$Sleep_Difference)
## 
##  Shapiro-Wilk normality test
## 
## data:  Dataset2$Sleep_Difference
## W = 0.98056, p-value = 0.576
# Conduct the dependent t-test
Dependent_Result <- t.test(
  Dataset2$Sleep_Before,
  Dataset2$Sleep_After,
  paired = TRUE,
  na.action = na.omit
)

Dependent_Result
## 
##  Paired t-test
## 
## data:  Dataset2$Sleep_Before and Dataset2$Sleep_After
## t = -10.921, df = 49, p-value = 9.957e-15
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -0.8974747 -0.6185253
## sample estimates:
## mean difference 
##          -0.758
# Calculate Cohen's d
Dependent_Effect <- cohen.d(
  Dataset2$Sleep_Before,
  Dataset2$Sleep_After,
  paired = TRUE
)

Dependent_Effect
## 
## Cohen's d
## 
## d estimate: -0.8442637 (large)
## 95 percent confidence interval:
##     lower     upper 
## -1.022927 -0.665600

Results

Students slept an average of 6.14 hours before the program (SD = 0.75) and 6.90 hours after the program (SD = 0.93). The difference scores were approximately normally distributed, W = 0.98, p = .576.

The dependent t-test showed a statistically significant difference in sleep duration before and after the program, t(49) = -10.92, p < .001. The effect size was large, Cohen’s d = 0.84.

Interpretation

Students slept significantly longer after following the phone-reduction program. Therefore, the null hypothesis was rejected.

Conclusion

The analyses found no statistically significant association between study mode and sleep quality. However, greater phone use was significantly related to fewer hours of sleep. Students in the high phone-use group slept less than students in the low phone-use group. Students also slept longer after completing the phone-reduction program.