1 Setup, Data, Packages

if (Sys.info()[["user"]] == "jwile") {
  loc.data <- "g:/My Drive/CBTI+Light project/Recruitment and data collection/"
} else {
  loc.data <- "/Volumes/GoogleDrive/My Drive/CBTI+Light project/Recruitment and data collection/"
}

## graphics packages
library(ggplot2)
library(ggpubr)

## tools and miscellaneous packages
library(JWileymisc)
## Registered S3 methods overwritten by 'lme4':
##   method                          from
##   cooks.distance.influence.merMod car 
##   influence.merMod                car 
##   dfbeta.influence.merMod         car 
##   dfbetas.influence.merMod        car
## data related packages
library(reshape2)
library(data.table)
## 
## Attaching package: 'data.table'
## The following objects are masked from 'package:reshape2':
## 
##     dcast, melt
## modelling packages
library(MplusAutomation)
## Version:  0.8
## We work hard to write this free software. Please help us get credit by citing: 
## 
## Hallquist, M. N. & Wiley, J. F. (2018). MplusAutomation: An R Package for Facilitating Large-Scale Latent Variable Analyses in Mplus. Structural Equation Modeling, 25, 621-638. doi: 10.1080/10705511.2017.1402334.
## 
## -- see citation("MplusAutomation").
## 
## Attaching package: 'MplusAutomation'
## The following object is masked from 'package:JWileymisc':
## 
##     cd
theme_set(theme_pubr())
Sys.setenv(TZ = "Australia/Melbourne")

SEtrans <- function(x) {
  (10 - sqrt(100 - x)) ^2
}
SEback <- function(x) {
  100 - ((10 - sqrt(x))^2)
}
square <- function(x) x^2


d.all <- readRDS(file.path(loc.data, "Data", "SleepWell_Surveys.RDS"))
d.sleep <- readRDS(file.path(loc.data, "Data", "SleepWell_Sleep.RDS"))

ds2 <- d.sleep[!is.na(Date)]
ds2 <- merge(ds2, d.all[!duplicated(ID), .(ID, condition, baseline_isi_high, baseline_stage_high)],
             by = "ID", all.x = TRUE)

## create stratification factors
ds2[, dcond := as.integer(condition == "CBT+")]
ds2[, dstrat1 := as.integer(baseline_isi_high == "ISI <= 7" & baseline_stage_high == "Stage <= 2")]
ds2[, dstrat2 := as.integer(baseline_isi_high == "ISI <= 7" & baseline_stage_high == "Stage >= 3")]
ds2[, dstrat3 := as.integer(baseline_isi_high == "ISI >= 8" & baseline_stage_high == "Stage <= 2")]
ds2[, dstrat4 := as.integer(baseline_isi_high == "ISI >= 8" & baseline_stage_high == "Stage >= 3")]

## time variable, weeks since Email1Date
ds2[, Time := as.integer(Date - Email1Date)/7, by = ID]

## covariates
ds2[, WKND := as.integer(weekdays(Date) %in% c("Saturday", "Sunday"))]
ds2[!is.na(DEXA), USEDEXA := as.integer(!DEXA %in% c("", "0"))]

## select only initially higher ISI at screening
## note that this means we cannot use dstrat1 or dstrat2
## as those only occur in women with low initial ISI levels
ds2 <- ds2[baseline_isi_high == "ISI >= 8"]


## transform sleep variables that are not normal / are skewed
ds2[, SEstrans := SEtrans(SEs)]
ds2[, SEactitrans := SEtrans(SEacti)]

ds2[, SOLstrans := as.numeric(winsorizor(sqrt(SOL), percentile = .005))]
ds2[, SOLactitrans := as.numeric(winsorizor(sqrt(SOLacti), percentile = .005))]

ds2[, WASOstrans := as.numeric(winsorizor(sqrt(WASO), percentile = .005))]
ds2[, WASOactitrans := as.numeric(winsorizor(sqrt(WASOacti), percentile = .005))]

## weighted.mean(c(1, 4, 2, 5), w = c(.3, .2, .25, .25))
## check that weight the differences relative to first by weights matches
## 1 + 3 * .2 + 1 * .25 + 4 * .25
mcsetup <- "
MODEL CONSTRAINT:
NEW(itau icbt idiff stau scbt sdiff);
  itau = mi + i3 * %0.4f;
  icbt = itau + i4;
  idiff = i4;
  stau = ms;
  scbt = ms + s1;
  sdiff = s1;
PLOT(tau cbt delta d);
LOOP(Time, 0, 6, 0.1428571);
tau = itau + stau * Time;
cbt = icbt + scbt * Time;
delta = cbt - tau;
d = delta / sqrt(vi + resvar);
resvar > .001;
vi > .001;
vs > .001;
"

## define geoms and styles and labels for
## the diary / acti sleep outcomes
dailysleepStyle <- list(
  geom_ribbon(colour = NA, alpha = .2),
  geom_line(size = 1),
  scale_x_continuous("week", breaks = -1:6, labels = c(
    "",
    "Intervention Start             ",
    paste0("Wk ", 1:5),
    "End")),
  theme(axis.title.x = element_blank()),
  color_palette("jco"),
  fill_palette("jco"),
  coord_cartesian(xlim = c(-.5, 6), expand = FALSE, clip = "off"),
  theme(plot.margin = margin(6, 12, 0, 20, "pt")))

2 Diary - Sleep Efficiency

sesdat <- na.omit(ds2[, .(ID, Time, dstrat4, dcond, SEstrans)])

