Loading libraries/packages & paths
# Opening the packages we need
library(openxlsx) # package to open xlsx files
library(dplyr) # A grammar of data manipulation
library(tidyr) # for pivot_wider to reshape data
library(ggplot2) # to use ggplot for plotting
library(jtools) # to use summ for summarizing models
library(lme4) # to use lmer for mixed models (testing between and within effects)
library(psych) # to use describe
if(nchar(system.file(package="lme4"))) citation("lme4")
# Creating data paths
path <- "/Users/emurbanw/Dropbox (University of Michigan)/MED-EFDC-DDC-internal/Consultations/Cathy_Goldstein_5.2024/"
# Loading the xlsx workbook; Note that if your xlsx file is not password encrypted you can type anything into the pw box (or just remove the password call in the code below)
wb <- loadWorkbook(paste0(path, "data_raw.xlsx"))
# What are the sheet names in the xlsx datafile? These will be input into later calls to open up each sheet.
sheets <- getSheetNames(paste0(path, "data_raw.xlsx"))
print(sheets)
Opening, appending, and saving the data
# Opening separate data tabs
I01 <- read.xlsx(paste0(path, "data_raw.xlsx"), detectDates = TRUE, sheet = "I01")
I03 <- read.xlsx(paste0(path, "data_raw.xlsx"), detectDates = TRUE, sheet = "I03")
I04 <- read.xlsx(paste0(path, "data_raw.xlsx"), detectDates = TRUE, sheet = "I04")
I05 <- read.xlsx(paste0(path, "data_raw.xlsx"), detectDates = TRUE, sheet = "I05")
I07 <- read.xlsx(paste0(path, "data_raw.xlsx"), detectDates = TRUE, sheet = "I07")
I08 <- read.xlsx(paste0(path, "data_raw.xlsx"), detectDates = TRUE, sheet = "I08")
I09 <- read.xlsx(paste0(path, "data_raw.xlsx"), detectDates = TRUE, sheet = "I09")
I10 <- read.xlsx(paste0(path, "data_raw.xlsx"), detectDates = TRUE, sheet = "I10")
data <- rbind(I01, I03, I04, I05, I07, I08, I09, I10)
# Transforming the excel date-time serial number (the integer portion represents the day since Jan 1 1900, the decimal portion is the time)
data$SleepOnsetDateTimeR <- openxlsx::convertToDateTime(data$SleepOnsetDateTime)
data$WakeDateTimeR <- openxlsx::convertToDateTime(data$WakeDateTime)
# Making a SleepOnsetTime and WakeTime (no dates)
data <- data %>%
mutate(SleepOnsetDate = floor(SleepOnsetDateTime),
SleepOnsetTime = SleepOnsetDateTime - SleepOnsetDate,
WakeDate = floor(WakeDateTime),
WakeTime = WakeDateTime - WakeDate)
data$SleepOnsetDate <- floor(data$SleepOnsetDateTime)
data$SleepOnsetTime <- data$SleepOnsetDateTime - data$SleepOnsetDate
data$WakeDate <- floor(data$WakeDateTime)
data$WakeTime <- data$WakeDateTime - data$WakeDate
data <- data[ ,c("ID", "Method", "Day", "Dayb", "SleepDate", "SleepOnsetDateTimeR", "SleepOnsetDateTime", "SleepOnsetDate", "SleepOnsetTime", "WakeDateTimeR", "WakeDateTime", "WakeDate", "WakeTime", "TotalSleepTimeMinutes", "TotalAwakeTimeMinutes", "SleepPercentage", "AverageRMSSD", "AverageHF", "AverageLF", "ParticipantId")]
write.csv(data, (paste0(path, "data.csv")))
Calculating differences
data <- read.csv((paste0(path, "data.csv")))
data$Method <- as.factor(data$Method)
data_wide <- data %>%
pivot_wider(
id_cols = c(ID, Day, Dayb),
names_from = (Method),
values_from = c("SleepDate", "SleepOnsetDateTimeR", "SleepOnsetDateTime", "SleepOnsetDate", "SleepOnsetTime", "WakeDateTimeR", "WakeDateTime", "WakeDate", "WakeTime", "TotalSleepTimeMinutes", "TotalAwakeTimeMinutes", "SleepPercentage", "AverageRMSSD", "AverageHF", "AverageLF")
)
data_wide <- data_wide %>%
mutate(SleepOnsetDate_diff = SleepOnsetDate_automated - SleepOnsetDate_cleaned,
SleepOnsetDateTime_diff = SleepOnsetDateTime_automated - SleepOnsetDateTime_cleaned,
WakeDate_diff = WakeDate_automated - WakeDate_cleaned,
WakeDateTime_diff = WakeDateTime_automated - WakeDateTime_cleaned,
TotalSleepTimeMinutes_diff = TotalSleepTimeMinutes_automated - TotalSleepTimeMinutes_cleaned,
TotalAwakeTimeMinutes_diff = TotalAwakeTimeMinutes_automated - TotalAwakeTimeMinutes_cleaned,
SleepPercentage_diff = SleepPercentage_automated - SleepPercentage_cleaned)
write.csv(data_wide, (paste0(path, "data_wide.csv")))
Descriptives
# 1 night of missing data; 55 nights with data in for both automated and cleaned
nrow(data_wide[is.na(data_wide$SleepOnsetDateTime_automated), ])
## [1] 1
nrow(data_wide[!is.na(data_wide$SleepOnsetDateTime_automated), ])
## [1] 55
# Differences in SleepOnsetDateTime by Method; range from -7380 seconds (123 minutes) to 0 seconds
# Note: To convert from Date-Time serial format we multiple the value by 86400 seconds (the number of seconds in a day) OR by 1440 minutes (the number of minutes in a day)
# -0.0854166666977108 * 86400 = -7380 seconds
nrow(data_wide[is.na(data_wide$SleepOnsetDateTime_diff), ]) # 1 missing
## [1] 1
table(data_wide$SleepOnsetDateTime_diff)
##
## -0.0854166666977108 -0.0218749999985448 -0.0125000000043656
## 1 1 1
## -0.00833333330228925 -0.00694444450346055 -0.00624999999854481
## 2 1 1
## -0.00312499999563443 0
## 1 47
nrow(data_wide[data_wide$SleepOnsetDateTime_diff < 0 & !is.na(data_wide$SleepOnsetDateTime_diff), ]) # 8 cases where sleep onset date time is earlier in automated vs. cleaned (8/55 = 14.5%)
## [1] 8
length(unique(data_wide$ID[data_wide$SleepOnsetDateTime_diff < 0 & !is.na(data_wide$SleepOnsetDateTime_diff)])) # 4 participants where this is the case
## [1] 4
nrow(data_wide[data_wide$SleepOnsetDateTime_diff == 0 & !is.na(data_wide$SleepOnsetDateTime_diff), ]) # 47 cases where they are identical (47/55 = 85.5%)
## [1] 47
length(unique(data_wide$ID[data_wide$SleepOnsetDateTime_diff == 0 & !is.na(data_wide$SleepOnsetDateTime_diff)])) # 8 participants where this is the case
## [1] 8
nrow(data_wide[data_wide$SleepOnsetDateTime_diff > 0 & !is.na(data_wide$SleepOnsetDateTime_diff), ]) # 0 cases where sleep onset date time is later in automated vs. cleaned (0/55 = 0%)
## [1] 0
# Differences in WakeDateTime by Method; range from -10,350 seconds (172.5 minutes) to 1260 seconds (21 minutes)
# Note: To convert from Date-Time serial format we multiple the value by 86400 seconds (the number of seconds in a day) OR by 1440 minutes (the number of minutes in a day)
# -0.119791666598758 * 86400 = -10350 seconds
nrow(data_wide[is.na(data_wide$WakeDateTime_diff), ]) # 1 missing
## [1] 1
table(data_wide$WakeDateTime_diff)
##
## -0.119791666598758 0 0.0145833333008341
## 1 53 1
nrow(data_wide[data_wide$WakeDateTime_diff < 0 & !is.na(data_wide$WakeDateTime_diff), ]) # 1 case where wake date time is earlier in automated vs. cleaned (1/55 = 1.8%)
## [1] 1
length(unique(data_wide$ID[data_wide$WakeDateTime_diff < 0 & !is.na(data_wide$WakeDateTime_diff)])) # 1 participants where this is the case
## [1] 1
nrow(data_wide[data_wide$WakeDateTime_diff == 0 & !is.na(data_wide$WakeDateTime_diff), ]) # 53 cases where they are identical (53/55 = 96.4%)
## [1] 53
length(unique(data_wide$ID[data_wide$WakeDateTime_diff == 0 & !is.na(data_wide$WakeDateTime_diff)])) # 8 participants where this is the case
## [1] 8
nrow(data_wide[data_wide$WakeDateTime_diff > 0 & !is.na(data_wide$WakeDateTime_diff), ]) # 1 case where wake date time is later in automated vs. cleaned (1/55 = 1.8%)
## [1] 1
length(unique(data_wide$ID[data_wide$WakeDateTime_diff > 0 & !is.na(data_wide$WakeDateTime_diff)])) # 1 participant where this is the case
## [1] 1
# Differences in TotalSleepTimeMinutes by Method; range from -92.5 minutes to 30.5 minutes
nrow(data_wide[is.na(data_wide$TotalSleepTimeMinutes_diff), ]) # 1 missing
## [1] 1
table(data_wide$TotalSleepTimeMinutes_diff)
##
## -92.5 0 0.5 1 2 2.5 3.5 5 5.5 24 30.5
## 1 45 1 1 1 1 1 1 1 1 1
nrow(data_wide[data_wide$TotalSleepTimeMinutes_diff < 0 & !is.na(data_wide$TotalSleepTimeMinutes_diff), ]) # 1 case where total sleep time minutes is lower in automated vs. cleaned (1/55 = 1.8%)
## [1] 1
nrow(data_wide[data_wide$TotalSleepTimeMinutes_diff == 0 & !is.na(data_wide$TotalSleepTimeMinutes_diff), ]) # 45 cases where they are identical (45/55 = 82%)
## [1] 45
length(unique(data_wide$ID[data_wide$TotalSleepTimeMinutes_diff == 0 & !is.na(data_wide$TotalSleepTimeMinutes_diff)])) # 8 participants where this is the case
## [1] 8
nrow(data_wide[data_wide$TotalSleepTimeMinutes_diff > 0 & !is.na(data_wide$TotalSleepTimeMinutes_diff), ]) # 9 cases where total sleep time minutes is greater in automated vs. cleaned (9/55 = 16.4%)
## [1] 9
length(unique(data_wide$ID[data_wide$TotalSleepTimeMinutes_diff > 0 & !is.na(data_wide$TotalSleepTimeMinutes_diff)])) # 5 participants where this is the case
## [1] 5
# Differences in TotalAwakeTimeMinutes by Method; range from -80 minutes to 99 minutes
nrow(data_wide[is.na(data_wide$TotalAwakeTimeMinutes_diff), ]) # 1 missing
## [1] 1
table(data_wide$TotalAwakeTimeMinutes_diff)
##
## -80 0 1 3.5000000000001
## 1 45 1 1
## 6.5 8 8.5 16
## 2 1 1 1
## 17.5 98.9999999999999
## 1 1
nrow(data_wide[data_wide$TotalAwakeTimeMinutes_diff < 0 & !is.na(data_wide$TotalAwakeTimeMinutes_diff), ]) # 1 case where total awake minutes is lower in automated vs. cleaned (8/55 = 15%)
## [1] 1
nrow(data_wide[data_wide$TotalAwakeTimeMinutes_diff == 0 & !is.na(data_wide$TotalAwakeTimeMinutes_diff), ]) # 45 cases where they are identical (45/55 = 82%)
## [1] 45
nrow(data_wide[data_wide$TotalAwakeTimeMinutes_diff > 0 & !is.na(data_wide$TotalAwakeTimeMinutes_diff), ]) # 9 cases where total awake minutes is greater in automated vs. cleaned (9/55 = 16.4%)
## [1] 9
# Differences in SleepPercentage by Method; range from -16.1% to 11.5%
nrow(data_wide[is.na(data_wide$SleepPercentage_diff), ]) # 1 missing
## [1] 1
table(data_wide$SleepPercentage_diff)
##
## -0.16133301642178 -0.0306184296619409 -0.030386384976526
## 1 1 1
## -0.0151501061571121 -0.0145480464625131 -0.011739165818922
## 1 1 1
## -0.010983333333334 -0.00637906976744196 0
## 1 1 45
## 0.00448336886993606 0.115442095914742
## 1 1
nrow(data_wide[data_wide$SleepPercentage_diff < 0 & !is.na(data_wide$SleepPercentage_diff), ]) # 8 cases where sleep percentage is lower in automated vs. cleaned (8/55 = 15%)
## [1] 8
length(unique(data_wide$ID[data_wide$SleepPercentage_diff < 0 & !is.na(data_wide$SleepPercentage_diff)])) # 4 participants where this is the case
## [1] 4
nrow(data_wide[data_wide$SleepPercentage_diff == 0 & !is.na(data_wide$SleepPercentage_diff), ]) # 45 cases where they are identical (45/55 = 82%)
## [1] 45
length(unique(data_wide$ID[data_wide$SleepPercentage_diff == 0 & !is.na(data_wide$SleepPercentage_diff)])) # 8 participants where this is the case
## [1] 8
nrow(data_wide[data_wide$SleepPercentage_diff > 0 & !is.na(data_wide$SleepPercentage_diff), ]) # 2 cases where sleep percentage is greater in automated vs. cleaned (2/55 = 3.6%)
## [1] 2
length(unique(data_wide$ID[data_wide$SleepPercentage_diff > 0 & !is.na(data_wide$SleepPercentage_diff)])) # 2 participants where this is the case
## [1] 2
SleepOnsetTime
# Because of rounding it looks like the two below are exactly the same, but they differ by .003 (see the SleepOnsetTime specific means below)
mean(data_wide$SleepOnsetDateTime_cleaned[!is.na(data_wide$SleepOnsetDateTime_automated)]) # 45371.77
## [1] 45371.77
mean(data_wide$SleepOnsetDateTime_automated[!is.na(data_wide$SleepOnsetDateTime_automated)]) # 45371.77
## [1] 45371.77
0.8893044 - 0.8863733 # cleaned - automated = 0.0029311
## [1] 0.0029311
mean(data_wide$SleepOnsetTime_cleaned[!is.na(data_wide$SleepOnsetDateTime_automated)]) # 0.5869508
## [1] 0.5869508
mean(data_wide$SleepOnsetTime_automated[!is.na(data_wide$SleepOnsetDateTime_automated)]) # 0.584173
## [1] 0.584173
0.5869508 - 0.584173 # cleaned - automated = 0.0027778
## [1] 0.0027778
# Note: Because the DateTime variables are inflated (the integer portion is in the thousands, and in these data the true differences lie in the decimal places) we will use the Time variable instead. This should ONLY be done if there are no DATE differences and only TIME differences between methods. Let's double check:
describe(data_wide$SleepOnsetDate_diff)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 55 0 0 0 0 0 0 0 0 NaN NaN 0
# Using a t-test with wide data (but this doesn't account for nesting within individuals)
var.test(data_wide$SleepOnsetTime_cleaned, data_wide$SleepOnsetTime_automated, paired = TRUE) # variances equal
##
## F test to compare two variances
##
## data: data_wide$SleepOnsetTime_cleaned and data_wide$SleepOnsetTime_automated
## F = 0.99674, num df = 55, denom df = 54, p-value = 0.9898
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.5824393 1.7034718
## sample estimates:
## ratio of variances
## 0.9967418
t.test(data_wide$SleepOnsetTime_cleaned, data_wide$SleepOnsetTime_automated, var.equal = TRUE, paired = TRUE)
##
## Paired t-test
##
## data: data_wide$SleepOnsetTime_cleaned and data_wide$SleepOnsetTime_automated
## t = 1.7204, df = 54, p-value = 0.09108
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.0004592461 0.0060148017
## sample estimates:
## mean difference
## 0.002777778
# Is nesting within ID necessary? Yes.
# Unconditional means model: Average level SleepOnsetTime nested within ID; ICC = .52
onset0 <- lmer(SleepOnsetTime ~ 1 + (1|ID), data = data)
summ(onset0)
## MODEL INFO:
## Observations: 111
## Dependent Variable: SleepOnsetTime
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 87.76, BIC = 95.89
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.52
##
## FIXED EFFECTS:
## ------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- ------ ------ -------- ------ ------
## (Intercept) 0.59 0.12 4.95 7.00 0.00
## ------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## ID (Intercept) 0.33
## Residual 0.31
## ------------------------------------
##
## Grouping variables:
## -------------------------
## Group # groups ICC
## ------- ---------- ------
## ID 8 0.52
## -------------------------
# Is nesting within Day also necessary? Yes.
# Unconditional means model: Average level SleepOnsetTime nested within unique Day; ID ICC = .48, Dayb ICC = .52
onset1 <- lmer(SleepOnsetTime ~ 1 + (1|ID/Dayb), data = data)
summ(onset1)
## MODEL INFO:
## Observations: 111
## Dependent Variable: SleepOnsetTime
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = -269.91, BIC = -259.07
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 1.00
##
## FIXED EFFECTS:
## ------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- ------ ------ -------- ------ ------
## (Intercept) 0.59 0.12 4.95 7.00 0.00
## ------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 0.33
## ID (Intercept) 0.32
## Residual 0.01
## ------------------------------------
##
## Grouping variables:
## ---------------------------
## Group # groups ICC
## --------- ---------- ------
## Dayb:ID 56 0.52
## ID 8 0.48
## ---------------------------
# We will continue with both ID and Dayb as our grouping variables
onset2 <- lmer(SleepOnsetTime ~ Method + (1|ID/Dayb), data = data)
summ(onset2, digits = 4)
## MODEL INFO:
## Observations: 111
## Dependent Variable: SleepOnsetTime
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = -259.8131, BIC = -246.2654
## Pseudo-R² (fixed effects) = 0.0000
## Pseudo-R² (total) = 0.9997
##
## FIXED EFFECTS:
## -----------------------------------------------------------------
## Est. S.E. t val. d.f. p
## ------------------- -------- -------- -------- --------- --------
## (Intercept) 0.5902 0.1196 4.9361 7.0016 0.0017
## Methodcleaned 0.0028 0.0016 1.7207 54.0012 0.0910
## -----------------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 0.3256
## ID (Intercept) 0.3150
## Residual 0.0085
## ------------------------------------
##
## Grouping variables:
## -----------------------------
## Group # groups ICC
## --------- ---------- --------
## Dayb:ID 56 0.5164
## ID 8 0.4833
## -----------------------------
# Estimate for method is: .0028
.0028 * 86400 # = 241.92 seconds
## [1] 241.92
WakeTime
mean(data_wide$WakeDateTime_cleaned[!is.na(data_wide$WakeDateTime_automated)]) # 45372.1
## [1] 45372.1
mean(data_wide$WakeDateTime_automated[!is.na(data_wide$WakeDateTime_automated)]) # 45372.09
## [1] 45372.09
45372.1 - 45372.09 # cleaned - automated = 0.01
## [1] 0.01
mean(data_wide$WakeTime_cleaned[!is.na(data_wide$WakeDateTime_automated)]) # 0.3144697
## [1] 0.3144697
mean(data_wide$WakeTime_automated[!is.na(data_wide$WakeDateTime_automated)]) # 0.3125568
## [1] 0.3125568
0.3144697 - 0.3125568 # cleaned - automated = 0.0019129
## [1] 0.0019129
# Note: Because the DateTime variables are inflated (the integer portion is in the thousands, and in these data the true differences lie in the decimal places) we will use the Time variable instead. This should ONLY be done if there are no DATE differences and only TIME differences between methods. Let's double check:
describe(data_wide$WakeDate_diff)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 55 0 0 0 0 0 0 0 0 NaN NaN 0
# Using a t-test with wide data (but this doesn't account for nesting within individuals)
var.test(data_wide$WakeTime_cleaned, data_wide$WakeTime_automated, paired = TRUE) # variances equal
##
## F test to compare two variances
##
## data: data_wide$WakeTime_cleaned and data_wide$WakeTime_automated
## F = 0.99611, num df = 55, denom df = 54, p-value = 0.9879
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.5820685 1.7023874
## sample estimates:
## ratio of variances
## 0.9961073
t.test(data_wide$WakeTime_cleaned, data_wide$WakeTime_automated, var.equal = TRUE, paired = TRUE)
##
## Paired t-test
##
## data: data_wide$WakeTime_cleaned and data_wide$WakeTime_automated
## t = 0.86989, df = 54, p-value = 0.3882
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.002495810 0.006321567
## sample estimates:
## mean difference
## 0.001912879
# Is nesting within ID necessary? Yes.
# Unconditional means model: Average level WakeTime nested within ID; ICC = .71
wake0 <- lmer(WakeTime ~ 1 + (1|ID), data = data)
summ(wake0)
## MODEL INFO:
## Observations: 111
## Dependent Variable: WakeTime
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = -428.10, BIC = -419.97
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.71
##
## FIXED EFFECTS:
## ------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- ------ ------ -------- ------ ------
## (Intercept) 0.31 0.02 18.99 7.00 0.00
## ------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## ID (Intercept) 0.05
## Residual 0.03
## ------------------------------------
##
## Grouping variables:
## -------------------------
## Group # groups ICC
## ------- ---------- ------
## ID 8 0.71
## -------------------------
# Is nesting within Day also necessary? Yes.
# Unconditional means model: Average level WakeTime nested within unique Day; ID ICC = .69, Dayb ICC = .26
wake1 <- lmer(WakeTime ~ 1 + (1|ID/Dayb), data = data)
summ(wake1)
## MODEL INFO:
## Observations: 111
## Dependent Variable: WakeTime
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = -497.09, BIC = -486.25
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.96
##
## FIXED EFFECTS:
## ------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- ------ ------ -------- ------ ------
## (Intercept) 0.31 0.02 18.91 7.00 0.00
## ------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 0.03
## ID (Intercept) 0.05
## Residual 0.01
## ------------------------------------
##
## Grouping variables:
## ---------------------------
## Group # groups ICC
## --------- ---------- ------
## Dayb:ID 56 0.26
## ID 8 0.69
## ---------------------------
# We will continue with both ID and Dayb as our grouping variables
wake2 <- lmer(WakeTime ~ Method + (1|ID/Dayb), data = data)
summ(wake2, digits = 4)
## MODEL INFO:
## Observations: 111
## Dependent Variable: WakeTime
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = -485.3966, BIC = -471.8490
## Pseudo-R² (fixed effects) = 0.0003
## Pseudo-R² (total) = 0.9555
##
## FIXED EFFECTS:
## ------------------------------------------------------------------
## Est. S.E. t val. d.f. p
## ------------------- -------- -------- --------- --------- --------
## (Intercept) 0.3114 0.0166 18.8020 7.0639 0.0000
## Methodcleaned 0.0019 0.0022 0.8441 54.1660 0.4023
## ------------------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 0.0281
## ID (Intercept) 0.0454
## Residual 0.0115
## ------------------------------------
##
## Grouping variables:
## -----------------------------
## Group # groups ICC
## --------- ---------- --------
## Dayb:ID 56 0.2647
## ID 8 0.6908
## -----------------------------
# Estimate for method is: 0.0019
0.0019 * 86400 # = 164.16 seconds
## [1] 164.16
TotalSleepTimeMinutes
mean(data_wide$TotalSleepTimeMinutes_cleaned[!is.na(data_wide$TotalSleepTimeMinutes_automated)]) # 419.1727
## [1] 419.1727
mean(data_wide$TotalSleepTimeMinutes_automated[!is.na(data_wide$TotalSleepTimeMinutes_automated)]) # 418.8455
## [1] 418.8455
419.1727 - 418.8455 # cleaned - automated = 0.3272
## [1] 0.3272
# Using a t-test with wide data (but this doesn't account for nesting within individuals)
var.test(data_wide$TotalSleepTimeMinutes_cleaned, data_wide$TotalSleepTimeMinutes_automated, paired = TRUE) # variances equal
##
## F test to compare two variances
##
## data: data_wide$TotalSleepTimeMinutes_cleaned and data_wide$TotalSleepTimeMinutes_automated
## F = 0.85914, num df = 55, denom df = 54, p-value = 0.5765
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.5020335 1.4683073
## sample estimates:
## ratio of variances
## 0.8591415
t.test(data_wide$TotalSleepTimeMinutes_cleaned, data_wide$TotalSleepTimeMinutes_automated, var.equal = TRUE, paired = TRUE)
##
## Paired t-test
##
## data: data_wide$TotalSleepTimeMinutes_cleaned and data_wide$TotalSleepTimeMinutes_automated
## t = 0.17716, df = 54, p-value = 0.86
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -3.376420 4.030965
## sample estimates:
## mean difference
## 0.3272727
# Is nesting within ID necessary? No, ICC is very low.
# Unconditional means model: Average level TotalSleepTimeMinutes nested within ID; ICC = .06
sleepmin0 <- lmer(TotalSleepTimeMinutes ~ 1 + (1|ID), data = data)
summ(sleepmin0)
## MODEL INFO:
## Observations: 111
## Dependent Variable: TotalSleepTimeMinutes
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 1216.45, BIC = 1224.58
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.06
##
## FIXED EFFECTS:
## --------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- -------- ------ -------- ------ ------
## (Intercept) 419.32 7.41 56.62 7.04 0.00
## --------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## ID (Intercept) 14.33
## Residual 56.92
## ------------------------------------
##
## Grouping variables:
## -------------------------
## Group # groups ICC
## ------- ---------- ------
## ID 8 0.06
## -------------------------
# Is nesting within Day necessary? Yes.
# Unconditional means model: Average level TotalSleepTimeMinutes nested within unique Day; ICC = .97
sleepmin1 <- lmer(TotalSleepTimeMinutes ~ 1 + (1|Dayb), data = data)
summ(sleepmin1)
## MODEL INFO:
## Observations: 111
## Dependent Variable: TotalSleepTimeMinutes
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 1056.10, BIC = 1064.23
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.97
##
## FIXED EFFECTS:
## ---------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- -------- ------ -------- ------- ------
## (Intercept) 419.52 7.77 53.97 55.02 0.00
## ---------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb (Intercept) 57.77
## Residual 9.60
## ------------------------------------
##
## Grouping variables:
## -------------------------
## Group # groups ICC
## ------- ---------- ------
## Dayb 56 0.97
## -------------------------
# We will continue with Dayb as our grouping variable
sleepmin2 <- lmer(TotalSleepTimeMinutes ~ Method + (1|Dayb), data = data)
summ(sleepmin2)
## MODEL INFO:
## Observations: 111
## Dependent Variable: TotalSleepTimeMinutes
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 1055.01, BIC = 1065.84
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.97
##
## FIXED EFFECTS:
## -----------------------------------------------------------
## Est. S.E. t val. d.f. p
## ------------------- -------- ------ -------- ------- ------
## (Intercept) 419.35 7.83 53.56 56.63 0.00
## Methodcleaned 0.34 1.85 0.18 54.05 0.85
## -----------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb (Intercept) 57.76
## Residual 9.69
## ------------------------------------
##
## Grouping variables:
## -------------------------
## Group # groups ICC
## ------- ---------- ------
## Dayb 56 0.97
## -------------------------
TotalAwakeTimeMinutes
mean(data_wide$TotalAwakeTimeMinutes_cleaned[!is.na(data_wide$TotalAwakeTimeMinutes_automated)]) # 52.45455
## [1] 52.45455
mean(data_wide$TotalAwakeTimeMinutes_automated[!is.na(data_wide$TotalAwakeTimeMinutes_automated)]) # 54.02727
## [1] 54.02727
52.45455 - 54.02727 # cleaned - automated = -1.57272
## [1] -1.57272
# Using a t-test with wide data (but this doesn't account for nesting within individuals)
var.test(data_wide$TotalAwakeTimeMinutes_cleaned, data_wide$TotalAwakeTimeMinutes_automated, paired = TRUE) # variances equal
##
## F test to compare two variances
##
## data: data_wide$TotalAwakeTimeMinutes_cleaned and data_wide$TotalAwakeTimeMinutes_automated
## F = 1.1629, num df = 55, denom df = 54, p-value = 0.58
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.6795544 1.9875063
## sample estimates:
## ratio of variances
## 1.162937
t.test(data_wide$TotalAwakeTimeMinutes_cleaned, data_wide$TotalAwakeTimeMinutes_automated, var.equal = TRUE, paired = TRUE)
##
## Paired t-test
##
## data: data_wide$TotalAwakeTimeMinutes_cleaned and data_wide$TotalAwakeTimeMinutes_automated
## t = -0.66007, df = 54, p-value = 0.512
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -6.349718 3.204263
## sample estimates:
## mean difference
## -1.572727
# Is nesting within ID necessary? Yes.
# Unconditional means model: Average level TotalAwakeTimeMinutes nested within ID; ICC = .34
awakemin0 <- lmer(TotalAwakeTimeMinutes ~ 1 + (1|ID), data = data)
summ(awakemin0)
## MODEL INFO:
## Observations: 111
## Dependent Variable: TotalAwakeTimeMinutes
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 941.23, BIC = 949.35
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.34
##
## FIXED EFFECTS:
## -------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- ------- ------ -------- ------ ------
## (Intercept) 52.92 4.22 12.54 7.02 0.00
## -------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## ID (Intercept) 11.18
## Residual 15.55
## ------------------------------------
##
## Grouping variables:
## -------------------------
## Group # groups ICC
## ------- ---------- ------
## ID 8 0.34
## -------------------------
# Is nesting within Day also necessary? Yes.
# Unconditional means model: Average level TotalAwakeTimeMinutes nested within unique Day; ID ICC = .32, Dayb ICC = .25
awakemin1 <- lmer(TotalAwakeTimeMinutes ~ 1 + (1|ID/Dayb), data = data)
summ(awakemin1)
## MODEL INFO:
## Observations: 111
## Dependent Variable: TotalAwakeTimeMinutes
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 936.09, BIC = 946.93
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.57
##
## FIXED EFFECTS:
## -------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- ------- ------ -------- ------ ------
## (Intercept) 52.81 4.22 12.50 7.01 0.00
## -------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 9.62
## ID (Intercept) 10.87
## Residual 12.55
## ------------------------------------
##
## Grouping variables:
## ---------------------------
## Group # groups ICC
## --------- ---------- ------
## Dayb:ID 56 0.25
## ID 8 0.32
## ---------------------------
# We will continue with both ID and Dayb as our grouping variables
awakemin2 <- lmer(TotalAwakeTimeMinutes ~ Method + (1|ID/Dayb), data = data)
summ(awakemin2)
## MODEL INFO:
## Observations: 111
## Dependent Variable: TotalAwakeTimeMinutes
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 933.86, BIC = 947.40
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.57
##
## FIXED EFFECTS:
## ----------------------------------------------------------
## Est. S.E. t val. d.f. p
## ------------------- ------- ------ -------- ------- ------
## (Intercept) 53.79 4.39 12.24 8.21 0.00
## Methodcleaned -1.94 2.40 -0.81 53.06 0.42
## ----------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 9.54
## ID (Intercept) 10.87
## Residual 12.61
## ------------------------------------
##
## Grouping variables:
## ---------------------------
## Group # groups ICC
## --------- ---------- ------
## Dayb:ID 56 0.25
## ID 8 0.32
## ---------------------------
SleepPercentage
mean(data_wide$SleepPercentage_cleaned[!is.na(data_wide$SleepPercentage_automated)]) # 0.8893044
## [1] 0.8893044
mean(data_wide$SleepPercentage_automated[!is.na(data_wide$SleepPercentage_automated)]) # 0.8863733
## [1] 0.8863733
0.8893044 - 0.8863733 # cleaned - automated = 0.0029311
## [1] 0.0029311
# Using a t-test with wide data (but this doesn't account for nesting within individuals)
var.test(data_wide$SleepPercentage_cleaned, data_wide$SleepPercentage_automated, paired = TRUE) # variances equal
##
## F test to compare two variances
##
## data: data_wide$SleepPercentage_cleaned and data_wide$SleepPercentage_automated
## F = 1.4938, num df = 55, denom df = 54, p-value = 0.1421
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.8728711 2.5529034
## sample estimates:
## ratio of variances
## 1.493764
t.test(data_wide$SleepPercentage_cleaned, data_wide$SleepPercentage_automated, var.equal = TRUE, paired = TRUE)
##
## Paired t-test
##
## data: data_wide$SleepPercentage_cleaned and data_wide$SleepPercentage_automated
## t = 0.78409, df = 54, p-value = 0.4364
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.004563576 0.010425834
## sample estimates:
## mean difference
## 0.002931129
# Is nesting within ID necessary? Yes.
# Unconditional means model: Average level SleepPercentage nested within ID; ICC = .45
perc0 <- lmer(SleepPercentage ~ 1 + (1|ID), data = data)
summ(perc0)
## MODEL INFO:
## Observations: 111
## Dependent Variable: SleepPercentage
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = -462.92, BIC = -454.79
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.45
##
## FIXED EFFECTS:
## ------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- ------ ------ -------- ------ ------
## (Intercept) 0.89 0.01 103.08 7.01 0.00
## ------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## ID (Intercept) 0.02
## Residual 0.03
## ------------------------------------
##
## Grouping variables:
## -------------------------
## Group # groups ICC
## ------- ---------- ------
## ID 8 0.45
## -------------------------
# Is nesting within Day also necessary? Yes.
# Unconditional means model: Average level SleepPercentage nested within unique Day; ID ICC = .43, Dayb ICC = .25
perc1 <- lmer(SleepPercentage ~ 1 + (1|ID/Dayb), data = data)
summ(perc1)
## MODEL INFO:
## Observations: 111
## Dependent Variable: SleepPercentage
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = -471.35, BIC = -460.51
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.68
##
## FIXED EFFECTS:
## ------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- ------ ------ -------- ------ ------
## (Intercept) 0.89 0.01 102.73 7.01 0.00
## ------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 0.02
## ID (Intercept) 0.02
## Residual 0.02
## ------------------------------------
##
## Grouping variables:
## ---------------------------
## Group # groups ICC
## --------- ---------- ------
## Dayb:ID 56 0.25
## ID 8 0.43
## ---------------------------
# We will continue with both ID and Dayb as our grouping variables
perc2 <- lmer(SleepPercentage ~ Method + (1|ID/Dayb), data = data)
summ(perc2, digits = 4)
## MODEL INFO:
## Observations: 111
## Dependent Variable: SleepPercentage
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = -460.9105, BIC = -447.3629
## Pseudo-R² (fixed effects) = 0.0026
## Pseudo-R² (total) = 0.6804
##
## FIXED EFFECTS:
## -------------------------------------------------------------------
## Est. S.E. t val. d.f. p
## ------------------- -------- -------- ---------- --------- --------
## (Intercept) 0.8870 0.0089 100.1406 7.7076 0.0000
## Methodcleaned 0.0036 0.0038 0.9423 52.4550 0.3504
## -------------------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 0.0176
## ID (Intercept) 0.0229
## Residual 0.0198
## ------------------------------------
##
## Grouping variables:
## -----------------------------
## Group # groups ICC
## --------- ---------- --------
## Dayb:ID 56 0.2515
## ID 8 0.4280
## -----------------------------
AverageRMSSD
mean(data_wide$AverageRMSSD_cleaned[!is.na(data_wide$AverageRMSSD_automated)]) # 37.28763
## [1] 37.28763
mean(data_wide$AverageRMSSD_automated[!is.na(data_wide$AverageRMSSD_automated)]) # 37.40878
## [1] 37.40878
37.28763 - 37.40878 # cleaned - automated = -0.12115
## [1] -0.12115
# Using a t-test with wide data (but this doesn't account for nesting within individuals)
var.test(data_wide$AverageRMSSD_cleaned, data_wide$AverageRMSSD_automated, paired = TRUE) # variances equal
##
## F test to compare two variances
##
## data: data_wide$AverageRMSSD_cleaned and data_wide$AverageRMSSD_automated
## F = 1.3826, num df = 55, denom df = 54, p-value = 0.2355
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.8078959 2.3628693
## sample estimates:
## ratio of variances
## 1.382571
t.test(data_wide$AverageRMSSD_cleaned, data_wide$AverageRMSSD_automated, var.equal = TRUE, paired = TRUE)
##
## Paired t-test
##
## data: data_wide$AverageRMSSD_cleaned and data_wide$AverageRMSSD_automated
## t = -0.36741, df = 54, p-value = 0.7148
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.7822910 0.5399771
## sample estimates:
## mean difference
## -0.121157
# Is nesting within ID necessary? Yes.
# Unconditional means model: Average level RMSSD nested within ID; ICC = .75
rmssd0 <- lmer(AverageRMSSD ~ 1 + (1|ID), data = data)
summ(rmssd0)
## MODEL INFO:
## Observations: 111
## Dependent Variable: AverageRMSSD
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 943.04, BIC = 951.17
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.75
##
## FIXED EFFECTS:
## -------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- ------- ------ -------- ------ ------
## (Intercept) 39.00 9.31 4.19 6.99 0.00
## -------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## ID (Intercept) 26.03
## Residual 14.86
## ------------------------------------
##
## Grouping variables:
## -------------------------
## Group # groups ICC
## ------- ---------- ------
## ID 8 0.75
## -------------------------
# Is nesting within Day also necessary? Yes.
# Unconditional means model: Average level RMSSD nested within unique Day; ID ICC = .73, Dayb ICC = .27
rmssd1 <- lmer(AverageRMSSD ~ 1 + (1|ID/Dayb), data = data)
summ(rmssd1)
## MODEL INFO:
## Observations: 111
## Dependent Variable: AverageRMSSD
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 751.85, BIC = 762.69
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 1.00
##
## FIXED EFFECTS:
## -------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- ------- ------ -------- ------ ------
## (Intercept) 39.59 9.85 4.02 7.00 0.01
## -------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 16.59
## ID (Intercept) 27.13
## Residual 1.72
## ------------------------------------
##
## Grouping variables:
## ---------------------------
## Group # groups ICC
## --------- ---------- ------
## Dayb:ID 56 0.27
## ID 8 0.73
## ---------------------------
# We will continue with both ID and Dayb as our grouping variables
rmssd2 <- lmer(AverageRMSSD ~ Method + (1|ID/Dayb), data = data)
summ(rmssd2, digits = 4)
## MODEL INFO:
## Observations: 111
## Dependent Variable: AverageRMSSD
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 754.1275, BIC = 767.6752
## Pseudo-R² (fixed effects) = 0.0000
## Pseudo-R² (total) = 0.9970
##
## FIXED EFFECTS:
## -------------------------------------------------------------------
## Est. S.E. t val. d.f. p
## ------------------- --------- -------- --------- --------- --------
## (Intercept) 39.6485 9.8482 4.0260 7.0035 0.0050
## Methodcleaned -0.1085 0.3300 -0.3289 53.8544 0.7435
## -------------------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 16.5897
## ID (Intercept) 27.1318
## Residual 1.7305
## ------------------------------------
##
## Grouping variables:
## -----------------------------
## Group # groups ICC
## --------- ---------- --------
## Dayb:ID 56 0.2713
## ID 8 0.7257
## -----------------------------
AverageHF
mean(data_wide$AverageHF_cleaned[!is.na(data_wide$AverageHF_automated)]) # 624.8729
## [1] 624.8729
mean(data_wide$AverageHF_automated[!is.na(data_wide$AverageHF_automated)]) # 635.1769
## [1] 635.1769
624.8729 - 635.1769 # cleaned - automated = -10.304
## [1] -10.304
# Using a t-test with wide data (but this doesn't account for nesting within individuals)
var.test(data_wide$AverageHF_cleaned, data_wide$AverageHF_automated, paired = TRUE) # variances equal
##
## F test to compare two variances
##
## data: data_wide$AverageHF_cleaned and data_wide$AverageHF_automated
## F = 1.3678, num df = 55, denom df = 54, p-value = 0.2514
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.7992527 2.3375901
## sample estimates:
## ratio of variances
## 1.36778
t.test(data_wide$AverageHF_cleaned, data_wide$AverageHF_automated, var.equal = TRUE, paired = TRUE)
##
## Paired t-test
##
## data: data_wide$AverageHF_cleaned and data_wide$AverageHF_automated
## t = -0.78182, df = 54, p-value = 0.4377
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -36.72719 16.11925
## sample estimates:
## mean difference
## -10.30397
# Is nesting within ID necessary? Yes.
# Unconditional means model: Average level AverageHF nested within ID; ICC = .69
hf0 <- lmer(AverageHF ~ 1 + (1|ID), data = data)
summ(hf0)
## MODEL INFO:
## Observations: 111
## Dependent Variable: AverageHF
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 1811.60, BIC = 1819.73
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.69
##
## FIXED EFFECTS:
## ----------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- -------- -------- -------- ------ ------
## (Intercept) 706.89 413.90 1.71 6.98 0.13
## ----------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## ID (Intercept) 1151.87
## Residual 778.44
## ------------------------------------
##
## Grouping variables:
## -------------------------
## Group # groups ICC
## ------- ---------- ------
## ID 8 0.69
## -------------------------
# Is nesting within Day also necessary? Yes.
# Unconditional means model: Average level AverageHF nested within unique Day; ID ICC = .66, Dayb ICC = .33
hf1 <- lmer(AverageHF ~ 1 + (1|ID/Dayb), data = data)
summ(hf1)
## MODEL INFO:
## Observations: 111
## Dependent Variable: AverageHF
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 1588.88, BIC = 1599.72
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 1.00
##
## FIXED EFFECTS:
## ----------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- -------- -------- -------- ------ ------
## (Intercept) 732.82 439.37 1.67 7.00 0.14
## ----------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 849.27
## ID (Intercept) 1200.40
## Residual 68.89
## ------------------------------------
##
## Grouping variables:
## ---------------------------
## Group # groups ICC
## --------- ---------- ------
## Dayb:ID 56 0.33
## ID 8 0.66
## ---------------------------
# We will continue with both ID and Dayb as our grouping variables
hf2 <- lmer(AverageHF ~ Method + (1|ID/Dayb), data = data)
summ(hf2, digits = 4)
## MODEL INFO:
## Observations: 111
## Dependent Variable: AverageHF
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 1583.3173, BIC = 1596.8649
## Pseudo-R² (fixed effects) = 0.0000
## Pseudo-R² (total) = 0.9978
##
## FIXED EFFECTS:
## ----------------------------------------------------------------------
## Est. S.E. t val. d.f. p
## ------------------- ---------- ---------- --------- --------- --------
## (Intercept) 737.8890 439.5015 1.6789 7.0032 0.1370
## Methodcleaned -9.9651 13.1833 -0.7559 53.9374 0.4530
## ----------------------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 849.5704
## ID (Intercept) 1200.6143
## Residual 69.1356
## ------------------------------------
##
## Grouping variables:
## -----------------------------
## Group # groups ICC
## --------- ---------- --------
## Dayb:ID 56 0.3329
## ID 8 0.6649
## -----------------------------
AverageLF
mean(data_wide$AverageLF_cleaned[!is.na(data_wide$AverageLF_automated)]) # 1269.789
## [1] 1269.789
mean(data_wide$AverageLF_automated[!is.na(data_wide$AverageLF_automated)]) # 1267.474
## [1] 1267.474
1269.789 - 1267.474 # cleaned - automated = 2.315
## [1] 2.315
# Using a t-test with wide data (but this doesn't account for nesting within individuals)
var.test(data_wide$AverageLF_cleaned, data_wide$AverageLF_automated, paired = TRUE) # variances equal
##
## F test to compare two variances
##
## data: data_wide$AverageLF_cleaned and data_wide$AverageLF_automated
## F = 1.2404, num df = 55, denom df = 54, p-value = 0.4297
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.7248191 2.1198928
## sample estimates:
## ratio of variances
## 1.2404
t.test(data_wide$AverageLF_cleaned, data_wide$AverageLF_automated, var.equal = TRUE, paired = TRUE)
##
## Paired t-test
##
## data: data_wide$AverageLF_cleaned and data_wide$AverageLF_automated
## t = 0.22919, df = 54, p-value = 0.8196
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -17.93316 22.56237
## sample estimates:
## mean difference
## 2.314607
# Is nesting within ID necessary? Yes.
# Unconditional means model: Average level AverageLF nested within ID; ICC = .73
lf0 <- lmer(AverageLF ~ 1 + (1|ID), data = data)
summ(lf0)
## MODEL INFO:
## Observations: 111
## Dependent Variable: AverageLF
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 1750.56, BIC = 1758.69
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 0.73
##
## FIXED EFFECTS:
## -----------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- --------- -------- -------- ------ ------
## (Intercept) 1319.41 347.13 3.80 6.99 0.01
## -----------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## ID (Intercept) 969.16
## Residual 585.77
## ------------------------------------
##
## Grouping variables:
## -------------------------
## Group # groups ICC
## ------- ---------- ------
## ID 8 0.73
## -------------------------
# Is nesting within Day also necessary? Yes.
# Unconditional means model: Average level AverageLF nested within unique Day; ID ICC = .71, Dayb ICC = .29
lf1 <- lmer(AverageLF ~ 1 + (1|ID/Dayb), data = data)
summ(lf1)
## MODEL INFO:
## Observations: 111
## Dependent Variable: AverageLF
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 1529.13, BIC = 1539.97
## Pseudo-R² (fixed effects) = 0.00
## Pseudo-R² (total) = 1.00
##
## FIXED EFFECTS:
## -----------------------------------------------------------
## Est. S.E. t val. d.f. p
## ----------------- --------- -------- -------- ------ ------
## (Intercept) 1338.94 361.26 3.71 7.00 0.01
## -----------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 639.93
## ID (Intercept) 992.67
## Residual 52.52
## ------------------------------------
##
## Grouping variables:
## ---------------------------
## Group # groups ICC
## --------- ---------- ------
## Dayb:ID 56 0.29
## ID 8 0.71
## ---------------------------
# We will continue with both ID and Dayb as our grouping variables
lf2 <- lmer(AverageLF ~ Method + (1|ID/Dayb), data = data)
summ(lf2, digits = 4)
## MODEL INFO:
## Observations: 111
## Dependent Variable: AverageLF
## Type: Mixed effects linear regression
##
## MODEL FIT:
## AIC = 1524.6101, BIC = 1538.1578
## Pseudo-R² (fixed effects) = 0.0000
## Pseudo-R² (total) = 0.9980
##
## FIXED EFFECTS:
## ----------------------------------------------------------------------
## Est. S.E. t val. d.f. p
## ------------------- ----------- ---------- -------- --------- --------
## (Intercept) 1337.6295 361.2837 3.7024 7.0028 0.0076
## Methodcleaned 2.5753 10.1022 0.2549 53.9373 0.7997
## ----------------------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## Dayb:ID (Intercept) 639.8219
## ID (Intercept) 992.6278
## Residual 52.9777
## ------------------------------------
##
## Grouping variables:
## -----------------------------
## Group # groups ICC
## --------- ---------- --------
## Dayb:ID 56 0.2929
## ID 8 0.7051
## -----------------------------
Violin plots
graph_data <- data
# converting times to 24-hour scale for graphing; adding 24 hours to the rows where sleep onset occurred after 12am (so look wonky in the graph)
graph_data <- data %>%
mutate(SleepOnsetTime_converted = SleepOnsetTime * 24,
SleepOnsetTime_converted = ifelse(SleepOnsetTime_converted > 0 & SleepOnsetTime_converted < 5, SleepOnsetTime_converted + 24, SleepOnsetTime_converted),
WakeTime_converted = WakeTime * 24)
a <- ggplot(graph_data, aes(y=SleepOnsetTime_converted, fill=Method)) +
geom_boxplot(notch=TRUE) +
ylab("Sleep Onset Time") +
theme_classic() +
scale_x_discrete() +
scale_y_continuous(breaks = seq(20, 30, by = 2), labels = c("8pm", "10pm", "12am", "2am", "4am", "6am")) +
theme(legend.position = "none") +
scale_fill_manual(name=NULL,
values=c("grey", "white"),
labels=c("Automated","Cleaned"))
b <- ggplot(graph_data, aes(y=WakeTime_converted, fill=Method)) +
geom_boxplot(notch=TRUE) +
ylab("Wake Time") +
theme_classic() +
scale_x_discrete() +
scale_y_continuous(breaks = seq(5, 10, by = 1), labels = c("5am", "6am", "7am", "8am", "9am", "10am")) +
scale_fill_manual(name=NULL,
values=c("grey", "white"),
labels=c("Automated","Cleaned"))
c <- ggplot(data, aes(y=TotalSleepTimeMinutes, fill=Method)) +
geom_boxplot(notch=TRUE) +
ylab("Total Sleep Minutes") +
theme_classic() +
scale_x_discrete() +
theme(legend.position = "none") +
scale_fill_manual(name=NULL,
values=c("grey", "white"),
labels=c("Automated","Cleaned"))
d <- ggplot(data, aes(y=TotalAwakeTimeMinutes, fill=Method)) +
geom_boxplot(notch=TRUE) +
ylab("Total Awake Minutes") +
theme_classic() +
scale_x_discrete() +
theme(legend.position = "none") +
scale_fill_manual(name=NULL,
values=c("grey", "white"),
labels=c("Automated","Cleaned"))
e <- ggplot(data, aes(y=TotalSleepTimeMinutes, fill=Method)) +
geom_boxplot(notch=TRUE) +
ylab("Sleep Percentage") +
theme_classic() +
scale_x_discrete() +
scale_fill_manual(name=NULL,
values=c("grey", "white"),
labels=c("Automated","Cleaned"))
library(patchwork)
combined_plot <- (a | b)
combined_plot2 <- (c | d | e)
combined_plot
## Warning: Removed 1 row containing non-finite outside the scale range (`stat_boxplot()`).
## Removed 1 row containing non-finite outside the scale range (`stat_boxplot()`).

combined_plot2
## Warning: Removed 1 row containing non-finite outside the scale range (`stat_boxplot()`).
## Removed 1 row containing non-finite outside the scale range (`stat_boxplot()`).
## Removed 1 row containing non-finite outside the scale range (`stat_boxplot()`).
