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 high stage (>= 3) cancer at screening
## note that this means we cannot use dstrat1 or dstrat3
## as those only occur in women with stage 1 or 2
ds2 <- d.s2[baseline_stage_high == "Stage >= 3"]
## Error in eval(expr, envir, enclos): object 'd.s2' not found
## 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 = "07_AdvancedStage_ses.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 07_AdvancedStage_ses.inp
## Wrote data to: 07_AdvancedStage_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.51 (-1.56, 0.54)   .338
## 2     B SESTRANS<-DSTRAT4   0.86 (-5.43, 7.16)   .788
## 3       B SESTRANS<-DCOND  5.72 (-0.58, 12.01)   .075
## 4  B SESTRANS<-Intercepts 43.24 (38.10, 48.39) < .001
## 5         B S<-Intercepts    1.48 (0.74, 2.21) < .001
## 6                  B ITAU 43.55 (38.89, 48.22) < .001
## 7                  B ICBT 49.27 (45.05, 53.49) < .001
## 8                 B IDIFF  5.72 (-0.58, 12.01)   .075
## 9                  B STAU    1.48 (0.74, 2.21) < .001
## 10                 B SCBT    0.96 (0.22, 1.71)   .012
## 11                B SDIFF  -0.51 (-1.56, 0.54)   .338
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.715630 -0.5772660 12.00852
##  2:  Raw    1 5.642389 -0.6128169 11.89760
##  3:  Raw    2 5.569149 -0.6517463 11.79004
##  4:  Raw    3 5.495909 -0.6941105 11.68593
##  5:  Raw    4 5.422668 -0.7399608 11.58530
##  6:  Raw    5 5.349428 -0.7893443 11.48820
##  7:  Raw    6 5.276188 -0.8423021 11.39468
##  8:  Raw    7 5.202948 -0.8988698 11.30477
##  9:  Raw    8 5.129707 -0.9590771 11.21849
## 10:  Raw    9 5.056467 -1.0229475 11.13588
## 11:  Raw   10 4.983227 -1.0904979 11.05695
## 12:  Raw   11 4.909987 -1.1617385 10.98171
## 13:  Raw   12 4.836747 -1.2366731 10.91017
## 14:  Raw   13 4.763506 -1.3152987 10.84231
## 15:  Raw   14 4.690266 -1.3976052 10.77814
## 16:  Raw   15 4.617026 -1.4835764 10.71763
## 17:  Raw   16 4.543786 -1.5731895 10.66076
## 18:  Raw   17 4.470545 -1.6664152 10.60751
## 19:  Raw   18 4.397305 -1.7632184 10.55783
## 20:  Raw   19 4.324065 -1.8635582 10.51169
## 21:  Raw   20 4.250825 -1.9673883 10.46904
## 22:  Raw   21 4.177585 -2.0746577 10.42983
## 23:  Raw   22 4.104344 -2.1853104 10.39400
## 24:  Raw   23 4.031104 -2.2992861 10.36149
## 25:  Raw   24 3.957864 -2.4165218 10.33225
## 26:  Raw   25 3.884624 -2.5369501 10.30620
## 27:  Raw   26 3.811383 -2.6605010 10.28327
## 28:  Raw   27 3.738143 -2.7871027 10.26339
## 29:  Raw   28 3.664903 -2.9166806 10.24649
## 30:  Raw   29 3.591663 -3.0491590 10.23248
## 31:  Raw   30 3.518423 -3.1844614 10.22131
## 32:  Raw   31 3.445182 -3.3225095 10.21287
## 33:  Raw   32 3.371942 -3.4632258 10.20711
## 34:  Raw   33 3.298702 -3.6065319 10.20394
## 35:  Raw   34 3.225461 -3.7523494 10.20327
## 36:  Raw   35 3.152221 -3.9006011 10.20504
## 37:  Raw   36 3.078981 -4.0512104 10.20917
## 38:  Raw   37 3.005741 -4.2041006 10.21558
## 39:  Raw   38 2.932501 -4.3591981 10.22420
## 40:  Raw   39 2.859260 -4.5164285 10.23495
## 41:  Raw   40 2.786020 -4.6757202 10.24776
## 42:  Raw   41 2.712780 -4.8370023 10.26256
## 43:  Raw   42 2.639540 -5.0002065 10.27929
##     Type Time Estimate         LL       UL
sesdiffplot[Type == "standardized"]
##             Type Time  Estimate          LL        UL
##  1: standardized    0 0.2765824 -0.02899887 0.5821636
##  2: standardized    1 0.2730382 -0.03069925 0.5767757
##  3: standardized    2 0.2694941 -0.03256266 0.5715509
##  4: standardized    3 0.2659500 -0.03459182 0.5664918
##  5: standardized    4 0.2624058 -0.03678925 0.5616009
##  6: standardized    5 0.2588617 -0.03915724 0.5568807
##  7: standardized    6 0.2553176 -0.04169782 0.5523329
##  8: standardized    7 0.2517734 -0.04441272 0.5479596
##  9: standardized    8 0.2482293 -0.04730343 0.5437620
## 10: standardized    9 0.2446852 -0.05037111 0.5397415
## 11: standardized   10 0.2411410 -0.05361663 0.5358987
## 12: standardized   11 0.2375969 -0.05704051 0.5322343
## 13: standardized   12 0.2340528 -0.06064298 0.5287485
## 14: standardized   13 0.2305086 -0.06442393 0.5254412
## 15: standardized   14 0.2269645 -0.06838294 0.5223119
## 16: standardized   15 0.2234204 -0.07251926 0.5193600
## 17: standardized   16 0.2198762 -0.07683181 0.5165843
## 18: standardized   17 0.2163321 -0.08131924 0.5139834
## 19: standardized   18 0.2127880 -0.08597990 0.5115559
## 20: standardized   19 0.2092438 -0.09081184 0.5092995
## 21: standardized   20 0.2056997 -0.09581287 0.5072123
## 22: standardized   21 0.2021556 -0.10098056 0.5052917
## 23: standardized   22 0.1986114 -0.10631225 0.5035351
## 24: standardized   23 0.1950673 -0.11180506 0.5019397
## 25: standardized   24 0.1915232 -0.11745595 0.5005023
## 26: standardized   25 0.1879790 -0.12326171 0.4992198
## 27: standardized   26 0.1844349 -0.12921898 0.4980888
## 28: standardized   27 0.1808908 -0.13532431 0.4971058
## 29: standardized   28 0.1773466 -0.14157411 0.4962674
## 30: standardized   29 0.1738025 -0.14796476 0.4955697
## 31: standardized   30 0.1702584 -0.15449256 0.4950093
## 32: standardized   31 0.1667142 -0.16115372 0.4945822
## 33: standardized   32 0.1631701 -0.16794452 0.4942847
## 34: standardized   33 0.1596259 -0.17486116 0.4941131
## 35: standardized   34 0.1560818 -0.18189989 0.4940635
## 36: standardized   35 0.1525377 -0.18905696 0.4941323
## 37: standardized   36 0.1489936 -0.19632864 0.4943157
## 38: standardized   37 0.1454494 -0.20371127 0.4946101
## 39: standardized   38 0.1419053 -0.21120124 0.4950118
## 40: standardized   39 0.1383612 -0.21879499 0.4955173
## 41: standardized   40 0.1348170 -0.22648901 0.4961230
## 42: standardized   41 0.1312729 -0.23427990 0.4968257
## 43: standardized   42 0.1277287 -0.24216433 0.4976218
##             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 = "07_AdvancedStage_waso.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 07_AdvancedStage_waso.inp
## Wrote data to: 07_AdvancedStage_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.02 (-0.16, 0.19)   .855
## 2     B WASOSTRANS<-DSTRAT4  -0.58 (-1.75, 0.59)   .333
## 3       B WASOSTRANS<-DCOND  -0.38 (-1.57, 0.80)   .526
## 4  B WASOSTRANS<-Intercepts    5.66 (4.68, 6.64) < .001
## 5           B S<-Intercepts -0.16 (-0.28, -0.03)   .012
## 6                    B ITAU    5.45 (4.57, 6.33) < .001
## 7                    B ICBT    5.07 (4.27, 5.86) < .001
## 8                   B IDIFF  -0.38 (-1.57, 0.80)   .526
## 9                    B STAU -0.16 (-0.28, -0.03)   .012
## 10                   B SCBT -0.14 (-0.27, -0.02)   .026
## 11                  B SDIFF   0.02 (-0.16, 0.19)   .855
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 = 19, 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 = 34, 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.3847120 -1.572405 0.8029811
##  2:  Raw 0.1428571 -0.3823672 -1.563150 0.7984155
##  3:  Raw 0.2857142 -0.3800223 -1.554394 0.7943498
##  4:  Raw 0.4285713 -0.3776774 -1.546147 0.7907922
##  5:  Raw 0.5714284 -0.3753326 -1.538416 0.7877504
##  6:  Raw 0.7142855 -0.3729877 -1.531207 0.7852317
##  7:  Raw 0.8571426 -0.3706428 -1.524528 0.7832426
##  8:  Raw 0.9999998 -0.3682979 -1.518385 0.7817891
##  9:  Raw 1.1428568 -0.3659531 -1.512783 0.7808766
## 10:  Raw 1.2857139 -0.3636082 -1.507726 0.7805097
## 11:  Raw 1.4285710 -0.3612633 -1.503219 0.7806923
## 12:  Raw 1.5714282 -0.3589185 -1.499264 0.7814274
## 13:  Raw 1.7142853 -0.3565736 -1.495865 0.7827175
## 14:  Raw 1.8571423 -0.3542287 -1.493021 0.7845640
## 15:  Raw 1.9999995 -0.3518839 -1.490736 0.7869678
## 16:  Raw 2.1428566 -0.3495390 -1.489007 0.7899287
## 17:  Raw 2.2857137 -0.3471941 -1.487834 0.7934458
## 18:  Raw 2.4285707 -0.3448493 -1.487216 0.7975174
## 19:  Raw 2.5714278 -0.3425044 -1.487150 0.8021410
## 20:  Raw 2.7142849 -0.3401595 -1.487632 0.8073133
## 21:  Raw 2.8571420 -0.3378146 -1.488660 0.8130302
## 22:  Raw 2.9999993 -0.3354698 -1.490227 0.8192871
## 23:  Raw 3.1428564 -0.3331249 -1.492328 0.8260784
## 24:  Raw 3.2857134 -0.3307800 -1.494958 0.8333980
## 25:  Raw 3.4285705 -0.3284352 -1.498109 0.8412392
## 26:  Raw 3.5714276 -0.3260903 -1.501775 0.8495945
## 27:  Raw 3.7142847 -0.3237454 -1.505947 0.8584564
## 28:  Raw 3.8571417 -0.3214006 -1.510617 0.8678162
## 29:  Raw 3.9999990 -0.3190557 -1.515777 0.8776655
## 30:  Raw 4.1428561 -0.3167108 -1.521416 0.8879948
## 31:  Raw 4.2857132 -0.3143660 -1.527527 0.8987949
## 32:  Raw 4.4285703 -0.3120211 -1.534098 0.9100559
## 33:  Raw 4.5714273 -0.3096762 -1.541120 0.9217678
## 34:  Raw 4.7142844 -0.3073313 -1.548583 0.9339204
## 35:  Raw 4.8571415 -0.3049864 -1.556476 0.9465034
## 36:  Raw 4.9999986 -0.3026416 -1.564789 0.9595062
## 37:  Raw 5.1428556 -0.3002967 -1.573512 0.9729183
## 38:  Raw 5.2857127 -0.2979518 -1.582633 0.9867293
## 39:  Raw 5.4285698 -0.2956070 -1.592142 1.0009283
## 40:  Raw 5.5714269 -0.2932621 -1.602029 1.0155051
## 41:  Raw 5.7142839 -0.2909172 -1.612283 1.0304489
## 42:  Raw 5.8571415 -0.2885724 -1.622894 1.0457494
## 43:  Raw 5.9999986 -0.2862275 -1.633851 1.0613965
##     Type      Time   Estimate        LL        UL
wasodiffplot[Type == "standardized"]
##             Type      Time    Estimate         LL        UL
##  1: standardized 0.0000000 -0.10322821 -0.4223554 0.2158989
##  2: standardized 0.1428571 -0.10259902 -0.4198675 0.2146695
##  3: standardized 0.2857142 -0.10196984 -0.4175137 0.2135740
##  4: standardized 0.4285713 -0.10134064 -0.4152960 0.2126147
##  5: standardized 0.5714284 -0.10071146 -0.4132165 0.2117936
##  6: standardized 0.7142855 -0.10008226 -0.4112771 0.2111126
##  7: standardized 0.8571426 -0.09945308 -0.4094798 0.2105736
##  8: standardized 0.9999998 -0.09882389 -0.4078259 0.2101782
##  9: standardized 1.1428568 -0.09819470 -0.4063171 0.2099277
## 10: standardized 1.2857139 -0.09756551 -0.4049545 0.2098235
## 11: standardized 1.4285710 -0.09693632 -0.4037392 0.2098665
## 12: standardized 1.5714282 -0.09630713 -0.4026719 0.2100577
## 13: standardized 1.7142853 -0.09567794 -0.4017535 0.2103976
## 14: standardized 1.8571423 -0.09504876 -0.4009842 0.2108867
## 15: standardized 1.9999995 -0.09441956 -0.4003643 0.2115252
## 16: standardized 2.1428566 -0.09379037 -0.3998938 0.2123130
## 17: standardized 2.2857137 -0.09316118 -0.3995724 0.2132500
## 18: standardized 2.4285707 -0.09253199 -0.3993997 0.2143357
## 19: standardized 2.5714278 -0.09190281 -0.3993750 0.2155694
## 20: standardized 2.7142849 -0.09127361 -0.3994975 0.2169503
## 21: standardized 2.8571420 -0.09064443 -0.3997661 0.2184772
## 22: standardized 2.9999993 -0.09001524 -0.4001795 0.2201490
## 23: standardized 3.1428564 -0.08938605 -0.4007362 0.2219641
## 24: standardized 3.2857134 -0.08875686 -0.4014347 0.2239210
## 25: standardized 3.4285705 -0.08812767 -0.4022731 0.2260178
## 26: standardized 3.5714276 -0.08749848 -0.4032495 0.2282525
## 27: standardized 3.7142847 -0.08686929 -0.4043618 0.2306232
## 28: standardized 3.8571417 -0.08624010 -0.4056077 0.2331275
## 29: standardized 3.9999990 -0.08561091 -0.4069850 0.2357632
## 30: standardized 4.1428561 -0.08498172 -0.4084911 0.2385277
## 31: standardized 4.2857132 -0.08435253 -0.4101236 0.2414186
## 32: standardized 4.4285703 -0.08372334 -0.4118799 0.2444332
## 33: standardized 4.5714273 -0.08309416 -0.4137572 0.2475689
## 34: standardized 4.7142844 -0.08246496 -0.4157528 0.2508228
## 35: standardized 4.8571415 -0.08183578 -0.4178640 0.2541924
## 36: standardized 4.9999986 -0.08120658 -0.4200879 0.2576747
## 37: standardized 5.1428556 -0.08057740 -0.4224217 0.2612669
## 38: standardized 5.2857127 -0.07994821 -0.4248627 0.2649662
## 39: standardized 5.4285698 -0.07931902 -0.4274079 0.2687698
## 40: standardized 5.5714269 -0.07868983 -0.4300545 0.2726748
## 41: standardized 5.7142839 -0.07806064 -0.4327998 0.2766785
## 42: standardized 5.8571415 -0.07743145 -0.4356408 0.2807779
## 43: standardized 5.9999986 -0.07680226 -0.4385750 0.2849705
##             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 = "07_AdvancedStage_sol.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 07_AdvancedStage_sol.inp
## Wrote data to: 07_AdvancedStage_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.10, 0.17)   .592
## 2     B SOLSTRANS<-DSTRAT4   0.50 (-0.26, 1.26)   .197
## 3       B SOLSTRANS<-DCOND  -0.07 (-0.88, 0.73)   .855
## 4  B SOLSTRANS<-Intercepts    4.27 (3.62, 4.92) < .001
## 5          B S<-Intercepts -0.11 (-0.20, -0.01)   .026
## 6                   B ITAU    4.45 (3.86, 5.05) < .001
## 7                   B ICBT    4.38 (3.84, 4.91) < .001
## 8                  B IDIFF  -0.07 (-0.88, 0.73)   .855
## 9                   B STAU -0.11 (-0.20, -0.01)   .026
## 10                  B SCBT  -0.07 (-0.16, 0.02)   .137
## 11                 B SDIFF   0.04 (-0.10, 0.17)   .592
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 = 15, 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 = 22, 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.074795157 -0.8756496 0.7260593
##  2:  Raw 0.1428571 -0.069670729 -0.8627717 0.7234303
##  3:  Raw 0.2857142 -0.064546295 -0.8502655 0.7211729
##  4:  Raw 0.4285713 -0.059421867 -0.8381413 0.7192976
##  5:  Raw 0.5714284 -0.054297436 -0.8264096 0.7178147
##  6:  Raw 0.7142855 -0.049173005 -0.8150806 0.7167346
##  7:  Raw 0.8571426 -0.044048574 -0.8041641 0.7160669
##  8:  Raw 0.9999998 -0.038924143 -0.7936695 0.7158212
##  9:  Raw 1.1428568 -0.033799715 -0.7836061 0.7160066
## 10:  Raw 1.2857139 -0.028675284 -0.7739822 0.7166317
## 11:  Raw 1.4285710 -0.023550853 -0.7648061 0.7177044
## 12:  Raw 1.5714282 -0.018426422 -0.7560849 0.7192321
## 13:  Raw 1.7142853 -0.013301992 -0.7478255 0.7212215
## 14:  Raw 1.8571423 -0.008177562 -0.7400337 0.7236786
## 15:  Raw 1.9999995 -0.003053132 -0.7327147 0.7266084
## 16:  Raw 2.1428566  0.002071299 -0.7258727 0.7300153
## 17:  Raw 2.2857137  0.007195729 -0.7195112 0.7339026
## 18:  Raw 2.4285707  0.012320160 -0.7136325 0.7382728
## 19:  Raw 2.5714278  0.017444590 -0.7082382 0.7431274
## 20:  Raw 2.7142849  0.022569021 -0.7033289 0.7484670
## 21:  Raw 2.8571420  0.027693450 -0.6989041 0.7542910
## 22:  Raw 2.9999993  0.032817882 -0.6949624 0.7605981
## 23:  Raw 3.1428564  0.037942313 -0.6915014 0.7673860
## 24:  Raw 3.2857134  0.043066740 -0.6885179 0.7746513
## 25:  Raw 3.4285705  0.048191171 -0.6860077 0.7823901
## 26:  Raw 3.5714276  0.053315602 -0.6839657 0.7905970
## 27:  Raw 3.7142847  0.058440033 -0.6823862 0.7992663
## 28:  Raw 3.8571417  0.063564464 -0.6812625 0.8083915
## 29:  Raw 3.9999990  0.068688892 -0.6805874 0.8179651
## 30:  Raw 4.1428561  0.073813327 -0.6803527 0.8279794
## 31:  Raw 4.2857132  0.078937754 -0.6805502 0.8384257
## 32:  Raw 4.4285703  0.084062181 -0.6811706 0.8492950
## 33:  Raw 4.5714273  0.089186616 -0.6822048 0.8605780
## 34:  Raw 4.7142844  0.094311044 -0.6836426 0.8722647
## 35:  Raw 4.8571415  0.099435478 -0.6854742 0.8843451
## 36:  Raw 4.9999986  0.104559906 -0.6876890 0.8968088
## 37:  Raw 5.1428556  0.109684333 -0.6902765 0.9096452
## 38:  Raw 5.2857127  0.114808768 -0.6932261 0.9228436
## 39:  Raw 5.4285698  0.119933195 -0.6965271 0.9363934
## 40:  Raw 5.5714269  0.125057623 -0.7001686 0.9502838
## 41:  Raw 5.7142839  0.130182058 -0.7041398 0.9645039
## 42:  Raw 5.8571415  0.135306492 -0.7084303 0.9790432
## 43:  Raw 5.9999986  0.140430912 -0.7130293 0.9938912
##     Type      Time     Estimate         LL        UL
soldiffplot[Type == "standardized"]
##             Type      Time      Estimate         LL        UL
##  1: standardized 0.0000000 -0.0290131867 -0.3396959 0.2816695
##  2: standardized 0.1428571 -0.0270254109 -0.3346987 0.2806479
##  3: standardized 0.2857142 -0.0250376333 -0.3298456 0.2797703
##  4: standardized 0.4285713 -0.0230498575 -0.3251407 0.2790410
##  5: standardized 0.5714284 -0.0210620798 -0.3205880 0.2784638
##  6: standardized 0.7142855 -0.0190743040 -0.3161914 0.2780428
##  7: standardized 0.8571426 -0.0170865282 -0.3119549 0.2777818
##  8: standardized 0.9999998 -0.0150987515 -0.3078820 0.2776845
##  9: standardized 1.1428568 -0.0131109748 -0.3039763 0.2777543
## 10: standardized 1.2857139 -0.0111231981 -0.3002411 0.2779947
## 11: standardized 1.4285710 -0.0091354214 -0.2966795 0.2784087
## 12: standardized 1.5714282 -0.0071476451 -0.2932945 0.2789992
## 13: standardized 1.7142853 -0.0051598689 -0.2900885 0.2797687
## 14: standardized 1.8571423 -0.0031720921 -0.2870639 0.2807197
## 15: standardized 1.9999995 -0.0011843157 -0.2842227 0.2818541
## 16: standardized 2.1428566  0.0008034608 -0.2815666 0.2831735
## 17: standardized 2.2857137  0.0027912373 -0.2790968 0.2846793
## 18: standardized 2.4285707  0.0047790138 -0.2768143 0.2863724
## 19: standardized 2.5714278  0.0067667905 -0.2747198 0.2882534
## 20: standardized 2.7142849  0.0087545672 -0.2728134 0.2903225
## 21: standardized 2.8571420  0.0107423430 -0.2710949 0.2925797
## 22: standardized 2.9999993  0.0127301197 -0.2695639 0.2950242
## 23: standardized 3.1428564  0.0147178965 -0.2682194 0.2976552
## 24: standardized 3.2857134  0.0167056732 -0.2670602 0.3004715
## 25: standardized 3.4285705  0.0186934490 -0.2660846 0.3034714
## 26: standardized 3.5714276  0.0206812266 -0.2652906 0.3066531
## 27: standardized 3.7142847  0.0226690024 -0.2646761 0.3100141
## 28: standardized 3.8571417  0.0246567782 -0.2642384 0.3135520
## 29: standardized 3.9999990  0.0266445559 -0.2639748 0.3172639
## 30: standardized 4.1428561  0.0286323316 -0.2638821 0.3211468
## 31: standardized 4.2857132  0.0306201074 -0.2639571 0.3251973
## 32: standardized 4.4285703  0.0326078832 -0.2641962 0.3294120
## 33: standardized 4.5714273  0.0345956609 -0.2645958 0.3337871
## 34: standardized 4.7142844  0.0365834385 -0.2651521 0.3383190
## 35: standardized 4.8571415  0.0385712124 -0.2658612 0.3430036
## 36: standardized 4.9999986  0.0405589901 -0.2667190 0.3478369
## 37: standardized 5.1428556  0.0425467677 -0.2677214 0.3528149
## 38: standardized 5.2857127  0.0445345454 -0.2688643 0.3579334
## 39: standardized 5.4285698  0.0465223193 -0.2701436 0.3631882
## 40: standardized 5.5714269  0.0485100970 -0.2715550 0.3685752
## 41: standardized 5.7142839  0.0504978746 -0.2730944 0.3740902
## 42: standardized 5.8571415  0.0524856485 -0.2747577 0.3797290
## 43: standardized 5.9999986  0.0544734262 -0.2765407 0.3854876
##             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 = "07_AdvancedStage_tst.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 07_AdvancedStage_tst.inp
## Wrote data to: 07_AdvancedStage_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.07 (-0.15, 0.02)   .120
## 2     B TSTS<-DSTRAT4  0.18 (-0.31, 0.66)   .474
## 3       B TSTS<-DCOND  0.49 (-0.02, 0.99)   .058
## 4  B TSTS<-Intercepts   6.52 (6.12, 6.93) < .001
## 5     B S<-Intercepts   0.13 (0.07, 0.19) < .001
## 6              B ITAU   6.59 (6.21, 6.96) < .001
## 7              B ICBT   7.07 (6.74, 7.41) < .001
## 8             B IDIFF  0.49 (-0.02, 0.99)   .058
## 9              B STAU   0.13 (0.07, 0.19) < .001
## 10             B SCBT  0.06 (-0.00, 0.12)   .052
## 11            B SDIFF -0.07 (-0.15, 0.02)   .120
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.48721710 -0.01557238 0.9900066
##  2:  Raw 0.1428571 0.47753176 -0.02082147 0.9758850
##  3:  Raw 0.2857142 0.46784639 -0.02633253 0.9620253
##  4:  Raw 0.4285713 0.45816106 -0.03211224 0.9484344
##  5:  Raw 0.5714284 0.44847569 -0.03816709 0.9351185
##  6:  Raw 0.7142855 0.43879035 -0.04450325 0.9220839
##  7:  Raw 0.8571426 0.42910498 -0.05112663 0.9093366
##  8:  Raw 0.9999998 0.41941965 -0.05804275 0.8968821
##  9:  Raw 1.1428568 0.40973428 -0.06525673 0.8847253
## 10:  Raw 1.2857139 0.40004894 -0.07277323 0.8728711
## 11:  Raw 1.4285710 0.39036357 -0.08059645 0.8613236
## 12:  Raw 1.5714282 0.38067824 -0.08873002 0.8500865
## 13:  Raw 1.7142853 0.37099287 -0.09717704 0.8391628
## 14:  Raw 1.8571423 0.36130753 -0.10594000 0.8285550
## 15:  Raw 1.9999995 0.35162216 -0.11502077 0.8182651
## 16:  Raw 2.1428566 0.34193683 -0.12442058 0.8082942
## 17:  Raw 2.2857137 0.33225146 -0.13414003 0.7986429
## 18:  Raw 2.4285707 0.32256612 -0.14417905 0.7893113
## 19:  Raw 2.5714278 0.31288075 -0.15453689 0.7802984
## 20:  Raw 2.7142849 0.30319542 -0.16521220 0.7716030
## 21:  Raw 2.8571420 0.29351005 -0.17620297 0.7632231
## 22:  Raw 2.9999993 0.28382471 -0.18750657 0.7551560
## 23:  Raw 3.1428564 0.27413934 -0.19911979 0.7473985
## 24:  Raw 3.2857134 0.26445401 -0.21103889 0.7399469
## 25:  Raw 3.4285705 0.25476864 -0.22325955 0.7327968
## 26:  Raw 3.5714276 0.24508329 -0.23577702 0.7259436
## 27:  Raw 3.7142847 0.23539793 -0.24858607 0.7193819
## 28:  Raw 3.8571417 0.22571258 -0.26168111 0.7131063
## 29:  Raw 3.9999990 0.21602723 -0.27505618 0.7071106
## 30:  Raw 4.1428561 0.20634188 -0.28870502 0.7013888
## 31:  Raw 4.2857132 0.19665653 -0.30262113 0.6959342
## 32:  Raw 4.4285703 0.18697117 -0.31679773 0.6907400
## 33:  Raw 4.5714273 0.17728582 -0.33122793 0.6857996
## 34:  Raw 4.7142844 0.16760047 -0.34590474 0.6811057
## 35:  Raw 4.8571415 0.15791512 -0.36082101 0.6766512
## 36:  Raw 4.9999986 0.14822976 -0.37596956 0.6724291
## 37:  Raw 5.1428556 0.13854441 -0.39134324 0.6684321
## 38:  Raw 5.2857127 0.12885906 -0.40693483 0.6646529
## 39:  Raw 5.4285698 0.11917370 -0.42273727 0.6610847
## 40:  Raw 5.5714269 0.10948835 -0.43874344 0.6577201
## 41:  Raw 5.7142839 0.09980299 -0.45494640 0.6545524
## 42:  Raw 5.8571415 0.09011764 -0.47133932 0.6515746
## 43:  Raw 5.9999986 0.08043229 -0.48791546 0.6487800
##     Type      Time   Estimate          LL        UL
tstdiffplot[Type == "standardized"]
##             Type      Time   Estimate           LL        UL
##  1: standardized 0.0000000 0.28168464 -0.009582931 0.5729522
##  2: standardized 0.1428571 0.27608505 -0.012602559 0.5647726
##  3: standardized 0.2857142 0.27048546 -0.015773434 0.5567443
##  4: standardized 0.4285713 0.26488587 -0.019099439 0.5488712
##  5: standardized 0.5714284 0.25928628 -0.022584325 0.5411569
##  6: standardized 0.7142855 0.25368670 -0.026231695 0.5336050
##  7: standardized 0.8571426 0.24808709 -0.030044969 0.5262192
##  8: standardized 0.9999998 0.24248751 -0.034027364 0.5190024
##  9: standardized 1.1428568 0.23688792 -0.038181860 0.5119577
## 10: standardized 1.2857139 0.23128833 -0.042511184 0.5050879
## 11: standardized 1.4285710 0.22568874 -0.047017779 0.4983953
## 12: standardized 1.5714282 0.22008915 -0.051703785 0.4918821
## 13: standardized 1.7142853 0.21448956 -0.056571014 0.4855502
## 14: standardized 1.8571423 0.20888998 -0.061620940 0.4794009
## 15: standardized 1.9999995 0.20329040 -0.066854678 0.4734355
## 16: standardized 2.1428566 0.19769081 -0.072272971 0.4676546
## 17: standardized 2.2857137 0.19209123 -0.077876195 0.4620586
## 18: standardized 2.4285707 0.18649164 -0.083664335 0.4566476
## 19: standardized 2.5714278 0.18089205 -0.089637019 0.4514211
## 20: standardized 2.7142849 0.17529246 -0.095793471 0.4463784
## 21: standardized 2.8571420 0.16969287 -0.102132574 0.4415183
## 22: standardized 2.9999993 0.16409329 -0.108652830 0.4368394
## 23: standardized 3.1428564 0.15849370 -0.115352422 0.4323398
## 24: standardized 3.2857134 0.15289411 -0.122229189 0.4280174
## 25: standardized 3.4285705 0.14729452 -0.129280686 0.4238697
## 26: standardized 3.5714276 0.14169493 -0.136504173 0.4198940
## 27: standardized 3.7142847 0.13609535 -0.143896654 0.4160873
## 28: standardized 3.8571417 0.13049576 -0.151454911 0.4124464
## 29: standardized 3.9999990 0.12489617 -0.159175515 0.4089679
## 30: standardized 4.1428561 0.11929658 -0.167054862 0.4056480
## 31: standardized 4.2857132 0.11369699 -0.175089180 0.4024832
## 32: standardized 4.4285703 0.10809740 -0.183274597 0.3994694
## 33: standardized 4.5714273 0.10249782 -0.191607118 0.3966027
## 34: standardized 4.7142844 0.09689823 -0.200082675 0.3938791
## 35: standardized 4.8571415 0.09129864 -0.208697170 0.3912944
## 36: standardized 4.9999986 0.08569905 -0.217446461 0.3888445
## 37: standardized 5.1428556 0.08009946 -0.226326376 0.3865253
## 38: standardized 5.2857127 0.07449988 -0.235332772 0.3843325
## 39: standardized 5.4285698 0.06890029 -0.244461536 0.3822621
## 40: standardized 5.5714269 0.06330070 -0.253708571 0.3803100
## 41: standardized 5.7142839 0.05770111 -0.263069808 0.3784721
## 42: standardized 5.8571415 0.05210152 -0.272541344 0.3767444
## 43: standardized 5.9999986 0.04650193 -0.282119244 0.3751231
##             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 = "07_AdvancedStage_seacti.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 07_AdvancedStage_seacti.inp
## Wrote data to: 07_AdvancedStage_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   0.83 (-0.11, 1.76)   .082
## 2     B SEACTITRAN<-DSTRAT4   0.58 (-4.21, 5.36)   .814
## 3       B SEACTITRAN<-DCOND   1.17 (-3.46, 5.81)   .620
## 4  B SEACTITRAN<-Intercepts 44.20 (40.55, 47.84) < .001
## 5           B S<-Intercepts  -0.07 (-0.71, 0.56)   .817
## 6                    B ITAU 44.40 (41.08, 47.73) < .001
## 7                    B ICBT 45.58 (42.35, 48.80) < .001
## 8                   B IDIFF   1.17 (-3.46, 5.81)   .620
## 9                    B STAU  -0.07 (-0.71, 0.56)   .817
## 10                   B SCBT    0.75 (0.07, 1.44)   .032
## 11                  B SDIFF   0.83 (-0.11, 1.76)   .082
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 1.174455 -3.4626534  5.811563
##  2:  Raw 0.1428571 1.292519 -3.3154726  5.900510
##  3:  Raw 0.2857142 1.410583 -3.1719809  5.993146
##  4:  Raw 0.4285713 1.528647 -3.0322399  6.089533
##  5:  Raw 0.5714284 1.646711 -2.8963032  6.189724
##  6:  Raw 0.7142855 1.764774 -2.7642162  6.293765
##  7:  Raw 0.8571426 1.882838 -2.6360145  6.401691
##  8:  Raw 0.9999998 2.000902 -2.5117242  6.513528
##  9:  Raw 1.1428568 2.118966 -2.3913620  6.629293
## 10:  Raw 1.2857139 2.237030 -2.2749331  6.748992
## 11:  Raw 1.4285710 2.355093 -2.1624339  6.872621
## 12:  Raw 1.5714282 2.473157 -2.0538495  7.000164
## 13:  Raw 1.7142853 2.591221 -1.9491554  7.131598
## 14:  Raw 1.8571423 2.709285 -1.8483177  7.266888
## 15:  Raw 1.9999995 2.827349 -1.7512926  7.405990
## 16:  Raw 2.1428566 2.945413 -1.6580280  7.548853
## 17:  Raw 2.2857137 3.063477 -1.5684633  7.695416
## 18:  Raw 2.4285707 3.181540 -1.4825308  7.845612
## 19:  Raw 2.5714278 3.299604 -1.4001559  7.999364
## 20:  Raw 2.7142849 3.417668 -1.3212584  8.156594
## 21:  Raw 2.8571420 3.535732 -1.2457528  8.317216
## 22:  Raw 2.9999993 3.653796 -1.1735492  8.481140
## 23:  Raw 3.1428564 3.771859 -1.1045547  8.648273
## 24:  Raw 3.2857134 3.889923 -1.0386733  8.818520
## 25:  Raw 3.4285705 4.007987 -0.9758072  8.991781
## 26:  Raw 3.5714276 4.126051 -0.9158574  9.167959
## 27:  Raw 3.7142847 4.244115 -0.8587243  9.346954
## 28:  Raw 3.8571417 4.362179 -0.8043082  9.528666
## 29:  Raw 3.9999990 4.480242 -0.7525101  9.712995
## 30:  Raw 4.1428561 4.598306 -0.7032316  9.899844
## 31:  Raw 4.2857132 4.716370 -0.6563761 10.089116
## 32:  Raw 4.4285703 4.834434 -0.6118484 10.280716
## 33:  Raw 4.5714273 4.952498 -0.5695557 10.474551
## 34:  Raw 4.7142844 5.070561 -0.5294071 10.670530
## 35:  Raw 4.8571415 5.188625 -0.4913145 10.868566
## 36:  Raw 4.9999986 5.306689 -0.4551923 11.068571
## 37:  Raw 5.1428556 5.424753 -0.4209575 11.270464
## 38:  Raw 5.2857127 5.542817 -0.3885302 11.474164
## 39:  Raw 5.4285698 5.660881 -0.3578332 11.679595
## 40:  Raw 5.5714269 5.778944 -0.3287922 11.886682
## 41:  Raw 5.7142839 5.897008 -0.3013359 12.095353
## 42:  Raw 5.8571415 6.015072 -0.2753959 12.305540
## 43:  Raw 5.9999986 6.133136 -0.2509064 12.517179
##     Type      Time Estimate         LL        UL
seactidiffplot[Type == "standardized"]
##             Type      Time   Estimate          LL        UL
##  1: standardized 0.0000000 0.08647821 -0.25510553 0.4280619
##  2: standardized 0.1428571 0.09517156 -0.24429497 0.4346381
##  3: standardized 0.2857142 0.10386491 -0.23375836 0.4414882
##  4: standardized 0.4285713 0.11255826 -0.22350021 0.4486167
##  5: standardized 0.5714284 0.12125161 -0.21352440 0.4560276
##  6: standardized 0.7142855 0.12994497 -0.20383421 0.4637241
##  7: standardized 0.8571426 0.13863830 -0.19443220 0.4717088
##  8: standardized 0.9999998 0.14733166 -0.18532018 0.4799835
##  9: standardized 1.1428568 0.15602501 -0.17649929 0.4885493
## 10: standardized 1.2857139 0.16471836 -0.16796984 0.4974066
## 11: standardized 1.4285710 0.17341171 -0.15973142 0.5065548
## 12: standardized 1.5714282 0.18210505 -0.15178281 0.5159929
## 13: standardized 1.7142853 0.19079840 -0.14412209 0.5257189
## 14: standardized 1.8571423 0.19949175 -0.13674662 0.5357301
## 15: standardized 1.9999995 0.20818511 -0.12965304 0.5460232
## 16: standardized 2.1428566 0.21687846 -0.12283739 0.5565943
## 17: standardized 2.2857137 0.22557181 -0.11629508 0.5674387
## 18: standardized 2.4285707 0.23426515 -0.11002098 0.5785513
## 19: standardized 2.5714278 0.24295850 -0.10400949 0.5899265
## 20: standardized 2.7142849 0.25165185 -0.09825457 0.6015583
## 21: standardized 2.8571420 0.26034519 -0.09274981 0.6134402
## 22: standardized 2.9999993 0.26903856 -0.08748850 0.6255656
## 23: standardized 3.1428564 0.27773190 -0.08246368 0.6379275
## 24: standardized 3.2857134 0.28642526 -0.07766821 0.6505187
## 25: standardized 3.4285705 0.29511860 -0.07309480 0.6633320
## 26: standardized 3.5714276 0.30381194 -0.06873608 0.6763600
## 27: standardized 3.7142847 0.31250530 -0.06458465 0.6895952
## 28: standardized 3.8571417 0.32119864 -0.06063311 0.7030304
## 29: standardized 3.9999990 0.32989201 -0.05687411 0.7166581
## 30: standardized 4.1428561 0.33858535 -0.05330038 0.7304711
## 31: standardized 4.2857132 0.34727868 -0.04990476 0.7444621
## 32: standardized 4.4285703 0.35597205 -0.04668020 0.7586243
## 33: standardized 4.5714273 0.36466539 -0.04361985 0.7729506
## 34: standardized 4.7142844 0.37335876 -0.04071699 0.7874345
## 35: standardized 4.8571415 0.38205209 -0.03796512 0.8020693
## 36: standardized 4.9999986 0.39074543 -0.03535791 0.8168488
## 37: standardized 5.1428556 0.39943880 -0.03288927 0.8317668
## 38: standardized 5.2857127 0.40813214 -0.03055328 0.8468176
## 39: standardized 5.4285698 0.41682550 -0.02834427 0.8619953
## 40: standardized 5.5714269 0.42551884 -0.02625677 0.8772945
## 41: standardized 5.7142839 0.43421218 -0.02428553 0.8927099
## 42: standardized 5.8571415 0.44290555 -0.02242551 0.9082366
## 43: standardized 5.9999986 0.45159888 -0.02067187 0.9238697
##             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 = "07_AdvancedStage_wasoacti.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 07_AdvancedStage_wasoacti.inp
## Wrote data to: 07_AdvancedStage_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.14 (-0.28, 0.01)   .060
## 2     B WASOACTITR<-DSTRAT4 -0.09 (-0.86, 0.67)   .810
## 3       B WASOACTITR<-DCOND -0.05 (-0.80, 0.69)   .888
## 4  B WASOACTITR<-Intercepts   7.12 (6.54, 7.71) < .001
## 5           B S<-Intercepts  0.04 (-0.06, 0.14)   .435
## 6                    B ITAU   7.09 (6.56, 7.62) < .001
## 7                    B ICBT   7.04 (6.52, 7.55) < .001
## 8                   B IDIFF -0.05 (-0.80, 0.69)   .888
## 9                    B STAU  0.04 (-0.06, 0.14)   .435
## 10                   B SCBT -0.10 (-0.21, 0.01)   .067
## 11                  B SDIFF -0.14 (-0.28, 0.01)   .060
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.05324878 -0.7963170 0.68981946
##  2:  Raw 0.1428571 -0.07308237 -0.8110871 0.66492242
##  3:  Raw 0.2857142 -0.09291594 -0.8264028 0.64057088
##  4:  Raw 0.4285713 -0.11274953 -0.8422741 0.61677510
##  5:  Raw 0.5714284 -0.13258311 -0.8587103 0.59354407
##  6:  Raw 0.7142855 -0.15241669 -0.8757192 0.57088578
##  7:  Raw 0.8571426 -0.17225029 -0.8933076 0.54880697
##  8:  Raw 0.9999998 -0.19208387 -0.9114808 0.52731311
##  9:  Raw 1.1428568 -0.21191745 -0.9302431 0.50640815
## 10:  Raw 1.2857139 -0.23175102 -0.9495969 0.48609483
## 11:  Raw 1.4285710 -0.25158462 -0.9695435 0.46637431
## 12:  Raw 1.5714282 -0.27141818 -0.9900826 0.44724625
## 13:  Raw 1.7142853 -0.29125178 -1.0112126 0.42870897
## 14:  Raw 1.8571423 -0.31108537 -1.0329300 0.41075930
## 15:  Raw 1.9999995 -0.33091894 -1.0552305 0.39339259
## 16:  Raw 2.1428566 -0.35075253 -1.0781080 0.37660295
## 17:  Raw 2.2857137 -0.37058610 -1.1015553 0.36038315
## 18:  Raw 2.4285707 -0.39041969 -1.1255642 0.34472483
## 19:  Raw 2.5714278 -0.41025329 -1.1501250 0.32961845
## 20:  Raw 2.7142849 -0.43008685 -1.1752272 0.31505349
## 21:  Raw 2.8571420 -0.44992045 -1.2008594 0.30101860
## 22:  Raw 2.9999993 -0.46975401 -1.2270097 0.28750157
## 23:  Raw 3.1428564 -0.48958760 -1.2536647 0.27448955
## 24:  Raw 3.2857134 -0.50942117 -1.2808115 0.26196918
## 25:  Raw 3.4285705 -0.52925479 -1.3084362 0.24992658
## 26:  Raw 3.5714276 -0.54908836 -1.3365242 0.23834759
## 27:  Raw 3.7142847 -0.56892192 -1.3650616 0.22721778
## 28:  Raw 3.8571417 -0.58875555 -1.3940337 0.21652257
## 29:  Raw 3.9999990 -0.60858911 -1.4234256 0.20624737
## 30:  Raw 4.1428561 -0.62842268 -1.4532230 0.19637758
## 31:  Raw 4.2857132 -0.64825624 -1.4834112 0.18689865
## 32:  Raw 4.4285703 -0.66808987 -1.5139760 0.17779626
## 33:  Raw 4.5714273 -0.68792343 -1.5449032 0.16905625
## 34:  Raw 4.7142844 -0.70775700 -1.5761788 0.16066475
## 35:  Raw 4.8571415 -0.72759062 -1.6077894 0.15260814
## 36:  Raw 4.9999986 -0.74742419 -1.6397215 0.14487319
## 37:  Raw 5.1428556 -0.76725775 -1.6719625 0.13744697
## 38:  Raw 5.2857127 -0.78709137 -1.7044997 0.13031697
## 39:  Raw 5.4285698 -0.80692494 -1.7373209 0.12347106
## 40:  Raw 5.5714269 -0.82675850 -1.7704145 0.11689749
## 41:  Raw 5.7142839 -0.84659213 -1.8037691 0.11058496
## 42:  Raw 5.8571415 -0.86642569 -1.8373740 0.10452256
## 43:  Raw 5.9999986 -0.88625926 -1.8712183 0.09869979
##     Type      Time    Estimate         LL         UL
wasoactidiffplot[Type == "standardized"]
##             Type      Time    Estimate         LL         UL
##  1: standardized 0.0000000 -0.02333493 -0.3489954 0.30232558
##  2: standardized 0.1428571 -0.03202650 -0.3554824 0.29142943
##  3: standardized 0.2857142 -0.04071807 -0.3622103 0.28077418
##  4: standardized 0.4285713 -0.04940963 -0.3691835 0.27036425
##  5: standardized 0.5714284 -0.05810120 -0.3764060 0.26020366
##  6: standardized 0.7142855 -0.06679276 -0.3838814 0.25029582
##  7: standardized 0.8571426 -0.07548434 -0.3916123 0.24064367
##  8: standardized 0.9999998 -0.08417590 -0.3996013 0.23124954
##  9: standardized 1.1428568 -0.09286746 -0.4078501 0.22211517
## 10: standardized 1.2857139 -0.10155904 -0.4163597 0.21324165
## 11: standardized 1.4285710 -0.11025060 -0.4251306 0.20462944
## 12: standardized 1.5714282 -0.11894216 -0.4341626 0.19627832
## 13: standardized 1.7142853 -0.12763374 -0.4434549 0.18818747
## 14: standardized 1.8571423 -0.13632530 -0.4530060 0.18035538
## 15: standardized 1.9999995 -0.14501686 -0.4628137 0.17277999
## 16: standardized 2.1428566 -0.15370843 -0.4728754 0.16545857
## 17: standardized 2.2857137 -0.16240001 -0.4831879 0.15838788
## 18: standardized 2.4285707 -0.17109157 -0.4937473 0.15156417
## 19: standardized 2.5714278 -0.17978314 -0.5045494 0.14498313
## 20: standardized 2.7142849 -0.18847470 -0.5155895 0.13864008
## 21: standardized 2.8571420 -0.19716626 -0.5268625 0.13252994
## 22: standardized 2.9999993 -0.20585783 -0.5383630 0.12664729
## 23: standardized 3.1428564 -0.21454941 -0.5500852 0.12098641
## 24: standardized 3.2857134 -0.22324097 -0.5620233 0.11554135
## 25: standardized 3.4285705 -0.23193254 -0.5741710 0.11030596
## 26: standardized 3.5714276 -0.24062410 -0.5865222 0.10527397
## 27: standardized 3.7142847 -0.24931566 -0.5990703 0.10043898
## 28: standardized 3.8571417 -0.25800723 -0.6118090 0.09579457
## 29: standardized 3.9999990 -0.26669881 -0.6247318 0.09133425
## 30: standardized 4.1428561 -0.27539036 -0.6378323 0.08705159
## 31: standardized 4.2857132 -0.28408194 -0.6511040 0.08294018
## 32: standardized 4.4285703 -0.29277351 -0.6645407 0.07899369
## 33: standardized 4.5714273 -0.30146506 -0.6781361 0.07520590
## 34: standardized 4.7142844 -0.31015664 -0.6918839 0.07157068
## 35: standardized 4.8571415 -0.31884819 -0.7057785 0.06808205
## 36: standardized 4.9999986 -0.32753977 -0.7198137 0.06473418
## 37: standardized 5.1428556 -0.33623132 -0.7339841 0.06152141
## 38: standardized 5.2857127 -0.34492290 -0.7482840 0.05843822
## 39: standardized 5.4285698 -0.35361448 -0.7627082 0.05547927
## 40: standardized 5.5714269 -0.36230603 -0.7772515 0.05263944
## 41: standardized 5.7142839 -0.37099761 -0.7919089 0.04991373
## 42: standardized 5.8571415 -0.37968916 -0.8066757 0.04729738
## 43: standardized 5.9999986 -0.38838074 -0.8215473 0.04478579
##             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.139 0.074 0.060  -0.283   0.006
## 3     B WASOACTITR<-DSTRAT4 -0.094 0.390 0.810  -0.858   0.671
## 4       B WASOACTITR<-DCOND -0.053 0.379 0.888  -0.796   0.690
## 6  B WASOACTITR<-Intercepts  7.124 0.298 0.000   6.541   7.707
## 7           B S<-Intercepts  0.039 0.050 0.435  -0.059   0.137
## 10                   B ITAU  7.091 0.272 0.000   6.558   7.623
## 11                   B ICBT  7.037 0.264 0.000   6.520   7.554
## 12                  B IDIFF -0.053 0.379 0.888  -0.796   0.690
## 13                   B STAU  0.039 0.050 0.435  -0.059   0.137
## 14                   B SCBT -0.100 0.054 0.067  -0.206   0.007
## 15                  B SDIFF -0.139 0.074 0.060  -0.283   0.006

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 = "07_AdvancedStage_solacti.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 07_AdvancedStage_solacti.inp
## Wrote data to: 07_AdvancedStage_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.04 (-0.12, 0.03)   .259
## 2     B SOLACTITRA<-DSTRAT4  0.19 (-0.14, 0.52)   .254
## 3       B SOLACTITRA<-DCOND  0.02 (-0.34, 0.37)   .919
## 4  B SOLACTITRA<-Intercepts   1.31 (1.04, 1.58) < .001
## 5           B S<-Intercepts  0.00 (-0.05, 0.05)   .977
## 6                    B ITAU   1.38 (1.12, 1.63) < .001
## 7                    B ICBT   1.40 (1.15, 1.64) < .001
## 8                   B IDIFF  0.02 (-0.34, 0.37)   .919
## 9                    B STAU  0.00 (-0.05, 0.05)   .977
## 10                   B SCBT -0.04 (-0.10, 0.01)   .132
## 11                  B SDIFF -0.04 (-0.12, 0.03)   .259
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.4, 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.4, 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.0184977949 -0.3361454 0.3731410
##  2:  Raw 0.1428571  0.0122301113 -0.3374757 0.3619359
##  3:  Raw 0.2857142  0.0059624282 -0.3390786 0.3510034
##  4:  Raw 0.4285713 -0.0003052555 -0.3409653 0.3403548
##  5:  Raw 0.5714284 -0.0065729390 -0.3431470 0.3300011
##  6:  Raw 0.7142855 -0.0128406221 -0.3456344 0.3199532
##  7:  Raw 0.8571426 -0.0191083066 -0.3484381 0.3102216
##  8:  Raw 0.9999998 -0.0253759902 -0.3515683 0.3008163
##  9:  Raw 1.1428568 -0.0316436738 -0.3550343 0.2917469
## 10:  Raw 1.2857139 -0.0379113555 -0.3588450 0.2830223
## 11:  Raw 1.4285710 -0.0441790409 -0.3630083 0.2746502
## 12:  Raw 1.5714282 -0.0504467227 -0.3675313 0.2666379
## 13:  Raw 1.7142853 -0.0567144081 -0.3724200 0.2589912
## 14:  Raw 1.8571423 -0.0629820898 -0.3776790 0.2517149
## 15:  Raw 1.9999995 -0.0692497715 -0.3833121 0.2448126
## 16:  Raw 2.1428566 -0.0755174607 -0.3893215 0.2382866
## 17:  Raw 2.2857137 -0.0817851424 -0.3957081 0.2321378
## 18:  Raw 2.4285707 -0.0880528241 -0.4024714 0.2263658
## 19:  Raw 2.5714278 -0.0943205059 -0.4096098 0.2209688
## 20:  Raw 2.7142849 -0.1005881950 -0.4171200 0.2159437
## 21:  Raw 2.8571420 -0.1068558767 -0.4249979 0.2112861
## 22:  Raw 2.9999993 -0.1131235585 -0.4332377 0.2069906
## 23:  Raw 3.1428564 -0.1193912402 -0.4418328 0.2030504
## 24:  Raw 3.2857134 -0.1256589293 -0.4507757 0.1994579
## 25:  Raw 3.4285705 -0.1319266111 -0.4600579 0.1962047
## 26:  Raw 3.5714276 -0.1381942928 -0.4696700 0.1932814
## 27:  Raw 3.7142847 -0.1444619745 -0.4796022 0.1906782
## 28:  Raw 3.8571417 -0.1507296562 -0.4898441 0.1883848
## 29:  Raw 3.9999990 -0.1569973379 -0.5003849 0.1863903
## 30:  Raw 4.1428561 -0.1632650197 -0.5112138 0.1846837
## 31:  Raw 4.2857132 -0.1695327163 -0.5223193 0.1832539
## 32:  Raw 4.4285703 -0.1758003980 -0.5336905 0.1820897
## 33:  Raw 4.5714273 -0.1820680797 -0.5453160 0.1811798
## 34:  Raw 4.7142844 -0.1883357614 -0.5571848 0.1805133
## 35:  Raw 4.8571415 -0.1946034431 -0.5692859 0.1800790
## 36:  Raw 4.9999986 -0.2008711249 -0.5816088 0.1798665
## 37:  Raw 5.1428556 -0.2071388066 -0.5941429 0.1798653
## 38:  Raw 5.2857127 -0.2134064883 -0.6068782 0.1800652
## 39:  Raw 5.4285698 -0.2196741849 -0.6198049 0.1804566
## 40:  Raw 5.5714269 -0.2259418666 -0.6329137 0.1810300
## 41:  Raw 5.7142839 -0.2322095484 -0.6461955 0.1817764
## 42:  Raw 5.8571415 -0.2384772301 -0.6596417 0.1826872
## 43:  Raw 5.9999986 -0.2447449118 -0.6732439 0.1837541
##     Type      Time      Estimate         LL        UL
solactidiffplot[Type == "standardized"]
##             Type      Time      Estimate         LL        UL
##  1: standardized 0.0000000  0.0136273215 -0.2476286 0.2748832
##  2: standardized 0.1428571  0.0090099201 -0.2486113 0.2666312
##  3: standardized 0.2857142  0.0043925191 -0.2497955 0.2585805
##  4: standardized 0.4285713 -0.0002248817 -0.2511893 0.2507395
##  5: standardized 0.5714284 -0.0048422827 -0.2528008 0.2431163
##  6: standardized 0.7142855 -0.0094596837 -0.2546382 0.2357188
##  7: standardized 0.8571426 -0.0140770841 -0.2567092 0.2285550
##  8: standardized 0.9999998 -0.0186944846 -0.2590211 0.2216321
##  9: standardized 1.1428568 -0.0233118869 -0.2615810 0.2149573
## 10: standardized 1.2857139 -0.0279292874 -0.2643954 0.2085368
## 11: standardized 1.4285710 -0.0325466879 -0.2674702 0.2023768
## 12: standardized 1.5714282 -0.0371640883 -0.2708103 0.1964822
## 13: standardized 1.7142853 -0.0417814888 -0.2744204 0.1908574
## 14: standardized 1.8571423 -0.0463988893 -0.2783038 0.1855060
## 15: standardized 1.9999995 -0.0510162897 -0.2824632 0.1804306
## 16: standardized 2.1428566 -0.0556336939 -0.2869002 0.1756328
## 17: standardized 2.2857137 -0.0602510944 -0.2916154 0.1711133
## 18: standardized 2.4285707 -0.0648684949 -0.2966086 0.1668716
## 19: standardized 2.5714278 -0.0694858953 -0.3018783 0.1629065
## 20: standardized 2.7142849 -0.0741032958 -0.3074223 0.1592157
## 21: standardized 2.8571420 -0.0787206963 -0.3132372 0.1557958
## 22: standardized 2.9999993 -0.0833380967 -0.3193190 0.1526428
## 23: standardized 3.1428564 -0.0879554972 -0.3256628 0.1497518
## 24: standardized 3.2857134 -0.0925728977 -0.3322628 0.1471170
## 25: standardized 3.4285705 -0.0971902981 -0.3391127 0.1447321
## 26: standardized 3.5714276 -0.1018076986 -0.3462058 0.1425904
## 27: standardized 3.7142847 -0.1064250991 -0.3535347 0.1406845
## 28: standardized 3.8571417 -0.1110425070 -0.3610918 0.1390068
## 29: standardized 3.9999990 -0.1156599075 -0.3688690 0.1375492
## 30: standardized 4.1428561 -0.1202773079 -0.3768583 0.1363037
## 31: standardized 4.2857132 -0.1248947084 -0.3850515 0.1352620
## 32: standardized 4.4285703 -0.1295121014 -0.3934401 0.1344159
## 33: standardized 4.5714273 -0.1341295093 -0.4020160 0.1337570
## 34: standardized 4.7142844 -0.1387469023 -0.4107710 0.1332772
## 35: standardized 4.8571415 -0.1433643103 -0.4196971 0.1329685
## 36: standardized 4.9999986 -0.1479817033 -0.4287864 0.1328230
## 37: standardized 5.1428556 -0.1525991112 -0.4380311 0.1328329
## 38: standardized 5.2857127 -0.1572165191 -0.4474240 0.1329910
## 39: standardized 5.4285698 -0.1618339121 -0.4569577 0.1332899
## 40: standardized 5.5714269 -0.1664513201 -0.4666254 0.1337228
## 41: standardized 5.7142839 -0.1710687131 -0.4764204 0.1342829
## 42: standardized 5.8571415 -0.1756861210 -0.4863363 0.1349641
## 43: standardized 5.9999986 -0.1803035140 -0.4963671 0.1357601
##             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 = "07_AdvancedStage_tstacti.dat", run = TRUE, writeData = "always", hashfilename = FALSE)
## Wrote model to: 07_AdvancedStage_tstacti.inp
## Wrote data to: 07_AdvancedStage_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.04 (-0.13, 0.05)   .400
## 2     B TSTACTI<-DSTRAT4  0.34 (-0.07, 0.76)   .107
## 3       B TSTACTI<-DCOND  0.33 (-0.12, 0.79)   .154
## 4  B TSTACTI<-Intercepts   6.82 (6.47, 7.17) < .001
## 5        B S<-Intercepts  0.01 (-0.05, 0.07)   .704
## 6                 B ITAU   6.94 (6.62, 7.27) < .001
## 7                 B ICBT   7.27 (6.96, 7.59) < .001
## 8                B IDIFF  0.33 (-0.12, 0.79)   .154
## 9                 B STAU  0.01 (-0.05, 0.07)   .704
## 10                B SCBT -0.03 (-0.09, 0.04)   .427
## 11               B SDIFF -0.04 (-0.13, 0.05)   .400
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.3309999 -0.1239621 0.7859620
##  2:  Raw 0.1428571 0.3255581 -0.1236547 0.7747709
##  3:  Raw 0.2857142 0.3201163 -0.1236349 0.7638675
##  4:  Raw 0.4285713 0.3146745 -0.1239134 0.7532625
##  5:  Raw 0.5714284 0.3092327 -0.1245011 0.7429665
##  6:  Raw 0.7142855 0.3037909 -0.1254082 0.7329901
##  7:  Raw 0.8571426 0.2983491 -0.1266451 0.7233434
##  8:  Raw 0.9999998 0.2929073 -0.1282217 0.7140363
##  9:  Raw 1.1428568 0.2874655 -0.1301473 0.7050784
## 10:  Raw 1.2857139 0.2820238 -0.1324309 0.6964784
## 11:  Raw 1.4285710 0.2765819 -0.1350806 0.6882445
## 12:  Raw 1.5714282 0.2711402 -0.1381041 0.6803844
## 13:  Raw 1.7142853 0.2656983 -0.1415079 0.6729046
## 14:  Raw 1.8571423 0.2602566 -0.1452977 0.6658108
## 15:  Raw 1.9999995 0.2548148 -0.1494784 0.6591079
## 16:  Raw 2.1428566 0.2493730 -0.1540536 0.6527995
## 17:  Raw 2.2857137 0.2439312 -0.1590257 0.6468881
## 18:  Raw 2.4285707 0.2384894 -0.1643963 0.6413751
## 19:  Raw 2.5714278 0.2330476 -0.1701655 0.6362607
## 20:  Raw 2.7142849 0.2276058 -0.1763324 0.6315439
## 21:  Raw 2.8571420 0.2221640 -0.1828948 0.6272227
## 22:  Raw 2.9999993 0.2167222 -0.1898494 0.6232938
## 23:  Raw 3.1428564 0.2112804 -0.1971919 0.6197526
## 24:  Raw 3.2857134 0.2058386 -0.2049169 0.6165941
## 25:  Raw 3.4285705 0.2003968 -0.2130181 0.6138117
## 26:  Raw 3.5714276 0.1949550 -0.2214882 0.6113982
## 27:  Raw 3.7142847 0.1895132 -0.2303193 0.6093457
## 28:  Raw 3.8571417 0.1840714 -0.2395027 0.6076456
## 29:  Raw 3.9999990 0.1786296 -0.2490292 0.6062884
## 30:  Raw 4.1428561 0.1731878 -0.2588890 0.6052647
## 31:  Raw 4.2857132 0.1677460 -0.2690721 0.6045641
## 32:  Raw 4.4285703 0.1623042 -0.2795679 0.6041763
## 33:  Raw 4.5714273 0.1568624 -0.2903660 0.6040908
## 34:  Raw 4.7142844 0.1514206 -0.3014555 0.6042967
## 35:  Raw 4.8571415 0.1459788 -0.3128258 0.6047834
## 36:  Raw 4.9999986 0.1405370 -0.3244660 0.6055401
## 37:  Raw 5.1428556 0.1350952 -0.3363656 0.6065561
## 38:  Raw 5.2857127 0.1296534 -0.3485141 0.6078209
## 39:  Raw 5.4285698 0.1242116 -0.3609010 0.6093242
## 40:  Raw 5.5714269 0.1187698 -0.3735163 0.6110560
## 41:  Raw 5.7142839 0.1133280 -0.3863502 0.6130063
## 42:  Raw 5.8571415 0.1078862 -0.3993932 0.6151657
## 43:  Raw 5.9999986 0.1024444 -0.4126359 0.6175248
##     Type      Time  Estimate         LL        UL
tstactidiffplot[Type == "standardized"]
##             Type      Time   Estimate          LL        UL
##  1: standardized 0.0000000 0.23717366 -0.08923568 0.5635830
##  2: standardized 0.1428571 0.23327442 -0.08901142 0.5555602
##  3: standardized 0.2857142 0.22937517 -0.08899300 0.5477433
##  4: standardized 0.4285713 0.22547592 -0.08918808 0.5401399
##  5: standardized 0.5714284 0.22157668 -0.08960430 0.5327576
##  6: standardized 0.7142855 0.21767743 -0.09024915 0.5256040
##  7: standardized 0.8571426 0.21377817 -0.09112997 0.5186863
##  8: standardized 0.9999998 0.20987892 -0.09225381 0.5120116
##  9: standardized 1.1428568 0.20597968 -0.09362745 0.5055868
## 10: standardized 1.2857139 0.20208043 -0.09525724 0.4994181
## 11: standardized 1.4285710 0.19818118 -0.09714908 0.4935114
## 12: standardized 1.5714282 0.19428194 -0.09930836 0.4878722
## 13: standardized 1.7142853 0.19038269 -0.10173985 0.4825052
## 14: standardized 1.8571423 0.18648343 -0.10444767 0.4774145
## 15: standardized 1.9999995 0.18258418 -0.10743523 0.4726036
## 16: standardized 2.1428566 0.17868493 -0.11070517 0.4680750
## 17: standardized 2.2857137 0.17478569 -0.11425932 0.4638307
## 18: standardized 2.4285707 0.17088644 -0.11809874 0.4598716
## 19: standardized 2.5714278 0.16698720 -0.12222356 0.4561979
## 20: standardized 2.7142849 0.16308795 -0.12663314 0.4528090
## 21: standardized 2.8571420 0.15918870 -0.13132598 0.4497034
## 22: standardized 2.9999993 0.15528944 -0.13629974 0.4468786
## 23: standardized 3.1428564 0.15139019 -0.14155138 0.4443318
## 24: standardized 3.2857134 0.14749095 -0.14707701 0.4420589
## 25: standardized 3.4285705 0.14359170 -0.15287217 0.4400556
## 26: standardized 3.5714276 0.13969246 -0.15893170 0.4383166
## 27: standardized 3.7142847 0.13579321 -0.16524993 0.4368363
## 28: standardized 3.8571417 0.13189396 -0.17182066 0.4356086
## 29: standardized 3.9999990 0.12799470 -0.17863730 0.4346267
## 30: standardized 4.1428561 0.12409546 -0.18569289 0.4338838
## 31: standardized 4.2857132 0.12019621 -0.19298023 0.4333726
## 32: standardized 4.4285703 0.11629696 -0.20049186 0.4330858
## 33: standardized 4.5714273 0.11239772 -0.20822021 0.4330156
## 34: standardized 4.7142844 0.10849846 -0.21615760 0.4331545
## 35: standardized 4.8571415 0.10459922 -0.22429636 0.4334948
## 36: standardized 4.9999986 0.10069997 -0.23262878 0.4340287
## 37: standardized 5.1428556 0.09680072 -0.24114724 0.4347487
## 38: standardized 5.2857127 0.09290147 -0.24984422 0.4356472
## 39: standardized 5.4285698 0.08900222 -0.25871235 0.4367168
## 40: standardized 5.5714269 0.08510298 -0.26774436 0.4379503
## 41: standardized 5.7142839 0.08120372 -0.27693325 0.4393407
## 42: standardized 5.8571415 0.07730448 -0.28627214 0.4408811
## 43: standardized 5.9999986 0.07340523 -0.29575440 0.4425649
##             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 = "07_AdvancedStage_sleepdiaryacti_figure.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