sesfit <- mplusModeler(mplusObject(
  TITLE = "Self-Report SE Analysis;",
  VARIABLE = "
    WITHIN = Time;
    BETWEEN = dstrat4 dcond;
    CLUSTER = ID;",
  ANALYSIS = "
   ESTIMATOR = ML;
   TYPE = TWOLEVEL RANDOM;
   PROCESSORS = 2;
   STARTS = 50 5;
   STITERATIONS = 200;
   MITERATIONS = 10000;
   MCONVERGENCE  = .000001;
",
  MODEL = "
  %WITHIN%
  s | SEstrans ON Time;
  SEstrans* (resvar);
  %BETWEEN%
  SEstrans ON dstrat4 dcond (i3 - i4);
  s ON dcond (s1);
  SEstrans WITH s*;
  SEstrans* s* (vi vs);
  [SEstrans* s*] (mi ms);
",
OUTPUT = "CINTERVAL;",
PLOT = "TYPE = PLOT2;",
MODELCONSTRAINT = sprintf(
  mcsetup,
  mean(sesdat$dstrat4)),
usevariables = c("ID", "Time", "SEstrans",
                 "dstrat4", "dcond"),
rdata = as.data.frame(sesdat)),
dataout = "04_HighISI_ses.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 04_HighISI_ses.inp
## Wrote data to: 04_HighISI_ses.dat
## model information, coefficients, and effect sizes
sesout <- cbind(
  coef(sesfit, param = c("reg", "exp", "new")),
  round(confint(sesfit, param = c("reg", "exp", "new"))[,-1], 2))[, c(1, 2, 5, 6, 4)]
with(sesout,
     data.frame(
       Label = Label,
       Out = sprintf("%0.2f (%0.2f, %0.2f)", round(est, 2), LowerCI, UpperCI),
       pval = formatPval(pval, d = 3, sd = 3)))
##                     Label                  Out   pval
## 1              B S<-DCOND  -0.09 (-1.20, 1.02)   .873
## 2     B SESTRANS<-DSTRAT4  5.32 (-2.31, 12.95)   .171
## 3       B SESTRANS<-DCOND  6.00 (-1.71, 13.71)   .127
## 4  B SESTRANS<-Intercepts 38.32 (31.28, 45.37) < .001
## 5         B S<-Intercepts    1.46 (0.67, 2.24) < .001
## 6                  B ITAU 41.09 (35.28, 46.90) < .001
## 7                  B ICBT 47.09 (42.02, 52.16) < .001
## 8                 B IDIFF  6.00 (-1.71, 13.71)   .127
## 9                  B STAU    1.46 (0.67, 2.24) < .001
## 10                 B SCBT    1.36 (0.58, 2.15)   .001
## 11                B SDIFF  -0.09 (-1.20, 1.02)   .873
sesplot <- data.table(
  Condition = rep(c("TAU+", "CBT-I+Light"), each = 43),
  Time = c(sesfit$results$gh5$loop_data$xvalues, sesfit$results$gh5$loop_data$xvalues),
  Estimate = c(sesfit$results$gh5$loop_data$estimates[1, ], sesfit$results$gh5$loop_data$estimates[2, ]),
  LL = c(sesfit$results$gh5$loop_data$lowerci[1, ], sesfit$results$gh5$loop_data$lowerci[2, ]),
  UL = c(sesfit$results$gh5$loop_data$upperci[1, ], sesfit$results$gh5$loop_data$upperci[2, ]))

p.ses <- ggplot(sesplot, aes(Time, SEback(Estimate), ymin = SEback(LL), ymax = SEback(UL),
                             colour = Condition, fill = Condition)) +
  scale_y_continuous("SE (Diary)", breaks = 82:98) +
  annotate("text", x = 2, y = 93.5, label = sprintf("CBT-I+Light slope %s", formatPval(subset(sesout, Label == "B SCBT")$pval, d = 3, sd = 3, includeP = TRUE))) +
  annotate("text", x = 2, y = 87, label = sprintf("TAU+ slope %s", formatPval(subset(sesout, Label == "B STAU")$pval, d = 3, sd = 3, includeP = TRUE))) +
  dailysleepStyle
print(p.ses)

sesdiffplot <- with(sesfit$results$gh5$loop_data, data.table(
  Type = rep(c("Raw", "standardized"), each = 43),
  Time = round(c(xvalues, xvalues) * 7),
  Estimate = c(estimates[3, ], estimates[4, ]),
  LL = c(lowerci[3, ], lowerci[4, ]),
  UL = c(upperci[3, ], upperci[4, ])))

sesdiffplot[Type == "Raw"]
##     Type Time Estimate        LL       UL
##  1:  Raw    0 5.999818 -1.712006 13.71164
##  2:  Raw    1 5.986889 -1.715734 13.68951
##  3:  Raw    2 5.973960 -1.722720 13.67064
##  4:  Raw    3 5.961031 -1.732973 13.65504
##  5:  Raw    4 5.948102 -1.746496 13.64270
##  6:  Raw    5 5.935173 -1.763289 13.63363
##  7:  Raw    6 5.922244 -1.783345 13.62783
##  8:  Raw    7 5.909315 -1.806658 13.62529
##  9:  Raw    8 5.896386 -1.833212 13.62598
## 10:  Raw    9 5.883457 -1.862991 13.62991
## 11:  Raw   10 5.870528 -1.895975 13.63703
## 12:  Raw   11 5.857599 -1.932138 13.64734
## 13:  Raw   12 5.844670 -1.971452 13.66079
## 14:  Raw   13 5.831741 -2.013885 13.67737
## 15:  Raw   14 5.818812 -2.059403 13.69703
## 16:  Raw   15 5.805883 -2.107966 13.71973
## 17:  Raw   16 5.792954 -2.159535 13.74544
## 18:  Raw   17 5.780025 -2.214065 13.77412
## 19:  Raw   18 5.767097 -2.271511 13.80570
## 20:  Raw   19 5.754168 -2.331824 13.84016
## 21:  Raw   20 5.741239 -2.394955 13.87743
## 22:  Raw   21 5.728310 -2.460851 13.91747
## 23:  Raw   22 5.715381 -2.529459 13.96022
## 24:  Raw   23 5.702452 -2.600725 14.00563
## 25:  Raw   24 5.689523 -2.674593 14.05364
## 26:  Raw   25 5.676594 -2.751007 14.10419
## 27:  Raw   26 5.663665 -2.829909 14.15724
## 28:  Raw   27 5.650736 -2.911242 14.21271
## 29:  Raw   28 5.637807 -2.994949 14.27056
## 30:  Raw   29 5.624878 -3.080970 14.33073
## 31:  Raw   30 5.611949 -3.169250 14.39315
## 32:  Raw   31 5.599020 -3.259729 14.45777
## 33:  Raw   32 5.586091 -3.352350 14.52453
## 34:  Raw   33 5.573162 -3.447058 14.59338
## 35:  Raw   34 5.560233 -3.543795 14.66426
## 36:  Raw   35 5.547304 -3.642507 14.73711
## 37:  Raw   36 5.534375 -3.743137 14.81189
## 38:  Raw   37 5.521446 -3.845634 14.88853
## 39:  Raw   38 5.508517 -3.949942 14.96698
## 40:  Raw   39 5.495588 -4.056011 15.04719
## 41:  Raw   40 5.482659 -4.163790 15.12911
## 42:  Raw   41 5.469730 -4.273228 15.21269
## 43:  Raw   42 5.456801 -4.384277 15.29788
##     Type Time Estimate        LL       UL
sesdiffplot[Type == "standardized"]
##             Type Time  Estimate          LL        UL
##  1: standardized    0 0.2929659 -0.08537106 0.6713030
##  2: standardized    1 0.2923346 -0.08554134 0.6702107
##  3: standardized    2 0.2917033 -0.08587002 0.6692767
##  4: standardized    3 0.2910720 -0.08635750 0.6685016
##  5: standardized    4 0.2904407 -0.08700396 0.6678854
##  6: standardized    5 0.2898094 -0.08780938 0.6674282
##  7: standardized    6 0.2891781 -0.08877354 0.6671298
##  8: standardized    7 0.2885468 -0.08989602 0.6669896
##  9: standardized    8 0.2879155 -0.09117621 0.6670071
## 10: standardized    9 0.2872842 -0.09261329 0.6671816
## 11: standardized   10 0.2866529 -0.09420628 0.6675120
## 12: standardized   11 0.2860216 -0.09595399 0.6679971
## 13: standardized   12 0.2853902 -0.09785508 0.6686355
## 14: standardized   13 0.2847589 -0.09990801 0.6694259
## 15: standardized   14 0.2841276 -0.10211112 0.6703663
## 16: standardized   15 0.2834963 -0.10446259 0.6714552
## 17: standardized   16 0.2828650 -0.10696044 0.6726905
## 18: standardized   17 0.2822337 -0.10960259 0.6740699
## 19: standardized   18 0.2816024 -0.11238682 0.6755916
## 20: standardized   19 0.2809711 -0.11531082 0.6772529
## 21: standardized   20 0.2803398 -0.11837218 0.6790517
## 22: standardized   21 0.2797084 -0.12156840 0.6809853
## 23: standardized   22 0.2790771 -0.12489692 0.6830512
## 24: standardized   23 0.2784458 -0.12835510 0.6852468
## 25: standardized   24 0.2778145 -0.13194026 0.6875693
## 26: standardized   25 0.2771832 -0.13564968 0.6900161
## 27: standardized   26 0.2765519 -0.13948059 0.6925844
## 28: standardized   27 0.2759206 -0.14343022 0.6952714
## 29: standardized   28 0.2752893 -0.14749578 0.6980743
## 30: standardized   29 0.2746580 -0.15167443 0.7009904
## 31: standardized   30 0.2740267 -0.15596342 0.7040167
## 32: standardized   31 0.2733954 -0.16035993 0.7071506
## 33: standardized   32 0.2727641 -0.16486120 0.7103893
## 34: standardized   33 0.2721327 -0.16946447 0.7137299
## 35: standardized   34 0.2715014 -0.17416701 0.7171699
## 36: standardized   35 0.2708701 -0.17896612 0.7207063
## 37: standardized   36 0.2702388 -0.18385915 0.7243367
## 38: standardized   37 0.2696075 -0.18884347 0.7280585
## 39: standardized   38 0.2689762 -0.19391653 0.7318689
## 40: standardized   39 0.2683449 -0.19907577 0.7357655
## 41: standardized   40 0.2677136 -0.20431873 0.7397459
## 42: standardized   41 0.2670823 -0.20964296 0.7438075
## 43: standardized   42 0.2664509 -0.21504611 0.7479480
##             Type Time  Estimate          LL        UL

3 Diary - WASO

wasodat <- na.omit(ds2[, .(ID, Time, dstrat4, dcond, WASOstrans)])

wasofit <- mplusModeler(mplusObject(
  TITLE = "Self-Report WASO Analysis;",
  VARIABLE = "
    WITHIN = Time;
    BETWEEN = dstrat4 dcond;
    CLUSTER = ID;",
  ANALYSIS = "
   ESTIMATOR = ML;
   TYPE = TWOLEVEL RANDOM;
   PROCESSORS = 2;
   STARTS = 50 5;
   STITERATIONS = 200;
   MITERATIONS = 10000;
   MCONVERGENCE  = .000001;
",
  MODEL = "
  %WITHIN%
  s | WASOstrans ON Time;
  WASOstrans* (resvar);
  %BETWEEN%
  WASOstrans ON dstrat4 dcond (i3 - i4);
  s ON dcond (s1);
  WASOstrans WITH s*;
  WASOstrans* s* (vi vs);
  [WASOstrans* s*] (mi ms);
",
  OUTPUT = "CINTERVAL;",
  PLOT = "TYPE = PLOT2;",
  MODELCONSTRAINT = sprintf(
    mcsetup,
    mean(wasodat$dstrat4)),
  usevariables = c("ID", "Time", "WASOstrans",
                  "dstrat4", "dcond"),
  rdata = as.data.frame(wasodat)),
  dataout = "04_HighISI_waso.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 04_HighISI_waso.inp
## Wrote data to: 04_HighISI_waso.dat
## model information, coefficients, and effect sizes
wasoout <- cbind(
  coef(wasofit, param = c("reg", "exp", "new")),
  round(confint(wasofit, param = c("reg", "exp", "new"))[,-1], 2))[, c(1, 2, 5, 6, 4)]
with(wasoout,
     data.frame(
       Label = Label,
       Out = sprintf("%0.2f (%0.2f, %0.2f)", round(est, 2), LowerCI, UpperCI),
       pval = formatPval(pval, d = 3, sd = 3)))
##                       Label                  Out   pval
## 1                B S<-DCOND  -0.09 (-0.28, 0.11)   .380
## 2     B WASOSTRANS<-DSTRAT4 -1.49 (-2.94, -0.04)   .044
## 3       B WASOSTRANS<-DCOND  -0.26 (-1.73, 1.21)   .728
## 4  B WASOSTRANS<-Intercepts    6.51 (5.15, 7.86) < .001
## 5           B S<-Intercepts  -0.12 (-0.25, 0.02)   .096
## 6                    B ITAU    5.74 (4.63, 6.85) < .001
## 7                    B ICBT    5.48 (4.51, 6.44) < .001
## 8                   B IDIFF  -0.26 (-1.73, 1.21)   .728
## 9                    B STAU  -0.12 (-0.25, 0.02)   .096
## 10                   B SCBT -0.20 (-0.34, -0.06)   .004
## 11                  B SDIFF  -0.09 (-0.28, 0.11)   .380
wasoplot <- data.table(
  Condition = rep(c("TAU+", "CBT-I+Light"), each = 43),
  Time = c(wasofit$results$gh5$loop_data$xvalues, wasofit$results$gh5$loop_data$xvalues),
  Estimate = c(wasofit$results$gh5$loop_data$estimates[1, ], wasofit$results$gh5$loop_data$estimates[2, ]),
  LL = c(wasofit$results$gh5$loop_data$lowerci[1, ], wasofit$results$gh5$loop_data$lowerci[2, ]),
  UL = c(wasofit$results$gh5$loop_data$upperci[1, ], wasofit$results$gh5$loop_data$upperci[2, ]))

p.waso <- ggplot(wasoplot, aes(Time, Estimate^2, ymin = LL^2, ymax = UL^2,
                               colour = Condition, fill = Condition)) +
  scale_y_continuous("WASO (Diary)", breaks = seq(10,60,5)) +
  annotate("text", x = 2, y = 21, label = sprintf("CBT-I+Light slope %s", formatPval(subset(wasoout, Label == "B SCBT")$pval, d = 3, sd = 3, includeP = TRUE))) +
  annotate("text", x = 2, y = 35, label = sprintf("TAU+ slope %s", formatPval(subset(wasoout, Label == "B STAU")$pval, d = 3, sd = 3, includeP = TRUE))) +
  dailysleepStyle
print(p.waso)

wasodiffplot <- with(wasofit$results$gh5$loop_data, data.table(
  Type = rep(c("Raw", "standardized"), each = 43),
  Time = c(xvalues, xvalues),
  Estimate = c(estimates[3, ], estimates[4, ]),
  LL = c(lowerci[3, ], lowerci[4, ]),
  UL = c(upperci[3, ], upperci[4, ])))


wasodiffplot[Type == "Raw"]
##     Type      Time   Estimate        LL        UL
##  1:  Raw 0.0000000 -0.2610321 -1.731924 1.2098594
##  2:  Raw 0.1428571 -0.2732826 -1.739287 1.1927218
##  3:  Raw 0.2857142 -0.2855330 -1.747147 1.1760805
##  4:  Raw 0.4285713 -0.2977835 -1.755507 1.1599400
##  5:  Raw 0.5714284 -0.3100340 -1.764372 1.1443043
##  6:  Raw 0.7142855 -0.3222845 -1.773746 1.1291769
##  7:  Raw 0.8571426 -0.3345349 -1.783631 1.1145610
##  8:  Raw 0.9999998 -0.3467854 -1.794030 1.1004587
##  9:  Raw 1.1428568 -0.3590359 -1.804944 1.0868725
## 10:  Raw 1.2857139 -0.3712863 -1.816376 1.0738034
## 11:  Raw 1.4285710 -0.3835368 -1.828326 1.0612526
## 12:  Raw 1.5714282 -0.3957873 -1.840795 1.0492202
## 13:  Raw 1.7142853 -0.4080378 -1.853782 1.0377060
## 14:  Raw 1.8571423 -0.4202882 -1.867286 1.0267093
## 15:  Raw 1.9999995 -0.4325387 -1.881306 1.0162288
## 16:  Raw 2.1428566 -0.4447892 -1.895841 1.0062624
## 17:  Raw 2.2857137 -0.4570397 -1.910887 0.9968079
## 18:  Raw 2.4285707 -0.4692901 -1.926442 0.9878622
## 19:  Raw 2.5714278 -0.4815406 -1.942503 0.9794219
## 20:  Raw 2.7142849 -0.4937911 -1.959065 0.9714830
## 21:  Raw 2.8571420 -0.5060415 -1.976124 0.9640412
## 22:  Raw 2.9999993 -0.5182920 -1.993675 0.9570915
## 23:  Raw 3.1428564 -0.5305425 -2.011714 0.9506288
## 24:  Raw 3.2857134 -0.5427930 -2.030233 0.9446473
## 25:  Raw 3.4285705 -0.5550434 -2.049228 0.9391409
## 26:  Raw 3.5714276 -0.5672939 -2.068691 0.9341033
## 27:  Raw 3.7142847 -0.5795444 -2.088616 0.9295277
## 28:  Raw 3.8571417 -0.5917948 -2.108997 0.9254072
## 29:  Raw 3.9999990 -0.6040453 -2.129825 0.9217343
## 30:  Raw 4.1428561 -0.6162958 -2.151093 0.9185018
## 31:  Raw 4.2857132 -0.6285462 -2.172794 0.9157017
## 32:  Raw 4.4285703 -0.6407967 -2.194920 0.9133263
## 33:  Raw 4.5714273 -0.6530472 -2.217462 0.9113675
## 34:  Raw 4.7142844 -0.6652977 -2.240412 0.9098172
## 35:  Raw 4.8571415 -0.6775481 -2.263763 0.9086670
## 36:  Raw 4.9999986 -0.6897986 -2.287506 0.9079086
## 37:  Raw 5.1428556 -0.7020491 -2.311632 0.9075336
## 38:  Raw 5.2857127 -0.7142996 -2.336133 0.9075336
## 39:  Raw 5.4285698 -0.7265500 -2.361000 0.9079003
## 40:  Raw 5.5714269 -0.7388005 -2.386226 0.9086251
## 41:  Raw 5.7142839 -0.7510509 -2.411802 0.9096996
## 42:  Raw 5.8571415 -0.7633014 -2.437718 0.9111156
## 43:  Raw 5.9999986 -0.7755519 -2.463969 0.9128647
##     Type      Time   Estimate        LL        UL
wasodiffplot[Type == "standardized"]
##             Type      Time    Estimate         LL        UL
##  1: standardized 0.0000000 -0.06911339 -0.4589807 0.3207539
##  2: standardized 0.1428571 -0.07235694 -0.4609512 0.3162373
##  3: standardized 0.2857142 -0.07560050 -0.4630530 0.3118521
##  4: standardized 0.4285713 -0.07884405 -0.4652874 0.3075994
##  5: standardized 0.5714284 -0.08208760 -0.4676554 0.3034802
##  6: standardized 0.7142855 -0.08533116 -0.4701579 0.2994956
##  7: standardized 0.8571426 -0.08857471 -0.4727956 0.2956462
##  8: standardized 0.9999998 -0.09181826 -0.4755692 0.2919327
##  9: standardized 1.1428568 -0.09506182 -0.4784792 0.2883556
## 10: standardized 1.2857139 -0.09830537 -0.4815260 0.2849152
## 11: standardized 1.4285710 -0.10154893 -0.4847097 0.2816119
## 12: standardized 1.5714282 -0.10479248 -0.4880305 0.2784455
## 13: standardized 1.7142853 -0.10803603 -0.4914882 0.2754161
## 14: standardized 1.8571423 -0.11127958 -0.4950826 0.2725235
## 15: standardized 1.9999995 -0.11452314 -0.4988134 0.2697671
## 16: standardized 2.1428566 -0.11776669 -0.5026800 0.2671466
## 17: standardized 2.2857137 -0.12101024 -0.5066818 0.2646613
## 18: standardized 2.4285707 -0.12425379 -0.5108179 0.2623104
## 19: standardized 2.5714278 -0.12749735 -0.5150875 0.2600929
## 20: standardized 2.7142849 -0.13074091 -0.5194895 0.2580077
## 21: standardized 2.8571420 -0.13398446 -0.5240228 0.2560538
## 22: standardized 2.9999993 -0.13722801 -0.5286859 0.2542298
## 23: standardized 3.1428564 -0.14047156 -0.5334774 0.2525343
## 24: standardized 3.2857134 -0.14371511 -0.5383961 0.2509658
## 25: standardized 3.4285705 -0.14695868 -0.5434400 0.2495227
## 26: standardized 3.5714276 -0.15020223 -0.5486077 0.2482033
## 27: standardized 3.7142847 -0.15344578 -0.5538973 0.2470057
## 28: standardized 3.8571417 -0.15668933 -0.5593069 0.2459282
## 29: standardized 3.9999990 -0.15993288 -0.5648346 0.2449688
## 30: standardized 4.1428561 -0.16317643 -0.5704785 0.2441256
## 31: standardized 4.2857132 -0.16642000 -0.5762364 0.2433964
## 32: standardized 4.4285703 -0.16966355 -0.5821064 0.2427793
## 33: standardized 4.5714273 -0.17290710 -0.5880862 0.2422720
## 34: standardized 4.7142844 -0.17615065 -0.5941737 0.2418724
## 35: standardized 4.8571415 -0.17939420 -0.6003668 0.2415784
## 36: standardized 4.9999986 -0.18263777 -0.6066632 0.2413877
## 37: standardized 5.1428556 -0.18588132 -0.6130607 0.2412981
## 38: standardized 5.2857127 -0.18912487 -0.6195571 0.2413074
## 39: standardized 5.4285698 -0.19236842 -0.6261502 0.2414134
## 40: standardized 5.5714269 -0.19561197 -0.6328378 0.2416138
## 41: standardized 5.7142839 -0.19885553 -0.6396175 0.2419065
## 42: standardized 5.8571415 -0.20209908 -0.6464873 0.2422892
## 43: standardized 5.9999986 -0.20534264 -0.6534449 0.2427597
##             Type      Time    Estimate         LL        UL

4 Diary - SOL

soldat <- na.omit(ds2[, .(ID, Time, dstrat4, dcond, SOLstrans)])

solfit <- mplusModeler(mplusObject(
  TITLE = "Self-Report SOL Analysis;",
  VARIABLE = "
    WITHIN = Time;
    BETWEEN = dstrat4 dcond;
    CLUSTER = ID;",
  ANALYSIS = "
   ESTIMATOR = ML;
   TYPE = TWOLEVEL RANDOM;
   PROCESSORS = 2;
   STARTS = 50 5;
   STITERATIONS = 200;
   MITERATIONS = 10000;
   MCONVERGENCE  = .000001;
",
  MODEL = "
  %WITHIN%
  s | SOLstrans ON Time;
  SOLstrans* (resvar);
  %BETWEEN%
  SOLstrans ON dstrat4 dcond (i3 - i4);
  s ON dcond (s1);
  SOLstrans WITH s*;
  SOLstrans* s* (vi vs);
  [SOLstrans* s*] (mi ms);
",
  OUTPUT = "CINTERVAL;",
  PLOT = "TYPE = PLOT2;",
  MODELCONSTRAINT = sprintf(
    mcsetup,
    mean(soldat$dstrat4)),
  usevariables = c("ID", "Time", "SOLstrans",
                  "dstrat4", "dcond"),
  rdata = as.data.frame(soldat)),
  dataout = "04_HighISI_sol.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 04_HighISI_sol.inp
## Wrote data to: 04_HighISI_sol.dat
## model information, coefficients, and effect sizes
solout <- cbind(
  coef(solfit, param = c("reg", "exp", "new")),
  round(confint(solfit, param = c("reg", "exp", "new"))[,-1], 2))[, c(1, 2, 5, 6, 4)]
with(solout,
     data.frame(
       Label = Label,
       Out = sprintf("%0.2f (%0.2f, %0.2f)", round(est, 2), LowerCI, UpperCI),
       pval = formatPval(pval, d = 3, sd = 3)))
##                      Label                  Out   pval
## 1               B S<-DCOND  -0.04 (-0.21, 0.13)   .679
## 2     B SOLSTRANS<-DSTRAT4   0.21 (-0.72, 1.14)   .663
## 3       B SOLSTRANS<-DCOND   0.06 (-1.01, 1.13)   .916
## 4  B SOLSTRANS<-Intercepts    4.56 (3.62, 5.50) < .001
## 5          B S<-Intercepts  -0.10 (-0.22, 0.03)   .119
## 6                   B ITAU    4.67 (3.86, 5.47) < .001
## 7                   B ICBT    4.72 (4.02, 5.43) < .001
## 8                  B IDIFF   0.06 (-1.01, 1.13)   .916
## 9                   B STAU  -0.10 (-0.22, 0.03)   .119
## 10                  B SCBT -0.13 (-0.25, -0.01)   .027
## 11                 B SDIFF  -0.04 (-0.21, 0.13)   .679
solplot <- data.table(
  Condition = rep(c("TAU+", "CBT-I+Light"), each = 43),
  Time = c(solfit$results$gh5$loop_data$xvalues, solfit$results$gh5$loop_data$xvalues),
  Estimate = c(solfit$results$gh5$loop_data$estimates[1, ], solfit$results$gh5$loop_data$estimates[2, ]),
  LL = c(solfit$results$gh5$loop_data$lowerci[1, ], solfit$results$gh5$loop_data$lowerci[2, ]),
  UL = c(solfit$results$gh5$loop_data$upperci[1, ], solfit$results$gh5$loop_data$upperci[2, ]))

p.sol <- ggplot(solplot, aes(Time, Estimate^2, ymin = LL^2, ymax = UL^2,
                             colour = Condition, fill = Condition)) +
  scale_y_continuous("SOL (Diary)", breaks = seq(10,30,2)) +
  annotate("text", x = 2, y = 17, label = sprintf("CBT-I+Light slope %s", formatPval(subset(solout, Label == "B SCBT")$pval, d = 3, sd = 3, includeP = TRUE))) +
  annotate("text", x = 2, y = 23, label = sprintf("TAU+ slope %s", formatPval(subset(solout, Label == "B STAU")$pval, d = 3, sd = 3, includeP = TRUE))) +
  dailysleepStyle
print(p.sol)

soldiffplot <- with(solfit$results$gh5$loop_data, data.table(
  Type = rep(c("Raw", "standardized"), each = 43),
  Time = c(xvalues, xvalues),
  Estimate = c(estimates[3, ], estimates[4, ]),
  LL = c(lowerci[3, ], lowerci[4, ]),
  UL = c(upperci[3, ], upperci[4, ])))


soldiffplot[Type == "Raw"]
##     Type      Time     Estimate         LL        UL
##  1:  Raw 0.0000000  0.057891928 -1.0139680 1.1297518
##  2:  Raw 0.1428571  0.052776318 -1.0073042 1.1128567
##  3:  Raw 0.2857142  0.047660708 -1.0010697 1.0963911
##  4:  Raw 0.4285713  0.042545099 -0.9952784 1.0803686
##  5:  Raw 0.5714284  0.037429493 -0.9899448 1.0648037
##  6:  Raw 0.7142855  0.032313883 -0.9850827 1.0497104
##  7:  Raw 0.8571426  0.027198274 -0.9807062 1.0351027
##  8:  Raw 0.9999998  0.022082664 -0.9768291 1.0209944
##  9:  Raw 1.1428568  0.016967056 -0.9734650 1.0073992
## 10:  Raw 1.2857139  0.011851447 -0.9706273 0.9943302
## 11:  Raw 1.4285710  0.006735838 -0.9683288 0.9818005
## 12:  Raw 1.5714282  0.001620229 -0.9665819 0.9698223
## 13:  Raw 1.7142853 -0.003495380 -0.9653983 0.9584076
## 14:  Raw 1.8571423 -0.008610989 -0.9647893 0.9475673
## 15:  Raw 1.9999995 -0.013726598 -0.9647652 0.9373120
## 16:  Raw 2.1428566 -0.018842207 -0.9653355 0.9276511
## 17:  Raw 2.2857137 -0.023957815 -0.9665089 0.9185932
## 18:  Raw 2.4285707 -0.029073425 -0.9682928 0.9101459
## 19:  Raw 2.5714278 -0.034189034 -0.9706939 0.9023159
## 20:  Raw 2.7142849 -0.039304644 -0.9737175 0.8951083
## 21:  Raw 2.8571420 -0.044420250 -0.9773679 0.8885274
## 22:  Raw 2.9999993 -0.049535859 -0.9816478 0.8825761
## 23:  Raw 3.1428564 -0.054651469 -0.9865592 0.8772563
## 24:  Raw 3.2857134 -0.059767079 -0.9921023 0.8725681
## 25:  Raw 3.4285705 -0.064882688 -0.9982764 0.8685110
## 26:  Raw 3.5714276 -0.069998294 -1.0050792 0.8650825
## 27:  Raw 3.7142847 -0.075113907 -1.0125072 0.8622794
## 28:  Raw 3.8571417 -0.080229513 -1.0205561 0.8600971
## 29:  Raw 3.9999990 -0.085345119 -1.0292200 0.8585297
## 30:  Raw 4.1428561 -0.090460733 -1.0384920 0.8575705
## 31:  Raw 4.2857132 -0.095576338 -1.0483639 0.8572112
## 32:  Raw 4.4285703 -0.100691952 -1.0588272 0.8574432
## 33:  Raw 4.5714273 -0.105807558 -1.0698717 0.8582565
## 34:  Raw 4.7142844 -0.110923164 -1.0814868 0.8596405
## 35:  Raw 4.8571415 -0.116038777 -1.0936613 0.8615837
## 36:  Raw 4.9999986 -0.121154383 -1.1063830 0.8640742
## 37:  Raw 5.1428556 -0.126269996 -1.1196394 0.8670995
## 38:  Raw 5.2857127 -0.131385610 -1.1334175 0.8706464
## 39:  Raw 5.4285698 -0.136501208 -1.1477039 0.8747015
## 40:  Raw 5.5714269 -0.141616821 -1.1624849 0.8792512
## 41:  Raw 5.7142839 -0.146732435 -1.1777464 0.8842816
## 42:  Raw 5.8571415 -0.151848033 -1.1934747 0.8897786
## 43:  Raw 5.9999986 -0.156963646 -1.2096553 0.8957280
##     Type      Time     Estimate         LL        UL
soldiffplot[Type == "standardized"]
##             Type      Time      Estimate         LL        UL
##  1: standardized 0.0000000  0.0212644245 -0.3724059 0.4149348
##  2: standardized 0.1428571  0.0193853974 -0.3699607 0.4087315
##  3: standardized 0.2857142  0.0175063703 -0.3676733 0.4026861
##  4: standardized 0.4285713  0.0156273432 -0.3655489 0.3968036
##  5: standardized 0.5714284  0.0137483170 -0.3635927 0.3910894
##  6: standardized 0.7142855  0.0118692908 -0.3618099 0.3855485
##  7: standardized 0.8571426  0.0099902637 -0.3602057 0.3801862
##  8: standardized 0.9999998  0.0081112375 -0.3587850 0.3750075
##  9: standardized 1.1428568  0.0062322104 -0.3575529 0.3700173
## 10: standardized 1.2857139  0.0043531838 -0.3565143 0.3652206
## 11: standardized 1.4285710  0.0024741569 -0.3556739 0.3606222
## 12: standardized 1.5714282  0.0005951303 -0.3550362 0.3562265
## 13: standardized 1.7142853 -0.0012838964 -0.3546057 0.3520379
## 14: standardized 1.8571423 -0.0031629233 -0.3543863 0.3480604
## 15: standardized 1.9999995 -0.0050419499 -0.3543819 0.3442980
## 16: standardized 2.1428566 -0.0069209766 -0.3545959 0.3407540
## 17: standardized 2.2857137 -0.0088000037 -0.3550316 0.3374316
## 18: standardized 2.4285707 -0.0106790299 -0.3556917 0.3343337
## 19: standardized 2.5714278 -0.0125580570 -0.3565786 0.3314625
## 20: standardized 2.7142849 -0.0144370832 -0.3576942 0.3288200
## 21: standardized 2.8571420 -0.0163161103 -0.3590401 0.3264079
## 22: standardized 2.9999993 -0.0181951374 -0.3606174 0.3242272
## 23: standardized 3.1428564 -0.0200741645 -0.3624267 0.3222784
## 24: standardized 3.2857134 -0.0219531897 -0.3644680 0.3205617
## 25: standardized 3.4285705 -0.0238322169 -0.3667412 0.3190768
## 26: standardized 3.5714276 -0.0257112440 -0.3692454 0.3178228
## 27: standardized 3.7142847 -0.0275902711 -0.3719792 0.3167987
## 28: standardized 3.8571417 -0.0294692982 -0.3749411 0.3160025
## 29: standardized 3.9999990 -0.0313483253 -0.3781289 0.3154322
## 30: standardized 4.1428561 -0.0332273506 -0.3815400 0.3150853
## 31: standardized 4.2857132 -0.0351063758 -0.3851715 0.3149588
## 32: standardized 4.4285703 -0.0369854048 -0.3890202 0.3150494
## 33: standardized 4.5714273 -0.0388644300 -0.3930823 0.3153535
## 34: standardized 4.7142844 -0.0407434590 -0.3973540 0.3158671
## 35: standardized 4.8571415 -0.0426224843 -0.4018311 0.3165862
## 36: standardized 4.9999986 -0.0445015095 -0.4065092 0.3175062
## 37: standardized 5.1428556 -0.0463805385 -0.4113836 0.3186225
## 38: standardized 5.2857127 -0.0482595637 -0.4164495 0.3199304
## 39: standardized 5.4285698 -0.0501385927 -0.4217021 0.3214250
## 40: standardized 5.5714269 -0.0520176180 -0.4271363 0.3231011
## 41: standardized 5.7142839 -0.0538966432 -0.4327469 0.3249536
## 42: standardized 5.8571415 -0.0557756722 -0.4385289 0.3269775
## 43: standardized 5.9999986 -0.0576546974 -0.4444770 0.3291675
##             Type      Time      Estimate         LL        UL

5 Diary - TST

tstdat <- na.omit(ds2[, .(ID, Time, dstrat4, dcond, TSTs)])

tstfit <- mplusModeler(mplusObject(
  TITLE = "Self-Report TST Analysis;",
  VARIABLE = "
    WITHIN = Time;
    BETWEEN = dstrat4 dcond;
    CLUSTER = ID;",
  ANALYSIS = "
   ESTIMATOR = ML;
   TYPE = TWOLEVEL RANDOM;
   PROCESSORS = 2;
   STARTS = 50 5;
   STITERATIONS = 200;
   MITERATIONS = 10000;
   MCONVERGENCE  = .000001;
",
  MODEL = "
  %WITHIN%
  s | TSTs ON Time;
  TSTs* (resvar);
  %BETWEEN%
  TSTs ON dstrat4 dcond (i3 - i4);
  s ON dcond (s1);
  TSTs WITH s*;
  TSTs* s* (vi vs);
  [TSTs* s*] (mi ms);
",
  OUTPUT = "CINTERVAL;",
  PLOT = "TYPE = PLOT2;",
  MODELCONSTRAINT = sprintf(
    mcsetup,
    mean(tstdat$dstrat4)),
  usevariables = c("ID", "Time", "TSTs",
                  "dstrat4", "dcond"),
  rdata = as.data.frame(tstdat)),
  dataout = "04_HighISI_tst.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 04_HighISI_tst.inp
## Wrote data to: 04_HighISI_tst.dat
## model information, coefficients, and effect sizes
tstout <- cbind(
  coef(tstfit, param = c("reg", "exp", "new")),
  round(confint(tstfit, param = c("reg", "exp", "new"))[,-1], 2))[, c(1, 2, 5, 6, 4)]
with(tstout,
     data.frame(
       Label = Label,
       Out = sprintf("%0.2f (%0.2f, %0.2f)", round(est, 2), LowerCI, UpperCI),
       pval = formatPval(pval, d = 3, sd = 3)))
##                 Label                 Out   pval
## 1          B S<-DCOND -0.10 (-0.21, 0.01)   .064
## 2     B TSTS<-DSTRAT4  0.32 (-0.25, 0.89)   .271
## 3       B TSTS<-DCOND  0.49 (-0.12, 1.10)   .119
## 4  B TSTS<-Intercepts   6.36 (5.81, 6.90) < .001
## 5     B S<-Intercepts   0.16 (0.08, 0.23) < .001
## 6              B ITAU   6.52 (6.06, 6.98) < .001
## 7              B ICBT   7.01 (6.61, 7.41) < .001
## 8             B IDIFF  0.49 (-0.12, 1.10)   .119
## 9              B STAU   0.16 (0.08, 0.23) < .001
## 10             B SCBT  0.06 (-0.02, 0.13)   .137
## 11            B SDIFF -0.10 (-0.21, 0.01)   .064
tstplot <- data.table(
  Condition = rep(c("TAU+", "CBT-I+Light"), each = 43),
  Time = c(tstfit$results$gh5$loop_data$xvalues, tstfit$results$gh5$loop_data$xvalues),
  Estimate = c(tstfit$results$gh5$loop_data$estimates[1, ], tstfit$results$gh5$loop_data$estimates[2, ]),
  LL = c(tstfit$results$gh5$loop_data$lowerci[1, ], tstfit$results$gh5$loop_data$lowerci[2, ]),
  UL = c(tstfit$results$gh5$loop_data$upperci[1, ], tstfit$results$gh5$loop_data$upperci[2, ]))

p.tst <- ggplot(tstplot, aes(Time, Estimate, ymin = LL, ymax = UL,
                             colour = Condition, fill = Condition)) +
  scale_y_continuous("TST (Diary)", breaks = seq(6,8,0.5)) +
  annotate("text", x = 2, y = 7.5, label = sprintf("CBT-I+Light slope %s", formatPval(subset(tstout, Label == "B SCBT")$pval, d = 3, sd = 3, includeP = TRUE))) +
  annotate("text", x = 2, y = 6.5, label = sprintf("TAU+ slope %s", formatPval(subset(tstout, Label == "B STAU")$pval, d = 3, sd = 3, includeP = TRUE))) +
  dailysleepStyle
print(p.tst)

tstdiffplot <- with(tstfit$results$gh5$loop_data, data.table(
  Type = rep(c("Raw", "standardized"), each = 43),
  Time = c(xvalues, xvalues),
  Estimate = c(estimates[3, ], estimates[4, ]),
  LL = c(lowerci[3, ], lowerci[4, ]),
  UL = c(upperci[3, ], upperci[4, ])))


tstdiffplot[Type == "Raw"]
##     Type      Time     Estimate         LL        UL
##  1:  Raw 0.0000000  0.485520601 -0.1249653 1.0960065
##  2:  Raw 0.1428571  0.471117765 -0.1339881 1.0762236
##  3:  Raw 0.2857142  0.456714928 -0.1433499 1.0567797
##  4:  Raw 0.4285713  0.442312092 -0.1530595 1.0376837
##  5:  Raw 0.5714284  0.427909255 -0.1631250 1.0189435
##  6:  Raw 0.7142855  0.413506418 -0.1735544 1.0005673
##  7:  Raw 0.8571426  0.399103612 -0.1843551 0.9825624
##  8:  Raw 0.9999998  0.384700775 -0.1955341 0.9649356
##  9:  Raw 1.1428568  0.370297939 -0.2070975 0.9476934
## 10:  Raw 1.2857139  0.355895102 -0.2190513 0.9308415
## 11:  Raw 1.4285710  0.341492265 -0.2314003 0.9143848
## 12:  Raw 1.5714282  0.327089429 -0.2441488 0.8983277
## 13:  Raw 1.7142853  0.312686622 -0.2573003 0.8826736
## 14:  Raw 1.8571423  0.298283786 -0.2708575 0.8674251
## 15:  Raw 1.9999995  0.283880949 -0.2848221 0.8525841
## 16:  Raw 2.1428566  0.269478112 -0.2991952 0.8381515
## 17:  Raw 2.2857137  0.255075276 -0.3139767 0.8241273
## 18:  Raw 2.4285707  0.240672454 -0.3291659 0.8105108
## 19:  Raw 2.5714278  0.226269618 -0.3447611 0.7973003
## 20:  Raw 2.7142849  0.211866796 -0.3607597 0.7844933
## 21:  Raw 2.8571420  0.197463959 -0.3771584 0.7720863
## 22:  Raw 2.9999993  0.183061123 -0.3939530 0.7600752
## 23:  Raw 3.1428564  0.168658301 -0.4111386 0.7484552
## 24:  Raw 3.2857134  0.154255465 -0.4287097 0.7372206
## 25:  Raw 3.4285705  0.139852628 -0.4466599 0.7263652
## 26:  Raw 3.5714276  0.125449806 -0.4649825 0.7158821
## 27:  Raw 3.7142847  0.111046970 -0.4836701 0.7057641
## 28:  Raw 3.8571417  0.096644133 -0.5027149 0.6960031
## 29:  Raw 3.9999990  0.082241304 -0.5221085 0.6865911
## 30:  Raw 4.1428561  0.067838475 -0.5418425 0.6775195
## 31:  Raw 4.2857132  0.053435642 -0.5619081 0.6687794
## 32:  Raw 4.4285703  0.039032809 -0.5822961 0.6603616
## 33:  Raw 4.5714273  0.024629978 -0.6029972 0.6522572
## 34:  Raw 4.7142844  0.010227147 -0.6240023 0.6444566
## 35:  Raw 4.8571415 -0.004175685 -0.6453019 0.6369506
## 36:  Raw 4.9999986 -0.018578516 -0.6668866 0.6297296
## 37:  Raw 5.1428556 -0.032981347 -0.6887471 0.6227844
## 38:  Raw 5.2857127 -0.047384180 -0.7108740 0.6161056
## 39:  Raw 5.4285698 -0.061787013 -0.7332581 0.6096841
## 40:  Raw 5.5714269 -0.076189846 -0.7558904 0.6035107
## 41:  Raw 5.7142839 -0.090592675 -0.7787620 0.5975767
## 42:  Raw 5.8571415 -0.104995504 -0.8018641 0.5918732
## 43:  Raw 5.9999986 -0.119398341 -0.8251883 0.5863917
##     Type      Time     Estimate         LL        UL
tstdiffplot[Type == "standardized"]
##             Type      Time     Estimate          LL        UL
##  1: standardized 0.0000000  0.283278674 -0.07397848 0.6405358
##  2: standardized 0.1428571  0.274875283 -0.07919867 0.6289493
##  3: standardized 0.2857142  0.266471922 -0.08461670 0.6175605
##  4: standardized 0.4285713  0.258068532 -0.09023765 0.6063747
##  5: standardized 0.5714284  0.249665141 -0.09606642 0.5953967
##  6: standardized 0.7142855  0.241261765 -0.10210768 0.5846312
##  7: standardized 0.8571426  0.232858390 -0.10836585 0.5740826
##  8: standardized 0.9999998  0.224454999 -0.11484504 0.5637550
##  9: standardized 1.1428568  0.216051623 -0.12154904 0.5536523
## 10: standardized 1.2857139  0.207648233 -0.12848125 0.5437777
## 11: standardized 1.4285710  0.199244857 -0.13564467 0.5341344
## 12: standardized 1.5714282  0.190841466 -0.14304189 0.5247248
## 13: standardized 1.7142853  0.182438090 -0.15067504 0.5155512
## 14: standardized 1.8571423  0.174034715 -0.15854572 0.5066152
## 15: standardized 1.9999995  0.165631324 -0.16665511 0.4979178
## 16: standardized 2.1428566  0.157227948 -0.17500383 0.4894597
## 17: standardized 2.2857137  0.148824558 -0.18359198 0.4812411
## 18: standardized 2.4285707  0.140421182 -0.19241919 0.4732615
## 19: standardized 2.5714278  0.132017791 -0.20148453 0.4655201
## 20: standardized 2.7142849  0.123614416 -0.21078660 0.4580154
## 21: standardized 2.8571420  0.115211032 -0.22032349 0.4507456
## 22: standardized 2.9999993  0.106807649 -0.23009282 0.4437081
## 23: standardized 3.1428564  0.098404266 -0.24009180 0.4369003
## 24: standardized 3.2857134  0.090000883 -0.25031719 0.4303190
## 25: standardized 3.4285705  0.081597507 -0.26076534 0.4239604
## 26: standardized 3.5714276  0.073194124 -0.27143234 0.4178206
## 27: standardized 3.7142847  0.064790741 -0.28231388 0.4118954
## 28: standardized 3.8571417  0.056387357 -0.29340541 0.4061801
## 29: standardized 3.9999990  0.047983974 -0.30470213 0.4006701
## 30: standardized 4.1428561  0.039580595 -0.31619903 0.3953602
## 31: standardized 4.2857132  0.031177212 -0.32789093 0.3902453
## 32: standardized 4.4285703  0.022773828 -0.33977252 0.3853202
## 33: standardized 4.5714273  0.014370446 -0.35183841 0.3805793
## 34: standardized 4.7142844  0.005967064 -0.36408311 0.3760172
## 35: standardized 4.8571415 -0.002436318 -0.37650111 0.3716285
## 36: standardized 4.9999986 -0.010839700 -0.38908693 0.3674075
## 37: standardized 5.1428556 -0.019243082 -0.40183502 0.3633489
## 38: standardized 5.2857127 -0.027646463 -0.41473994 0.3594470
## 39: standardized 5.4285698 -0.036049847 -0.42779627 0.3556966
## 40: standardized 5.5714269 -0.044453230 -0.44099873 0.3520923
## 41: standardized 5.7142839 -0.052856609 -0.45434201 0.3486288
## 42: standardized 5.8571415 -0.061259992 -0.46782100 0.3453010
## 43: standardized 5.9999986 -0.069663376 -0.48143071 0.3421040
##             Type      Time     Estimate          LL        UL

6 Actigraphy - Sleep Efficiency

seactidat <- na.omit(ds2[, .(ID, Time, dstrat4, dcond, SEactitrans)])

seactifit <- mplusModeler(mplusObject(
  TITLE = "Actigraphy SE Analysis;",
  VARIABLE = "
    WITHIN = Time;
    BETWEEN = dstrat4 dcond;
    CLUSTER = ID;",
  ANALYSIS = "
   ESTIMATOR = ML;
   TYPE = TWOLEVEL RANDOM;
   PROCESSORS = 2;
   STARTS = 50 5;
   STITERATIONS = 200;
   MITERATIONS = 10000;
   MCONVERGENCE  = .000001;
",
  MODEL = "
  %WITHIN%
  s | SEactitrans ON Time;
  SEactitrans* (resvar);
  %BETWEEN%
  SEactitrans ON dstrat4 dcond (i3 - i4);
  s ON dcond (s1);
  SEactitrans WITH s*;
  SEactitrans* s* (vi vs);
  [SEactitrans* s*] (mi ms);
",
  OUTPUT = "CINTERVAL;",
  PLOT = "TYPE = PLOT2;",
  MODELCONSTRAINT = sprintf(
    mcsetup,
    mean(seactidat$dstrat4)),
  usevariables = c("ID", "Time", "SEactitrans",
                   "dstrat4", "dcond"),
  rdata = as.data.frame(seactidat)),
  dataout = "04_HighISI_seacti.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 04_HighISI_seacti.inp
## Wrote data to: 04_HighISI_seacti.dat
## model information, coefficients, and effect sizes
## summary(seactifit)
seactiout <- cbind(
  coef(seactifit, param = c("reg", "exp", "new")),
  round(confint(seactifit, param = c("reg", "exp", "new"))[,-1], 2))[, c(1, 2, 5, 6, 4)]
with(seactiout,
     data.frame(
       Label = Label,
       Out = sprintf("%0.2f (%0.2f, %0.2f)", round(est, 2), LowerCI, UpperCI),
       pval = formatPval(pval, d = 3, sd = 3)))
##                       Label                  Out   pval
## 1                B S<-DCOND   1.01 (-0.11, 2.12)   .078
## 2     B SEACTITRAN<-DSTRAT4   1.37 (-4.22, 6.97)   .630
## 3       B SEACTITRAN<-DCOND  -0.55 (-6.10, 5.00)   .846
## 4  B SEACTITRAN<-Intercepts 44.29 (39.44, 49.14) < .001
## 5           B S<-Intercepts  -0.14 (-0.94, 0.65)   .727
## 6                    B ITAU 44.98 (40.91, 49.05) < .001
## 7                    B ICBT 44.43 (40.66, 48.19) < .001
## 8                   B IDIFF  -0.55 (-6.10, 5.00)   .846
## 9                    B STAU  -0.14 (-0.94, 0.65)   .727
## 10                   B SCBT    0.86 (0.07, 1.66)   .033
## 11                  B SDIFF   1.01 (-0.11, 2.12)   .078
seactiplot <- data.table(
  Condition = rep(c("TAU+", "CBT-I+Light"), each = 43),
  Time = c(seactifit$results$gh5$loop_data$xvalues, seactifit$results$gh5$loop_data$xvalues),
  Estimate = c(seactifit$results$gh5$loop_data$estimates[1, ], seactifit$results$gh5$loop_data$estimates[2, ]),
  LL = c(seactifit$results$gh5$loop_data$lowerci[1, ], seactifit$results$gh5$loop_data$lowerci[2, ]),
  UL = c(seactifit$results$gh5$loop_data$upperci[1, ], seactifit$results$gh5$loop_data$upperci[2, ]))

p.seacti <- ggplot(seactiplot, aes(Time, SEback(Estimate), ymin = SEback(LL), ymax = SEback(UL),
                                   colour = Condition, fill = Condition)) +
  scale_y_continuous("SE (Acti)", breaks = 85:95) +
  annotate("text", x = 2, y = 91, label = sprintf("CBT-I+Light slope %s", formatPval(subset(seactiout, Label == "B SCBT")$pval, d = 3, sd = 3, includeP = TRUE))) +
  annotate("text", x = 2, y = 88, label = sprintf("TAU+ slope %s", formatPval(subset(seactiout, Label == "B STAU")$pval, d = 3, sd = 3, includeP = TRUE))) +
  dailysleepStyle
print(p.seacti)

seactidiffplot <- with(seactifit$results$gh5$loop_data, data.table(
  Type = rep(c("Raw", "standardized"), each = 43),
  Time = c(xvalues, xvalues),
  Estimate = c(estimates[3, ], estimates[4, ]),
  LL = c(lowerci[3, ], lowerci[4, ]),
  UL = c(upperci[3, ], upperci[4, ])))


seactidiffplot[Type == "Raw"]
##     Type      Time   Estimate        LL        UL
##  1:  Raw 0.0000000 -0.5512769 -6.098123  4.995569
##  2:  Raw 0.1428571 -0.4076296 -5.921537  5.106278
##  3:  Raw 0.2857142 -0.2639823 -5.749409  5.221444
##  4:  Raw 0.4285713 -0.1203351 -5.581806  5.341136
##  5:  Raw 0.5714284  0.0233122 -5.418790  5.465415
##  6:  Raw 0.7142855  0.1669595 -5.260409  5.594328
##  7:  Raw 0.8571426  0.3106067 -5.106701  5.727915
##  8:  Raw 0.9999998  0.4542540 -4.957693  5.866201
##  9:  Raw 1.1428568  0.5979013 -4.813397  6.009200
## 10:  Raw 1.2857139  0.7415485 -4.673817  6.156914
## 11:  Raw 1.4285710  0.8851958 -4.538940  6.309332
## 12:  Raw 1.5714282  1.0288430 -4.408746  6.466432
## 13:  Raw 1.7142853  1.1724904 -4.283198  6.628179
## 14:  Raw 1.8571423  1.3161376 -4.162251  6.794526
## 15:  Raw 1.9999995  1.4597849 -4.045847  6.965417
## 16:  Raw 2.1428566  1.6034322 -3.933921  7.140785
## 17:  Raw 2.2857137  1.7470794 -3.826395  7.320553
## 18:  Raw 2.4285707  1.8907267 -3.723184  7.504637
## 19:  Raw 2.5714278  2.0343740 -3.624196  7.692944
## 20:  Raw 2.7142849  2.1780212 -3.529332  7.885375
## 21:  Raw 2.8571420  2.3216684 -3.438487  8.081824
## 22:  Raw 2.9999993  2.4653158 -3.351552  8.282184
## 23:  Raw 3.1428564  2.6089630 -3.268413  8.486339
## 24:  Raw 3.2857134  2.7526102 -3.188954  8.694175
## 25:  Raw 3.4285705  2.8962576 -3.113058  8.905574
## 26:  Raw 3.5714276  3.0399048 -3.040606  9.120416
## 27:  Raw 3.7142847  3.1835520 -2.971477  9.338581
## 28:  Raw 3.8571417  3.3271995 -2.905553  9.559952
## 29:  Raw 3.9999990  3.4708467 -2.842715  9.784409
## 30:  Raw 4.1428561  3.6144938 -2.782847 10.011835
## 31:  Raw 4.2857132  3.7581410 -2.725833 10.242115
## 32:  Raw 4.4285703  3.9017885 -2.671560 10.475137
## 33:  Raw 4.5714273  4.0454359 -2.619919 10.710790
## 34:  Raw 4.7142844  4.1890831 -2.570801 10.948967
## 35:  Raw 4.8571415  4.3327303 -2.524103 11.189563
## 36:  Raw 4.9999986  4.4763775 -2.479722 11.432477
## 37:  Raw 5.1428556  4.6200247 -2.437563 11.677612
## 38:  Raw 5.2857127  4.7636719 -2.397529 11.924872
## 39:  Raw 5.4285698  4.9073191 -2.359530 12.174169
## 40:  Raw 5.5714269  5.0509667 -2.323479 12.425411
## 41:  Raw 5.7142839  5.1946139 -2.289291 12.678518
## 42:  Raw 5.8571415  5.3382611 -2.256886 12.933409
## 43:  Raw 5.9999986  5.4819083 -2.226187 13.190004
##     Type      Time   Estimate        LL        UL
seactidiffplot[Type == "standardized"]
##             Type      Time     Estimate         LL        UL
##  1: standardized 0.0000000 -0.041137271 -0.4550247 0.3727502
##  2: standardized 0.1428571 -0.030418055 -0.4418490 0.3810129
##  3: standardized 0.2857142 -0.019698838 -0.4290100 0.3896123
##  4: standardized 0.4285713 -0.008979619 -0.4165130 0.3985537
##  5: standardized 0.5714284  0.001739599 -0.4043624 0.4078416
##  6: standardized 0.7142855  0.012458816 -0.3925620 0.4174797
##  7: standardized 0.8571426  0.023178034 -0.3811146 0.4274707
##  8: standardized 0.9999998  0.033897251 -0.3700220 0.4378165
##  9: standardized 1.1428568  0.044616468 -0.3592852 0.4485182
## 10: standardized 1.2857139  0.055335686 -0.3489044 0.4595757
## 11: standardized 1.4285710  0.066054903 -0.3388785 0.4709883
## 12: standardized 1.5714282  0.076774120 -0.3292058 0.4827541
## 13: standardized 1.7142853  0.087493338 -0.3198836 0.4948703
## 14: standardized 1.8571423  0.098212555 -0.3109083 0.5073334
## 15: standardized 1.9999995  0.108931772 -0.3022754 0.5201389
## 16: standardized 2.1428566  0.119650997 -0.2939798 0.5332817
## 17: standardized 2.2857137  0.130370215 -0.2860155 0.5467560
## 18: standardized 2.4285707  0.141089424 -0.2783762 0.5605550
## 19: standardized 2.5714278  0.151808649 -0.2710545 0.5746718
## 20: standardized 2.7142849  0.162527859 -0.2640431 0.5890988
## 21: standardized 2.8571420  0.173247084 -0.2573338 0.6038279
## 22: standardized 2.9999993  0.183966294 -0.2509182 0.6188508
## 23: standardized 3.1428564  0.194685519 -0.2447879 0.6341589
## 24: standardized 3.2857134  0.205404729 -0.2389339 0.6497433
## 25: standardized 3.4285705  0.216123953 -0.2333472 0.6655951
## 26: standardized 3.5714276  0.226843178 -0.2280188 0.6817052
## 27: standardized 3.7142847  0.237562388 -0.2229397 0.6980644
## 28: standardized 3.8571417  0.248281613 -0.2181008 0.7146640
## 29: standardized 3.9999990  0.259000838 -0.2134930 0.7314947
## 30: standardized 4.1428561  0.269720048 -0.2091077 0.7485478
## 31: standardized 4.2857132  0.280439258 -0.2049360 0.7658145
## 32: standardized 4.4285703  0.291158468 -0.2009695 0.7832864
## 33: standardized 4.5714273  0.301877707 -0.1971997 0.8009551
## 34: standardized 4.7142844  0.312596917 -0.1936187 0.8188125
## 35: standardized 4.8571415  0.323316127 -0.1902185 0.8368508
## 36: standardized 4.9999986  0.334035337 -0.1869915 0.8550622
## 37: standardized 5.1428556  0.344754577 -0.1839304 0.8734395
## 38: standardized 5.2857127  0.355473787 -0.1810280 0.8919756
## 39: standardized 5.4285698  0.366192997 -0.1782775 0.9106635
## 40: standardized 5.5714269  0.376912206 -0.1756724 0.9294968
## 41: standardized 5.7142839  0.387631446 -0.1732063 0.9484692
## 42: standardized 5.8571415  0.398350656 -0.1708732 0.9675745
## 43: standardized 5.9999986  0.409069866 -0.1686672 0.9868070
##             Type      Time     Estimate         LL        UL

7 Actigraphy - WASO

wasoactidat <- na.omit(ds2[, .(ID, Time, dstrat4, dcond, WASOactitrans)])

wasoactifit <- mplusModeler(mplusObject(
  TITLE = "Actigraphy WASO Analysis;",
  VARIABLE = "
    WITHIN = Time;
    BETWEEN = dstrat4 dcond;
    CLUSTER = ID;",
  ANALYSIS = "
   ESTIMATOR = ML;
   TYPE = TWOLEVEL RANDOM;
   PROCESSORS = 2;
   STARTS = 50 5;
   STITERATIONS = 200;
   MITERATIONS = 10000;
   MCONVERGENCE  = .000001;
",
  MODEL = "
  %WITHIN%
  s | WASOactitrans ON Time;
  WASOactitrans* (resvar);
  %BETWEEN%
  WASOactitrans ON dstrat4 dcond (i3 - i4);
  s ON dcond (s1);
  WASOactitrans WITH s*;
  WASOactitrans* s* (vi vs);
  [WASOactitrans* s*] (mi ms);
",
  OUTPUT = "CINTERVAL;",
  PLOT = "TYPE = PLOT2;",
  MODELCONSTRAINT = sprintf(
    mcsetup,
    mean(wasoactidat$dstrat4)),
  usevariables = c("ID", "Time", "WASOactitrans",
                   "dstrat4", "dcond"),
  rdata = as.data.frame(wasoactidat)),
  dataout = "04_HighISI_wasoacti.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 04_HighISI_wasoacti.inp
## Wrote data to: 04_HighISI_wasoacti.dat
## model information, coefficients, and effect sizes
wasoactiout <- cbind(
  coef(wasoactifit, param = c("reg", "exp", "new")),
  round(confint(wasoactifit, param = c("reg", "exp", "new"))[,-1], 2))[, c(1, 2, 5, 6, 4)]
with(wasoactiout,
     data.frame(
       Label = Label,
       Out = sprintf("%0.2f (%0.2f, %0.2f)", round(est, 2), LowerCI, UpperCI),
       pval = formatPval(pval, d = 3, sd = 3)))
##                       Label                  Out   pval
## 1                B S<-DCOND -0.21 (-0.38, -0.04)   .016
## 2     B WASOACTITR<-DSTRAT4  -0.21 (-1.12, 0.71)   .657
## 3       B WASOACTITR<-DCOND   0.32 (-0.57, 1.20)   .482
## 4  B WASOACTITR<-Intercepts    7.04 (6.26, 7.82) < .001
## 5           B S<-Intercepts   0.09 (-0.04, 0.21)   .165
## 6                    B ITAU    6.94 (6.29, 7.59) < .001
## 7                    B ICBT    7.26 (6.66, 7.86) < .001
## 8                   B IDIFF   0.32 (-0.57, 1.20)   .482
## 9                    B STAU   0.09 (-0.04, 0.21)   .165
## 10                   B SCBT -0.12 (-0.25, -0.00)   .046
## 11                  B SDIFF -0.21 (-0.38, -0.04)   .016
wasoactiplot <- data.table(
  Condition = rep(c("TAU+", "CBT-I+Light"), each = 43),
  Time = c(wasoactifit$results$gh5$loop_data$xvalues, wasoactifit$results$gh5$loop_data$xvalues),
  Estimate = c(wasoactifit$results$gh5$loop_data$estimates[1, ], wasoactifit$results$gh5$loop_data$estimates[2, ]),
  LL = c(wasoactifit$results$gh5$loop_data$lowerci[1, ], wasoactifit$results$gh5$loop_data$lowerci[2, ]),
  UL = c(wasoactifit$results$gh5$loop_data$upperci[1, ], wasoactifit$results$gh5$loop_data$upperci[2, ]))

p.wasoacti <- ggplot(wasoactiplot, aes(Time, Estimate^2, ymin = LL^2, ymax = UL^2,
                                       colour = Condition, fill = Condition)) +
  scale_y_continuous("WASO (Acti)", breaks = seq(10,70,5)) +
  annotate("text", x = 2, y = 42, label = sprintf("CBT-I+Light slope %s", formatPval(subset(wasoactiout, Label == "B SCBT")$pval, d = 3, sd = 3, includeP = TRUE))) +
  annotate("text", x = 2, y = 56, label = sprintf("TAU+ slope %s", formatPval(subset(wasoactiout, Label == "B STAU")$pval, d = 3, sd = 3, includeP = TRUE))) +
  dailysleepStyle
print(p.wasoacti)

wasoactidiffplot <- with(wasoactifit$results$gh5$loop_data, data.table(
  Type = rep(c("Raw", "standardized"), each = 43),
  Time = c(xvalues, xvalues),
  Estimate = c(estimates[3, ], estimates[4, ]),
  LL = c(lowerci[3, ], lowerci[4, ]),
  UL = c(upperci[3, ], upperci[4, ])))


wasoactidiffplot[Type == "Raw"]
##     Type      Time    Estimate         LL        UL
##  1:  Raw 0.0000000  0.31759536 -0.5678709 1.2030616
##  2:  Raw 0.1428571  0.28750017 -0.5932142 1.1682144
##  3:  Raw 0.2857142  0.25740498 -0.6192163 1.1340262
##  4:  Raw 0.4285713  0.22730979 -0.6458865 1.1005061
##  5:  Raw 0.5714284  0.19721462 -0.6732327 1.0676619
##  6:  Raw 0.7142855  0.16711943 -0.7012613 1.0355002
##  7:  Raw 0.8571426  0.13702424 -0.7299773 1.0040257
##  8:  Raw 0.9999998  0.10692906 -0.7593838 0.9732419
##  9:  Raw 1.1428568  0.07683387 -0.7894826 0.9431503
## 10:  Raw 1.2857139  0.04673869 -0.8202736 0.9137509
## 11:  Raw 1.4285710  0.01664351 -0.8517551 0.8850421
## 12:  Raw 1.5714282 -0.01345168 -0.8839239 0.8570206
## 13:  Raw 1.7142853 -0.04354686 -0.9167751 0.8296814
## 14:  Raw 1.8571423 -0.07364205 -0.9503022 0.8030182
## 15:  Raw 1.9999995 -0.10373724 -0.9844974 0.7770230
## 16:  Raw 2.1428566 -0.13383241 -1.0193512 0.7516865
## 17:  Raw 2.2857137 -0.16392760 -1.0548534 0.7269982
## 18:  Raw 2.4285707 -0.19402279 -1.0909920 0.7029464
## 19:  Raw 2.5714278 -0.22411796 -1.1277542 0.6795183
## 20:  Raw 2.7142849 -0.25421315 -1.1651266 0.6567002
## 21:  Raw 2.8571420 -0.28430834 -1.2030944 0.6344776
## 22:  Raw 2.9999993 -0.31440353 -1.2416425 0.6128354
## 23:  Raw 3.1428564 -0.34449869 -1.2807552 0.5917578
## 24:  Raw 3.2857134 -0.37459388 -1.3204165 0.5712287
## 25:  Raw 3.4285705 -0.40468907 -1.3606098 0.5512316
## 26:  Raw 3.5714276 -0.43478426 -1.4013183 0.5317498
## 27:  Raw 3.7142847 -0.46487945 -1.4425255 0.5127666
## 28:  Raw 3.8571417 -0.49497464 -1.4842144 0.4942651
## 29:  Raw 3.9999990 -0.52506983 -1.5263683 0.4762287
## 30:  Raw 4.1428561 -0.55516499 -1.5689707 0.4586406
## 31:  Raw 4.2857132 -0.58526021 -1.6120050 0.4414847
## 32:  Raw 4.4285703 -0.61535537 -1.6554554 0.4247446
## 33:  Raw 4.5714273 -0.64545053 -1.6993058 0.4084046
## 34:  Raw 4.7142844 -0.67554575 -1.7435408 0.3924493
## 35:  Raw 4.8571415 -0.70564091 -1.7881454 0.3768635
## 36:  Raw 4.9999986 -0.73573613 -1.8331050 0.3616327
## 37:  Raw 5.1428556 -0.76583129 -1.8784051 0.3467425
## 38:  Raw 5.2857127 -0.79592645 -1.9240322 0.3321793
## 39:  Raw 5.4285698 -0.82602167 -1.9699730 0.3179297
## 40:  Raw 5.5714269 -0.85611683 -2.0162144 0.3039807
## 41:  Raw 5.7142839 -0.88621205 -2.0627444 0.2903202
## 42:  Raw 5.8571415 -0.91630721 -2.1095505 0.2769361
## 43:  Raw 5.9999986 -0.94640243 -2.1566217 0.2638170
##     Type      Time    Estimate         LL        UL
wasoactidiffplot[Type == "standardized"]
##             Type      Time     Estimate         LL        UL
##  1: standardized 0.0000000  0.139618427 -0.2496394 0.5288763
##  2: standardized 0.1428571  0.126388252 -0.2607582 0.5135347
##  3: standardized 0.2857142  0.113158077 -0.2721712 0.4984873
##  4: standardized 0.4285713  0.099927902 -0.2838825 0.4837383
##  5: standardized 0.5714284  0.086697727 -0.2958958 0.4692912
##  6: standardized 0.7142855  0.073467553 -0.3082139 0.4551490
##  7: standardized 0.8571426  0.060237374 -0.3208390 0.4413137
##  8: standardized 0.9999998  0.047007199 -0.3337725 0.4277869
##  9: standardized 1.1428568  0.033777021 -0.3470153 0.4145693
## 10: standardized 1.2857139  0.020546846 -0.3605672 0.4016609
## 11: standardized 1.4285710  0.007316670 -0.3744275 0.3890609
## 12: standardized 1.5714282 -0.005913506 -0.3885947 0.3767677
## 13: standardized 1.7142853 -0.019143682 -0.4030664 0.3647791
## 14: standardized 1.8571423 -0.032373857 -0.4178399 0.3530921
## 15: standardized 1.9999995 -0.045604035 -0.4329113 0.3417033
## 16: standardized 2.1428566 -0.058834210 -0.4482766 0.3306082
## 17: standardized 2.2857137 -0.072064385 -0.4639310 0.3198022
## 18: standardized 2.4285707 -0.085294560 -0.4798690 0.3092799
## 19: standardized 2.5714278 -0.098524742 -0.4960850 0.2990355
## 20: standardized 2.7142849 -0.111754917 -0.5125726 0.2890628
## 21: standardized 2.8571420 -0.124985091 -0.5293254 0.2793552
## 22: standardized 2.9999993 -0.138215274 -0.5463364 0.2699059
## 23: standardized 3.1428564 -0.151445448 -0.5635986 0.2607077
## 24: standardized 3.2857134 -0.164675623 -0.5811046 0.2517534
## 25: standardized 3.4285705 -0.177905798 -0.5988472 0.2430355
## 26: standardized 3.5714276 -0.191135973 -0.6168185 0.2345466
## 27: standardized 3.7142847 -0.204366148 -0.6350113 0.2262790
## 28: standardized 3.8571417 -0.217596322 -0.6534178 0.2182251
## 29: standardized 3.9999990 -0.230826497 -0.6720306 0.2103776
## 30: standardized 4.1428561 -0.244056672 -0.6908422 0.2027288
## 31: standardized 4.2857132 -0.257286847 -0.7098452 0.1952715
## 32: standardized 4.4285703 -0.270517021 -0.7290325 0.1879984
## 33: standardized 4.5714273 -0.283747196 -0.7483969 0.1809025
## 34: standardized 4.7142844 -0.296977371 -0.7679315 0.1739767
## 35: standardized 4.8571415 -0.310207546 -0.7876296 0.1672145
## 36: standardized 4.9999986 -0.323437721 -0.8074846 0.1606091
## 37: standardized 5.1428556 -0.336667895 -0.8274902 0.1541544
## 38: standardized 5.2857127 -0.349898070 -0.8476402 0.1478440
## 39: standardized 5.4285698 -0.363128245 -0.8679286 0.1416721
## 40: standardized 5.5714269 -0.376358449 -0.8883499 0.1356330
## 41: standardized 5.7142839 -0.389588624 -0.9088984 0.1297211
## 42: standardized 5.8571415 -0.402818799 -0.9295687 0.1239311
## 43: standardized 5.9999986 -0.416048974 -0.9503559 0.1182580
##             Type      Time     Estimate         LL        UL
## model information, coefficients, and effect sizes
## summary(wasoactifit)
cbind(
  coef(wasoactifit, param = c("reg", "exp", "new")),
  confint(wasoactifit, param = c("reg", "exp", "new"))[,-1])
##                       Label    est    se  pval LowerCI UpperCI
## 2                B S<-DCOND -0.211 0.087 0.016  -0.382  -0.039
## 3     B WASOACTITR<-DSTRAT4 -0.208 0.467 0.657  -1.123   0.708
## 4       B WASOACTITR<-DCOND  0.318 0.452 0.482  -0.568   1.203
## 6  B WASOACTITR<-Intercepts  7.043 0.397 0.000   6.265   7.822
## 7           B S<-Intercepts  0.086 0.062 0.165  -0.035   0.207
## 10                   B ITAU  6.940 0.331 0.000   6.290   7.589
## 11                   B ICBT  7.257 0.307 0.000   6.656   7.858
## 12                  B IDIFF  0.318 0.452 0.482  -0.568   1.203
## 13                   B STAU  0.086 0.062 0.165  -0.035   0.207
## 14                   B SCBT -0.125 0.063 0.046  -0.248  -0.002
## 15                  B SDIFF -0.211 0.087 0.016  -0.382  -0.039

8 Actigraphy - SOL

solactidat <- na.omit(ds2[, .(ID, Time, dstrat4, dcond, SOLactitrans)])

solactifit <- mplusModeler(mplusObject(
  TITLE = "Actigraphy SOL Analysis;",
  VARIABLE = "
    WITHIN = Time;
    BETWEEN = dstrat4 dcond;
    CLUSTER = ID;",
  ANALYSIS = "
   ESTIMATOR = ML;
   TYPE = TWOLEVEL RANDOM;
   PROCESSORS = 2;
   STARTS = 50 5;
   STITERATIONS = 200;
   MITERATIONS = 10000;
   MCONVERGENCE  = .000001;
",
  MODEL = "
  %WITHIN%
  s | SOLactitrans ON Time;
  SOLactitrans* (resvar);
  %BETWEEN%
  SOLactitrans ON dstrat4 dcond (i3 - i4);
  s ON dcond (s1);
  SOLactitrans WITH s*;
  SOLactitrans* s* (vi vs);
  [SOLactitrans* s*] (mi ms);
",
  OUTPUT = "CINTERVAL;",
  PLOT = "TYPE = PLOT2;",
  MODELCONSTRAINT = sprintf(
    mcsetup,
    mean(solactidat$dstrat4)),
  usevariables = c("ID", "Time", "SOLactitrans",
                  "dstrat4", "dcond"),
  rdata = as.data.frame(solactidat)),
  dataout = "04_HighISI_solacti.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 04_HighISI_solacti.inp
## Wrote data to: 04_HighISI_solacti.dat
## model information, coefficients, and effect sizes
solactiout <- cbind(
  coef(solactifit, param = c("reg", "exp", "new")),
  round(confint(solactifit, param = c("reg", "exp", "new"))[,-1], 2))[, c(1, 2, 5, 6, 4)]
with(solactiout,
     data.frame(
       Label = Label,
       Out = sprintf("%0.2f (%0.2f, %0.2f)", round(est, 2), LowerCI, UpperCI),
       pval = formatPval(pval, d = 3, sd = 3)))
##                       Label                 Out   pval
## 1                B S<-DCOND -0.00 (-0.10, 0.09)   .922
## 2     B SOLACTITRA<-DSTRAT4  0.03 (-0.34, 0.39)   .881
## 3       B SOLACTITRA<-DCOND -0.09 (-0.53, 0.35)   .682
## 4  B SOLACTITRA<-Intercepts   1.52 (1.16, 1.89) < .001
## 5           B S<-Intercepts -0.02 (-0.09, 0.05)   .594
## 6                    B ITAU   1.53 (1.21, 1.86) < .001
## 7                    B ICBT   1.44 (1.14, 1.74) < .001
## 8                   B IDIFF -0.09 (-0.53, 0.35)   .682
## 9                    B STAU -0.02 (-0.09, 0.05)   .594
## 10                   B SCBT -0.02 (-0.09, 0.05)   .512
## 11                  B SDIFF -0.00 (-0.10, 0.09)   .922
solactiplot <- data.table(
  Condition = rep(c("TAU+", "CBT-I+Light"), each = 43),
  Time = c(solactifit$results$gh5$loop_data$xvalues, solactifit$results$gh5$loop_data$xvalues),
  Estimate = c(solactifit$results$gh5$loop_data$estimates[1, ], solactifit$results$gh5$loop_data$estimates[2, ]),
  LL = c(solactifit$results$gh5$loop_data$lowerci[1, ], solactifit$results$gh5$loop_data$lowerci[2, ]),
  UL = c(solactifit$results$gh5$loop_data$upperci[1, ], solactifit$results$gh5$loop_data$upperci[2, ]))

p.solacti <- ggplot(solactiplot, aes(Time, Estimate^2, ymin = LL^2, ymax = UL^2,
                                     colour = Condition, fill = Condition)) +
  scale_y_continuous("SOL (Acti)", breaks = seq(0,10,0.5)) +
  annotate("text", x = 2, y = 1.6, label = sprintf("CBT-I+Light slope %s", formatPval(subset(solactiout, Label == "B SCBT")$pval, d = 3, sd = 3, includeP = TRUE))) +
  annotate("text", x = 2, y = 2.5, label = sprintf("TAU+ slope %s", formatPval(subset(solactiout, Label == "B STAU")$pval, d = 3, sd = 3, includeP = TRUE))) +
  dailysleepStyle
print(p.solacti)

solactidiffplot <- with(solactifit$results$gh5$loop_data, data.table(
  Type = rep(c("Raw", "standardized"), each = 43),
  Time = c(xvalues, xvalues),
  Estimate = c(estimates[3, ], estimates[4, ]),
  LL = c(lowerci[3, ], lowerci[4, ]),
  UL = c(upperci[3, ], upperci[4, ])))


solactidiffplot[Type == "Raw"]
##     Type      Time    Estimate         LL        UL
##  1:  Raw 0.0000000 -0.09212289 -0.5327211 0.3484753
##  2:  Raw 0.1428571 -0.09282270 -0.5254927 0.3398473
##  3:  Raw 0.2857142 -0.09352251 -0.5185740 0.3315290
##  4:  Raw 0.4285713 -0.09422232 -0.5119820 0.3235373
##  5:  Raw 0.5714284 -0.09492213 -0.5057340 0.3158897
##  6:  Raw 0.7142855 -0.09562194 -0.4998477 0.3086038
##  7:  Raw 0.8571426 -0.09632175 -0.4943413 0.3016977
##  8:  Raw 0.9999998 -0.09702156 -0.4892325 0.2951894
##  9:  Raw 1.1428568 -0.09772138 -0.4845395 0.2890968
## 10:  Raw 1.2857139 -0.09842119 -0.4802798 0.2834374
## 11:  Raw 1.4285710 -0.09912100 -0.4764705 0.2782285
## 12:  Raw 1.5714282 -0.09982082 -0.4731279 0.2734863
## 13:  Raw 1.7142853 -0.10052063 -0.4702673 0.2692260
## 14:  Raw 1.8571423 -0.10122044 -0.4679028 0.2654619
## 15:  Raw 1.9999995 -0.10192025 -0.4660468 0.2622063
## 16:  Raw 2.1428566 -0.10262006 -0.4647102 0.2594701
## 17:  Raw 2.2857137 -0.10331987 -0.4639018 0.2572621
## 18:  Raw 2.4285707 -0.10401969 -0.4636281 0.2555888
## 19:  Raw 2.5714278 -0.10471950 -0.4638937 0.2544546
## 20:  Raw 2.7142849 -0.10541931 -0.4647003 0.2538616
## 21:  Raw 2.8571420 -0.10611912 -0.4660475 0.2538092
## 22:  Raw 2.9999993 -0.10681893 -0.4679324 0.2542945
## 23:  Raw 3.1428564 -0.10751874 -0.4703498 0.2553123
## 24:  Raw 3.2857134 -0.10821855 -0.4732921 0.2568550
## 25:  Raw 3.4285705 -0.10891836 -0.4767497 0.2589130
## 26:  Raw 3.5714276 -0.10961817 -0.4807112 0.2614748
## 27:  Raw 3.7142847 -0.11031799 -0.4851633 0.2645274
## 28:  Raw 3.8571417 -0.11101780 -0.4900916 0.2680560
## 29:  Raw 3.9999990 -0.11171761 -0.4954803 0.2720450
## 30:  Raw 4.1428561 -0.11241742 -0.5013126 0.2764778
## 31:  Raw 4.2857132 -0.11311723 -0.5075714 0.2813369
## 32:  Raw 4.4285703 -0.11381704 -0.5142388 0.2866048
## 33:  Raw 4.5714273 -0.11451685 -0.5212969 0.2922632
## 34:  Raw 4.7142844 -0.11521666 -0.5287277 0.2982943
## 35:  Raw 4.8571415 -0.11591648 -0.5365131 0.3046802
## 36:  Raw 4.9999986 -0.11661629 -0.5446358 0.3114032
## 37:  Raw 5.1428556 -0.11731610 -0.5530783 0.3184461
## 38:  Raw 5.2857127 -0.11801592 -0.5618240 0.3257921
## 39:  Raw 5.4285698 -0.11871573 -0.5708566 0.3334252
## 40:  Raw 5.5714269 -0.11941554 -0.5801607 0.3413296
## 41:  Raw 5.7142839 -0.12011535 -0.5897213 0.3494906
## 42:  Raw 5.8571415 -0.12081516 -0.5995240 0.3578937
## 43:  Raw 5.9999986 -0.12151497 -0.6095555 0.3665256
##     Type      Time    Estimate         LL        UL
solactidiffplot[Type == "standardized"]
##             Type      Time    Estimate         LL        UL
##  1: standardized 0.0000000 -0.06478955 -0.3747191 0.2451401
##  2: standardized 0.1428571 -0.06528172 -0.3696402 0.2390768
##  3: standardized 0.2857142 -0.06577389 -0.3647793 0.2332315
##  4: standardized 0.4285713 -0.06626607 -0.3601482 0.2276161
##  5: standardized 0.5714284 -0.06675824 -0.3557593 0.2222428
##  6: standardized 0.7142855 -0.06725042 -0.3516250 0.2171242
##  7: standardized 0.8571426 -0.06774259 -0.3477579 0.2122727
##  8: standardized 0.9999998 -0.06823476 -0.3441707 0.2077012
##  9: standardized 1.1428568 -0.06872693 -0.3408760 0.2034221
## 10: standardized 1.2857139 -0.06921911 -0.3378860 0.1994478
## 11: standardized 1.4285710 -0.06971128 -0.3352130 0.1957904
## 12: standardized 1.5714282 -0.07020346 -0.3328682 0.1924613
## 13: standardized 1.7142853 -0.07069563 -0.3308624 0.1894712
## 14: standardized 1.8571423 -0.07118780 -0.3292055 0.1868299
## 15: standardized 1.9999995 -0.07167998 -0.3279063 0.1845463
## 16: standardized 2.1428566 -0.07217215 -0.3269722 0.1826279
## 17: standardized 2.2857137 -0.07266433 -0.3264095 0.1810809
## 18: standardized 2.4285707 -0.07315650 -0.3262229 0.1799099
## 19: standardized 2.5714278 -0.07364868 -0.3264152 0.1791179
## 20: standardized 2.7142849 -0.07414085 -0.3269879 0.1787062
## 21: standardized 2.8571420 -0.07463302 -0.3279406 0.1786746
## 22: standardized 2.9999993 -0.07512520 -0.3292713 0.1790209
## 23: standardized 3.1428564 -0.07561737 -0.3309762 0.1797414
## 24: standardized 3.2857134 -0.07610954 -0.3330500 0.1808309
## 25: standardized 3.4285705 -0.07660171 -0.3354860 0.1822825
## 26: standardized 3.5714276 -0.07709389 -0.3382760 0.1840882
## 27: standardized 3.7142847 -0.07758606 -0.3414109 0.1862388
## 28: standardized 3.8571417 -0.07807824 -0.3448803 0.1887239
## 29: standardized 3.9999990 -0.07857041 -0.3486733 0.1915325
## 30: standardized 4.1428561 -0.07906259 -0.3527781 0.1946529
## 31: standardized 4.2857132 -0.07955476 -0.3571825 0.1980730
## 32: standardized 4.4285703 -0.08004693 -0.3618741 0.2017802
## 33: standardized 4.5714273 -0.08053911 -0.3668402 0.2057620
## 34: standardized 4.7142844 -0.08103128 -0.3720682 0.2100056
## 35: standardized 4.8571415 -0.08152346 -0.3775454 0.2144985
## 36: standardized 4.9999986 -0.08201563 -0.3832596 0.2192284
## 37: standardized 5.1428556 -0.08250780 -0.3891986 0.2241830
## 38: standardized 5.2857127 -0.08299997 -0.3953507 0.2293507
## 39: standardized 5.4285698 -0.08349215 -0.4017044 0.2347201
## 40: standardized 5.5714269 -0.08398432 -0.4082489 0.2402803
## 41: standardized 5.7142839 -0.08447650 -0.4149737 0.2460207
## 42: standardized 5.8571415 -0.08496867 -0.4218688 0.2519314
## 43: standardized 5.9999986 -0.08546084 -0.4289246 0.2580029
##             Type      Time    Estimate         LL        UL

9 Actigraphy - TST

tstactidat <- na.omit(ds2[, .(ID, Time, dstrat4, dcond, TSTacti)])

tstactifit <- mplusModeler(mplusObject(
  TITLE = "Actigraphy TST Analysis;",
  VARIABLE = "
    WITHIN = Time;
    BETWEEN = dstrat4 dcond;
    CLUSTER = ID;",
  ANALYSIS = "
   ESTIMATOR = ML;
   TYPE = TWOLEVEL RANDOM;
   PROCESSORS = 2;
   STARTS = 50 5;
   STITERATIONS = 200;
   MITERATIONS = 10000;
   MCONVERGENCE  = .000001;
",
  MODEL = "
  %WITHIN%
  s | TSTacti ON Time;
  TSTacti* (resvar);
  %BETWEEN%
  TSTacti ON dstrat4 dcond (i3 - i4);
  s ON dcond (s1);
  TSTacti WITH s*;
  TSTacti* s* (vi vs);
  [TSTacti* s*] (mi ms);
",
  OUTPUT = "CINTERVAL;",
  PLOT = "TYPE = PLOT2;",
  MODELCONSTRAINT = sprintf(
    mcsetup,
    mean(tstactidat$dstrat4)),
  usevariables = c("ID", "Time", "TSTacti",
                   "dstrat4", "dcond"),
  rdata = as.data.frame(tstactidat)),
  dataout = "04_HighISI_tstacti.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 04_HighISI_tstacti.inp
## Wrote data to: 04_HighISI_tstacti.dat
## model information, coefficients, and effect sizes
tstactiout <- cbind(
  coef(tstactifit, param = c("reg", "exp", "new")),
  round(confint(tstactifit, param = c("reg", "exp", "new"))[,-1], 2))[, c(1, 2, 5, 6, 4)]
with(tstactiout,
     data.frame(
       Label = Label,
       Out = sprintf("%0.2f (%0.2f, %0.2f)", round(est, 2), LowerCI, UpperCI),
       pval = formatPval(pval, d = 3, sd = 3)))
##                    Label                  Out   pval
## 1             B S<-DCOND -0.11 (-0.20, -0.02)   .019
## 2     B TSTACTI<-DSTRAT4   0.28 (-0.17, 0.74)   .226
## 3       B TSTACTI<-DCOND   0.42 (-0.11, 0.96)   .122
## 4  B TSTACTI<-Intercepts    6.81 (6.36, 7.26) < .001
## 5        B S<-Intercepts   0.06 (-0.01, 0.12)   .083
## 6                 B ITAU    6.96 (6.56, 7.35) < .001
## 7                 B ICBT    7.38 (7.01, 7.74) < .001
## 8                B IDIFF   0.42 (-0.11, 0.96)   .122
## 9                 B STAU   0.06 (-0.01, 0.12)   .083
## 10                B SCBT  -0.05 (-0.12, 0.01)   .113
## 11               B SDIFF -0.11 (-0.20, -0.02)   .019
tstactiplot <- data.table(
  Condition = rep(c("TAU+", "CBT-I+Light"), each = 43),
  Time = c(tstactifit$results$gh5$loop_data$xvalues, tstactifit$results$gh5$loop_data$xvalues),
  Estimate = c(tstactifit$results$gh5$loop_data$estimates[1, ], tstactifit$results$gh5$loop_data$estimates[2, ]),
  LL = c(tstactifit$results$gh5$loop_data$lowerci[1, ], tstactifit$results$gh5$loop_data$lowerci[2, ]),
  UL = c(tstactifit$results$gh5$loop_data$upperci[1, ], tstactifit$results$gh5$loop_data$upperci[2, ]))

p.tstacti <- ggplot(tstactiplot, aes(Time, Estimate, ymin = LL, ymax = UL,
                                     colour = Condition, fill = Condition)) +
  scale_y_continuous("TST (Acti)", breaks = seq(6.6,8,0.2)) +
  annotate("text", x = 2, y = 7.4, label = sprintf("CBT-I+Light slope %s", formatPval(subset(tstactiout, Label == "B SCBT")$pval, d = 3, sd = 3, includeP = TRUE))) +
  annotate("text", x = 2, y = 6.8, label = sprintf("TAU+ slope %s", formatPval(subset(tstactiout, Label == "B STAU")$pval, d = 3, sd = 3, includeP = TRUE))) +
  dailysleepStyle
print(p.tstacti)

tstactidiffplot <- with(tstactifit$results$gh5$loop_data, data.table(
  Type = rep(c("Raw", "standardized"), each = 43),
  Time = c(xvalues, xvalues),
  Estimate = c(estimates[3, ], estimates[4, ]),
  LL = c(lowerci[3, ], lowerci[4, ]),
  UL = c(upperci[3, ], upperci[4, ])))

tstactidiffplot[Type == "Raw"]
##     Type      Time     Estimate         LL        UL
##  1:  Raw 0.0000000  0.421360403 -0.1127384 0.9554592
##  2:  Raw 0.1428571  0.405518442 -0.1218730 0.9329098
##  3:  Raw 0.2857142  0.389676481 -0.1312558 0.9106088
##  4:  Raw 0.4285713  0.373834521 -0.1408963 0.8885654
##  5:  Raw 0.5714284  0.357992560 -0.1508039 0.8667890
##  6:  Raw 0.7142855  0.342150599 -0.1609881 0.8452893
##  7:  Raw 0.8571426  0.326308668 -0.1714582 0.8240755
##  8:  Raw 0.9999998  0.310466707 -0.1822236 0.8031570
##  9:  Raw 1.1428568  0.294624746 -0.1932937 0.7825432
## 10:  Raw 1.2857139  0.278782785 -0.2046773 0.7622429
## 11:  Raw 1.4285710  0.262940824 -0.2163832 0.7422648
## 12:  Raw 1.5714282  0.247098878 -0.2284198 0.7226176
## 13:  Raw 1.7142853  0.231256917 -0.2407952 0.7033090
## 14:  Raw 1.8571423  0.215414971 -0.2535168 0.6843467
## 15:  Raw 1.9999995  0.199573010 -0.2665915 0.6657376
## 16:  Raw 2.1428566  0.183731049 -0.2800259 0.6474879
## 17:  Raw 2.2857137  0.167889103 -0.2938253 0.6296035
## 18:  Raw 2.4285707  0.152047142 -0.3079948 0.6120890
## 19:  Raw 2.5714278  0.136205181 -0.3225383 0.5949486
## 20:  Raw 2.7142849  0.120363228 -0.3374590 0.5781854
## 21:  Raw 2.8571420  0.104521275 -0.3527592 0.5618018
## 22:  Raw 2.9999993  0.088679321 -0.3684404 0.5457990
## 23:  Raw 3.1428564  0.072837368 -0.3845027 0.5301775
## 24:  Raw 3.2857134  0.056995407 -0.4009458 0.5149366
## 25:  Raw 3.4285705  0.041153453 -0.4177681 0.5000750
## 26:  Raw 3.5714276  0.025311496 -0.4349672 0.4855902
## 27:  Raw 3.7142847  0.009469541 -0.4525398 0.4714789
## 28:  Raw 3.8571417 -0.006372415 -0.4704817 0.4577368
## 29:  Raw 3.9999990 -0.022214370 -0.4887879 0.4443591
## 30:  Raw 4.1428561 -0.038056325 -0.5074526 0.4313399
## 31:  Raw 4.2857132 -0.053898282 -0.5264695 0.4186729
## 32:  Raw 4.4285703 -0.069740236 -0.5458315 0.4063510
## 33:  Raw 4.5714273 -0.085582197 -0.5655310 0.3943666
## 34:  Raw 4.7142844 -0.101424150 -0.5855600 0.3827116
## 35:  Raw 4.8571415 -0.117266104 -0.6059099 0.3713776
## 36:  Raw 4.9999986 -0.133108065 -0.6265720 0.3603558
## 37:  Raw 5.1428556 -0.148950011 -0.6475372 0.3496371
## 38:  Raw 5.2857127 -0.164791971 -0.6687962 0.3392123
## 39:  Raw 5.4285698 -0.180633932 -0.6903399 0.3290720
## 40:  Raw 5.5714269 -0.196475878 -0.7121586 0.3192068
## 41:  Raw 5.7142839 -0.212317839 -0.7342429 0.3096071
## 42:  Raw 5.8571415 -0.228159800 -0.7565833 0.3002637
## 43:  Raw 5.9999986 -0.244001746 -0.7791707 0.2911672
##     Type      Time     Estimate         LL        UL
tstactidiffplot[Type == "standardized"]
##             Type      Time     Estimate          LL        UL
##  1: standardized 0.0000000  0.300521731 -0.08123842 0.6822819
##  2: standardized 0.1428571  0.289222986 -0.08770418 0.6661502
##  3: standardized 0.2857142  0.277924210 -0.09434766 0.6501961
##  4: standardized 0.4285713  0.266625464 -0.10117560 0.6344265
##  5: standardized 0.5714284  0.255326688 -0.10819481 0.6188481
##  6: standardized 0.7142855  0.244027913 -0.11541211 0.6034679
##  7: standardized 0.8571426  0.232729152 -0.12283433 0.5882927
##  8: standardized 0.9999998  0.221430391 -0.13046825 0.5733290
##  9: standardized 1.1428568  0.210131615 -0.13832054 0.5585838
## 10: standardized 1.2857139  0.198832855 -0.14639774 0.5440634
## 11: standardized 1.4285710  0.187534094 -0.15470621 0.5297744
## 12: standardized 1.5714282  0.176235333 -0.16325204 0.5157227
## 13: standardized 1.7142853  0.164936557 -0.17204109 0.5019142
## 14: standardized 1.8571423  0.153637797 -0.18107878 0.4883544
## 15: standardized 1.9999995  0.142339036 -0.19037022 0.4750483
## 16: standardized 2.1428566  0.131040260 -0.19992000 0.4620005
## 17: standardized 2.2857137  0.119741499 -0.20973223 0.4492152
## 18: standardized 2.4285707  0.108442731 -0.21981052 0.4366960
## 19: standardized 2.5714278  0.097143970 -0.23015779 0.4244457
## 20: standardized 2.7142849  0.085845202 -0.24077643 0.4124669
## 21: standardized 2.8571420  0.074546441 -0.25166813 0.4007610
## 22: standardized 2.9999993  0.063247673 -0.26283389 0.3893293
## 23: standardized 3.1428564  0.051948909 -0.27427408 0.3781719
## 24: standardized 3.2857134  0.040650140 -0.28598833 0.3672886
## 25: standardized 3.4285705  0.029351376 -0.29797557 0.3566783
## 26: standardized 3.5714276  0.018052612 -0.31023413 0.3463393
## 27: standardized 3.7142847  0.006753846 -0.32276160 0.3362693
## 28: standardized 3.8571417 -0.004544920 -0.33555499 0.3264652
## 29: standardized 3.9999990 -0.015843686 -0.34861073 0.3169234
## 30: standardized 4.1428561 -0.027142450 -0.36192471 0.3076398
## 31: standardized 4.2857132 -0.038441215 -0.37549224 0.2986098
## 32: standardized 4.4285703 -0.049739983 -0.38930827 0.2898283
## 33: standardized 4.5714273 -0.061038747 -0.40336734 0.2812898
## 34: standardized 4.7142844 -0.072337516 -0.41766360 0.2729886
## 35: standardized 4.8571415 -0.083636276 -0.43219095 0.2649184
## 36: standardized 4.9999986 -0.094935045 -0.44694299 0.2570729
## 37: standardized 5.1428556 -0.106233805 -0.46191320 0.2494456
## 38: standardized 5.2857127 -0.117532574 -0.47709489 0.2420298
## 39: standardized 5.4285698 -0.128831342 -0.49248132 0.2348186
## 40: standardized 5.5714269 -0.140130103 -0.50806558 0.2278054
## 41: standardized 5.7142839 -0.151428863 -0.52384096 0.2209832
## 42: standardized 5.8571415 -0.162727639 -0.53980058 0.2143453
## 43: standardized 5.9999986 -0.174026400 -0.55593771 0.2078849
##             Type      Time     Estimate          LL        UL

10 Final Panel Plot

p.all <- ggarrange(
  p.ses, p.seacti, p.sol, p.solacti, p.waso, p.wasoacti, p.tst, p.tstacti,
  labels = c("A", "B", "C", "D", "E", "F", "G", "H"),
  ncol=2, nrow=4,
  legend = "bottom",
  common.legend = TRUE)

print(p.all)

pdf(file = "04_HighISI_sleepdiaryacti_figure_6.pdf", width = 11, height = 12)
print(p.all)
dev.off()
## png 
##   2

11 Session Info for Documentation

sessionInfo()
## R version 4.1.0 (2021-05-18)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19043)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_United States.1252 
## [2] LC_CTYPE=English_United States.1252   
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] MplusAutomation_0.8 data.table_1.14.0   reshape2_1.4.4     
## [4] JWileymisc_1.2.1    ggpubr_0.4.0        ggplot2_3.3.3      
## [7] rmarkdown_2.8       knitr_1.33         
## 
## loaded via a namespace (and not attached):
##   [1] TH.data_1.0-10       VGAM_1.1-5           minqa_1.2.4         
##   [4] colorspace_2.0-1     ggsignif_0.6.1       ellipsis_0.3.2      
##   [7] rio_0.5.26           estimability_1.3     htmlTable_2.2.1     
##  [10] base64enc_0.1-3      rstudioapi_0.13      mice_3.13.0         
##  [13] farver_2.1.0         lavaan_0.6-8         MatrixModels_0.5-0  
##  [16] fansi_0.5.0          mvtnorm_1.1-1        codetools_0.2-18    
##  [19] splines_4.1.0        mnormt_2.0.2         robustbase_0.93-7   
##  [22] texreg_1.37.5        Formula_1.2-4        jsonlite_1.7.2      
##  [25] nloptr_1.2.2.2       broom_0.7.6          cluster_2.1.2       
##  [28] png_0.1-7            httr_1.4.2           compiler_4.1.0      
##  [31] emmeans_1.6.0        backports_1.2.1      assertthat_0.2.1    
##  [34] Matrix_1.3-3         htmltools_0.5.1.1    quantreg_5.85       
##  [37] tools_4.1.0          coda_0.19-4          gtable_0.3.0        
##  [40] glue_1.4.2           dplyr_1.0.6          ggthemes_4.2.4      
##  [43] Rcpp_1.0.6           carData_3.0-4        cellranger_1.1.0    
##  [46] jquerylib_0.1.4      rhdf5filters_1.4.0   vctrs_0.3.8         
##  [49] nlme_3.1-152         conquer_1.0.2        psych_2.1.3         
##  [52] xfun_0.23            stringr_1.4.0        proto_1.0.0         
##  [55] openxlsx_4.2.3       lme4_1.1-27          lifecycle_1.0.0     
##  [58] extraoperators_0.1.1 rstatix_0.7.0        polspline_1.1.19    
##  [61] DEoptimR_1.0-9       MASS_7.3-54          zoo_1.8-9           
##  [64] scales_1.1.1         hms_1.1.0            parallel_4.1.0      
##  [67] sandwich_3.0-1       rhdf5_2.36.0         SparseM_1.81        
##  [70] RColorBrewer_1.1-2   yaml_2.2.1           curl_4.3.1          
##  [73] gridExtra_2.3        pander_0.6.3         sass_0.4.0          
##  [76] rms_6.2-0            rpart_4.1-15         latticeExtra_0.6-29 
##  [79] stringi_1.6.2        highr_0.9            checkmate_2.0.0     
##  [82] boot_1.3-28          zip_2.1.1            rlang_0.4.11        
##  [85] pkgconfig_2.0.3      matrixStats_0.58.0   evaluate_0.14       
##  [88] lattice_0.20-44      Rhdf5lib_1.14.0      purrr_0.3.4         
##  [91] labeling_0.4.2       htmlwidgets_1.5.3    cowplot_1.1.1       
##  [94] tidyselect_1.1.1     ggsci_2.9            plyr_1.8.6          
##  [97] magrittr_2.0.1       R6_2.5.0             generics_0.1.0      
## [100] multcompView_0.1-8   Hmisc_4.5-0          multcomp_1.4-17     
## [103] DBI_1.1.1            gsubfn_0.7           pillar_1.6.1        
## [106] haven_2.4.1          foreign_0.8-81       withr_2.4.2         
## [109] mgcv_1.8-35          survival_3.2-11      abind_1.4-5         
## [112] nnet_7.3-16          tibble_3.1.2         crayon_1.4.1        
## [115] car_3.0-10           utf8_1.2.1           tmvnsim_1.0-2       
## [118] jpeg_0.1-8.1         grid_4.1.0           readxl_1.3.1        
## [121] pbivnorm_0.6.0       forcats_0.5.1        digest_0.6.27       
## [124] xtable_1.8-4         tidyr_1.1.3          stats4_4.1.0        
## [127] munsell_0.5.0        bslib_0.2.5.1