Regression (Phase-based)

Info

Init

Set Working Directory

Imports

Input and Output Directories and Files

Check Period and Phase in df2

Check Period and Phase in df3

Prepare for Regression

Code
ofd4 <- file.path(ofd0, "n0001-models-phase-i0021-all") ## CAUTION
ofd4 <- file.path(ofd0, "n0001-models-phase-i0008-all") ## CAUTION
dir.create(ofd4, showWarnings = FALSE, recursive = TRUE)

model <- "fit0x0"
fbase <- file.path(ofd4, model)
fpath <- paste0(fbase, ".extension")
cat0(fpath)
./data/20240428T200156-politicians-aux-analysis/n0001-init//n0001-models-phase-i0008-all/fit0x0.extension 

Fitting and Marginalization

Cleanup

Save Data for Reference

Source Helpers

Tweet Counts by Outcome, Phase and Party

Code
df2 %>%
  dplyr::count(Outcome, Phase, Party) %>%
  identity() %>%
  ggplot() +
  geom_bar(
    aes(
      x=Phase,
      y=n,
      group = Outcome,
      fill = Outcome
      ),
    alpha=0.75,
    stat="identity") +
  ## geom_text(
  ggrepel::geom_text_repel(
    aes(
      x = Phase,
      y = n,
      label = n,
      group = Outcome
    ),
    position = position_stack(vjust = 0.5),
    size = 2.5,
    angle = 0,
    family = "Times New Roman",
    color = "black",
    box.padding = 0.025,
    point.padding = 1e-06,
    min.segment.length = 0.05,
    force = 0.01,
  ) +
  scale_y_continuous(labels = scales::label_number()) +
  labs(y = "tweet count")  +
  theme_ggeffects() +
  cogsys::theme0 +
  scale_fill_brewer(palette = "Set1") +
  facet_wrap(~ Party) +
  NULL

Tweet Counts by Time (Days)

Code
df2 %>%
  dplyr::count(Days) %>%
  identity() %>%
  ggplot() +
  geom_line(aes(x=Days, y=n)) +
  lineED + lineRD + lineTD + timeDD +
  theme_ggeffects() +
  cogsys::theme0 +
  ## cogsys::theme2 +
  scale_y_continuous(labels = scales::label_number()) +
  labs(y = "tweet count")  +
  scale_fill_brewer(palette = "Set1") +
  NULL

Model fit01aPh: Null

Fit

Code
model <- "fit01aPh"
suppressWarnings(rm(list = model))
assign(
  model,
  lmerTest::lmer(
    formula = Agency ~ (1 | Name) + 1,
    data = df0,
    REML = REML,
    control = control))

fbase <- get_model_info(model, ofd4)
fit01aPh: [df0] Agency ~ (1 | Name) + 1
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: Agency ~ (1 | Name) + 1
   Data: df0
Control: control

REML criterion at convergence: 26631.7

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-7.9514 -0.5639 -0.0023  0.5683  7.3986 

Random effects:
 Groups   Name        Variance Std.Dev.
 Name     (Intercept) 0.006209 0.0788  
 Residual             0.067519 0.2598  
Number of obs: 169997, groups:  Name, 870

Fixed effects:
             Estimate Std. Error        df t value Pr(>|t|)    
(Intercept) 4.986e-01  2.807e-03 8.264e+02   177.7   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
--------------------------------------------------------------------- 
fit01aPh: [df0] Agency ~ (1 | Name) + 1
# R2 for Mixed Models

  Conditional R2: 0.084
     Marginal R2: 0.000
--------------------------------------------------------------------- 
fit01aPh: [df0] Agency ~ (1 | Name) + 1
# Intraclass Correlation Coefficient

    Adjusted ICC: 0.084
  Unadjusted ICC: 0.084
--------------------------------------------------------------------- 
fit01aPh: [df0] Agency ~ (1 | Name) + 1
# ICC by Group

Group |   ICC
-------------
Name  | 0.084
--------------------------------------------------------------------- 

Efects: Random

Code
model <- "fit01aPh"
extra <- "9001"
terms <- NULL

suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_model(get(model), type="re")

fbasefig <- file.path(ofd4, paste0(model, "-xtr-", extra, "-random", paste(terms, collapse = "-x-")))

ggsave(file=paste0(fbasefig,".png"),plot=gg88,width=8,height=44,limitsize=FALSE)
ggsave(file=paste0(fbasefig,".svg"),plot=gg88,width=8,height=88,limitsize=FALSE)
gg88

Model fit02aPh: Time

Fit

Code
model <- "fit02aPh"
suppressWarnings(rm(list = model))
assign(
  model,
  lmerTest::lmer(
    formula = Agency ~ (Time | Name) + Time,
    data = df0,
    REML = REML,
    control = control))

fbase <- get_model_info(model, ofd4)
fit02aPh: [df0] Agency ~ (Time | Name) + Time
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: Agency ~ (Time | Name) + Time
   Data: df0
Control: control

REML criterion at convergence: 24941.9

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-8.0353 -0.5639 -0.0047  0.5664  7.3362 

Random effects:
 Groups   Name        Variance Std.Dev. Corr
 Name     (Intercept) 0.006283 0.07927      
          Time        0.004088 0.06394  0.18
 Residual             0.066384 0.25765      
Number of obs: 169997, groups:  Name, 870

Fixed effects:
              Estimate Std. Error         df t value Pr(>|t|)    
(Intercept)   0.498029   0.002848 816.443563 174.884  < 2e-16 ***
Time         -0.010230   0.002634 709.116999  -3.884 0.000112 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
--------------------------------------------------------------------- 
fit02aPh: [df0] Agency ~ (Time | Name) + Time
# R2 for Mixed Models

  Conditional R2: 0.102
     Marginal R2: 0.000
--------------------------------------------------------------------- 
fit02aPh: [df0] Agency ~ (Time | Name) + Time
# Intraclass Correlation Coefficient

    Adjusted ICC: 0.102
  Unadjusted ICC: 0.102
--------------------------------------------------------------------- 
fit02aPh: [df0] Agency ~ (Time | Name) + Time
# ICC by Group

Group |   ICC
-------------
Name  | 0.085
--------------------------------------------------------------------- 

Effects: Time

Compute

Code
model <- "fit02aPh"
extra <- "1001"
terms <- c("Time")

suppressWarnings(rm(list = ls(pattern = "^ggeff")))
ggeff <- get_eff_null(model, terms, extra, ofd4)
fit02aPh: [df0] Agency ~ (Time | Name) + Time
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$pred0, n = Inf)
# Average predicted values of Agency

 Time | Predicted |     95% CI
------------------------------
-1.00 |      0.51 | 0.50, 0.51
-0.50 |      0.50 | 0.50, 0.51
 0.00 |      0.50 | 0.49, 0.50
 0.50 |      0.50 | 0.49, 0.50
 1.00 |      0.49 | 0.48, 0.50
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test0, n = Inf)
# (Average) Linear trend for Time

Slope     |       95% CI |     p
--------------------------------
-7.57e-03 | -0.01,  0.00 | 0.004
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test2, n = Inf)
# (Average) Linear trend for Time

Slope     |       95% CI |     p
--------------------------------
-7.57e-03 | -0.01,  0.00 | 0.004

Plot: Basic

Code
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- ggeff$pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
## gg88 <- gg88 + timeD + lineE + lineT + lineR + rect5 + cogsys::theme0 ## + scaleA

gg88 <- gg88 + timeD + lineE + lineT + lineR + rect3 + cogsys::theme0 + scaleC


ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.png"), plot = gg88 + cogsys::theme2, width=8, height=24)
ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.svg"), plot = gg88 + cogsys::theme2, width=16, height=48)
ggsave(file = paste0(ggeff$fbasefig, "-pred0-Fig.svg"), plot = gg88 + cogsys::theme2, width=12, height=48, limitsize = FALSE)

gg88

Model fit03aPh: Time x Phase

Fit

Code
model <- "fit03aPh"
suppressWarnings(rm(list = model))
assign(
  model,
  lmerTest::lmer(
    formula = Agency ~ (Time | Name) + Time * Phase,
    data = df0,
    REML = REML,
    control = control))

fbase <- get_model_info(model, ofd4)
fit03aPh: [df0] Agency ~ (Time | Name) + Time * Phase
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: Agency ~ (Time | Name) + Time * Phase
   Data: df0
Control: control

REML criterion at convergence: 24043.7

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-8.1156 -0.5629 -0.0072  0.5649  7.3761 

Random effects:
 Groups   Name        Variance Std.Dev. Corr
 Name     (Intercept) 0.006224 0.07889      
          Time        0.004129 0.06425  0.18
 Residual             0.066017 0.25694      
Number of obs: 169997, groups:  Name, 870

Fixed effects:
               Estimate Std. Error         df t value Pr(>|t|)    
(Intercept)   5.285e-01  3.170e-03  1.284e+03 166.749   <2e-16 ***
Time          4.459e-02  3.657e-03  2.769e+03  12.192   <2e-16 ***
PhaseAE      -4.145e-03  4.178e-03  1.691e+05  -0.992   0.3212    
PhaseBR      -5.689e-01  3.066e-02  1.686e+05 -18.558   <2e-16 ***
PhaseAR      -9.121e-03  4.936e-03  1.697e+05  -1.848   0.0646 .  
Time:PhaseAE -3.579e-01  2.590e-02  1.688e+05 -13.820   <2e-16 ***
Time:PhaseBR  1.610e+00  9.670e-02  1.686e+05  16.650   <2e-16 ***
Time:PhaseAR -9.963e-02  7.213e-03  1.676e+05 -13.812   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
--------------------------------------------------------------------- 
fit03aPh: [df0] Agency ~ (Time | Name) + Time * Phase
# R2 for Mixed Models

  Conditional R2: 0.107
     Marginal R2: 0.006
--------------------------------------------------------------------- 
fit03aPh: [df0] Agency ~ (Time | Name) + Time * Phase
# Intraclass Correlation Coefficient

    Adjusted ICC: 0.102
  Unadjusted ICC: 0.101
--------------------------------------------------------------------- 
fit03aPh: [df0] Agency ~ (Time | Name) + Time * Phase
# ICC by Group

Group |   ICC
-------------
Name  | 0.085
--------------------------------------------------------------------- 

Effects: Time

Compute

Code
model <- "fit03aPh"
extra <- "1001"
terms <- c("Time")

suppressWarnings(rm(list = ls(pattern = "^ggeff")))
ggeff <- get_eff_null(model, terms, extra, ofd4)
fit03aPh: [df0] Agency ~ (Time | Name) + Time * Phase
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$pred0, n = Inf)
# Average predicted values of Agency

 Time | Predicted |     95% CI
------------------------------
-1.00 |      0.45 | 0.44, 0.47
-0.50 |      0.48 | 0.47, 0.49
 0.00 |      0.50 | 0.50, 0.51
 0.50 |      0.53 | 0.52, 0.54
 1.00 |      0.56 | 0.54, 0.57
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test0, n = Inf)
# (Average) Linear trend for Time

Slope |     95% CI |      p
---------------------------
0.05  | 0.04, 0.06 | < .001
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test2, n = Inf)
# (Average) Linear trend for Time

Slope |     95% CI |      p
---------------------------
0.05  | 0.04, 0.06 | < .001

Plot: Basic

Code
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- ggeff$pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88 <- gg88 + cogsys::theme0 + timeD + lineE + lineT + lineR + rect3 ## + scaleA

ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.png"), plot = gg88 + cogsys::theme2, width=8, height=24)
ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.svg"), plot = gg88 + cogsys::theme2, width=16, height=48)

gg88

Effects: Phase

Compute

Code
model <- "fit03aPh"
extra <- "1002"
terms <- c("Phase")

suppressWarnings(rm(list = ls(pattern = "^ggeff")))
ggeff <- get_eff_null(model, terms, extra, ofd4)
fit03aPh: [df0] Agency ~ (Time | Name) + Time * Phase
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$pred0, n = Inf)
# Average predicted values of Agency

Phase | Predicted |       95% CI
--------------------------------
BE    |      0.53 |  0.52,  0.53
AE    |      0.55 |  0.54,  0.56
BR    |     -0.15 | -0.22, -0.08
AR    |      0.53 |  0.51,  0.54
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test0, n = Inf)
Phase | Predicted |       95% CI |      p
-----------------------------------------
BE    |      0.53 |  0.52,  0.53 | < .001
AE    |      0.55 |  0.54,  0.56 | < .001
BR    |     -0.15 | -0.22, -0.08 | < .001
AR    |      0.53 |  0.51,  0.54 | < .001
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test2, n = Inf)
# Pairwise comparisons

Phase | Contrast |       95% CI |      p
----------------------------------------
BE-AE |    -0.02 | -0.03, -0.01 | < .001
BE-BR |     0.68 |  0.61,  0.75 | < .001
BE-AR | 2.34e-03 | -0.01,  0.01 | 0.658 
AE-BR |     0.70 |  0.63,  0.77 | < .001
AE-AR |     0.02 |  0.01,  0.04 | 0.003 
BR-AR |    -0.68 | -0.75, -0.60 | < .001

Plot: Basic

Code
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- ggeff$pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88 <- gg88 + cogsys::theme0 # + timeD + lineE + lineT + lineR + rect4 ## + scaleA

ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.png"), plot = gg88 + cogsys::theme2, width=8, height=24)
ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.svg"), plot = gg88 + cogsys::theme2, width=16, height=48)

gg88

Effects: Time x Phase

Compute

Code
model <- "fit03aPh"
extra <- "1003"
terms <- c("Time","Phase")

suppressWarnings(rm(list = ls(pattern = "^ggeff")))
ggeff <- get_eff_null(model, terms, extra, ofd4)
fit03aPh: [df0] Agency ~ (Time | Name) + Time * Phase
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$pred0, n = Inf)
# Average predicted values of Agency

Phase: BE

 Time | Predicted |      95% CI
-------------------------------
-1.00 |      0.48 | 0.47,  0.49
-0.50 |      0.51 | 0.50,  0.51
 0.00 |      0.53 | 0.52,  0.54
 0.50 |      0.56 | 0.55,  0.56
 1.00 |      0.58 | 0.57,  0.59

Phase: AE

 Time | Predicted |      95% CI
-------------------------------
-1.00 |      0.84 | 0.78,  0.89
-0.50 |      0.68 | 0.65,  0.71
 0.00 |      0.53 | 0.52,  0.54
 0.50 |      0.37 | 0.35,  0.39
 1.00 |      0.22 | 0.17,  0.26

Phase: BR

 Time | Predicted |       95% CI
--------------------------------
-1.00 |     -1.70 | -1.95, -1.45
-0.50 |     -0.87 | -1.02, -0.71
 0.00 |     -0.04 | -0.10,  0.02
 0.50 |      0.79 |  0.76,  0.83
 1.00 |      1.62 |  1.49,  1.75

Phase: AR

 Time | Predicted |      95% CI
-------------------------------
-1.00 |      0.57 | 0.55,  0.60
-0.50 |      0.55 | 0.53,  0.56
 0.00 |      0.52 | 0.51,  0.53
 0.50 |      0.50 | 0.49,  0.50
 1.00 |      0.47 | 0.46,  0.48
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test0, n = Inf)
# (Average) Linear trend for Time

Phase | Slope |       95% CI |      p
-------------------------------------
BE    |  0.04 |  0.04,  0.05 | < .001
AE    | -0.31 | -0.36, -0.26 | < .001
BR    |  1.65 |  1.47,  1.84 | < .001
AR    | -0.06 | -0.07, -0.04 | < .001
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test2, n = Inf)
# (Average) Linear trend for Time

Phase | Contrast |       95% CI |      p
----------------------------------------
BE-AE |     0.36 |  0.31,  0.41 | < .001
BE-BR |    -1.61 | -1.80, -1.42 | < .001
BE-AR |     0.10 |  0.09,  0.11 | < .001
AE-BR |    -1.97 | -2.16, -1.77 | < .001
AE-AR |    -0.26 | -0.31, -0.21 | < .001
BR-AR |     1.71 |  1.52,  1.90 | < .001

Plot: Basic

Code
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- ggeff$pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88 <- gg88 + timeD + lineE + lineT + lineR + rect0 + cogsys::theme0 + scaleA
## gg88 <- gg88 + cogsys::theme0 + timeD + lineE + lineT + lineR + rect3 + scaleA

ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.png"), plot = gg88 + cogsys::theme2, width=8, height=24)

ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.svg"), plot = gg88 + cogsys::theme2, width=12, height=36, limitsize = FALSE)

ggsave(file = paste0(ggeff$fbasefig, "-pred0-Fig.svg"), plot = gg88 + cogsys::theme2, width=12, height=48, limitsize = FALSE)

gg88

Plot: Nicer

Code
# knitr::opts_chunk$set(fig.width=unit(12,"cm"), fig.height=unit(18,"cm"))
# gg88
suppressWarnings(rm(list = ls(pattern = "^gg99")))
gg99 <- gg88 + cogsys::theme2 + scaleA

ggsave(file = paste0(ggeff$fbasefig, "-pred0-FIG.svg"), plot = gg99 + cogsys::theme2, width=12, height=48, limitsize = FALSE)

## gg99

Model fit04aPh: Time x Phase x Outcome

Fit + Concreteness

Code
model <- "fit04cPh"
suppressWarnings(rm(list = model))
assign(
  model,
  lmerTest::lmer(
    formula = Agency ~ (Time | Name) + Concreteness + Time * Phase * Outcome,
    data = df0,
    REML = REML,
    control = control))

fbase <- get_model_info(model, ofd4)
fit04cPh: [df0] Agency ~ (Time | Name) + Concreteness + Time * Phase * Outcome
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: Agency ~ (Time | Name) + Concreteness + Time * Phase * Outcome
   Data: df0
Control: control

REML criterion at convergence: 22947.3

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-8.2540 -0.5628 -0.0058  0.5640  7.4058 

Random effects:
 Groups   Name        Variance Std.Dev. Corr 
 Name     (Intercept) 0.004628 0.06803       
          Time        0.003356 0.05793  -0.06
 Residual             0.065692 0.25630       
Number of obs: 169996, groups:  Name, 870

Fixed effects:
                             Estimate Std. Error         df t value Pr(>|t|)
(Intercept)                 3.329e-01  8.628e-03  1.939e+04  38.583  < 2e-16
Concreteness                2.193e-01  8.933e-03  1.694e+05  24.549  < 2e-16
Time                        5.708e-02  5.593e-03  3.422e+03  10.205  < 2e-16
PhaseAE                    -4.586e-02  7.678e-03  1.693e+05  -5.973 2.34e-09
PhaseBR                    -4.964e-01  6.015e-02  1.690e+05  -8.253  < 2e-16
PhaseAR                    -1.229e-01  1.032e-02  1.662e+05 -11.905  < 2e-16
Outcomewinner               2.169e-02  5.780e-03  1.441e+03   3.752 0.000182
Time:PhaseAE               -4.721e-01  5.045e-02  1.692e+05  -9.359  < 2e-16
Time:PhaseBR                1.143e+00  1.900e-01  1.689e+05   6.015 1.80e-09
Time:PhaseAR               -5.325e-02  1.520e-02  1.543e+05  -3.503 0.000460
Time:Outcomewinner         -2.036e-02  7.192e-03  3.273e+03  -2.831 0.004673
PhaseAE:Outcomewinner       5.817e-02  9.151e-03  1.692e+05   6.357 2.07e-10
PhaseBR:Outcomewinner      -8.234e-02  6.985e-02  1.689e+05  -1.179 0.238491
PhaseAR:Outcomewinner       1.483e-01  1.176e-02  1.679e+05  12.614  < 2e-16
Time:PhaseAE:Outcomewinner  1.605e-01  5.876e-02  1.692e+05   2.731 0.006311
Time:PhaseBR:Outcomewinner  5.814e-01  2.205e-01  1.688e+05   2.636 0.008386
Time:PhaseAR:Outcomewinner -4.541e-02  1.728e-02  1.603e+05  -2.627 0.008613
                              
(Intercept)                ***
Concreteness               ***
Time                       ***
PhaseAE                    ***
PhaseBR                    ***
PhaseAR                    ***
Outcomewinner              ***
Time:PhaseAE               ***
Time:PhaseBR               ***
Time:PhaseAR               ***
Time:Outcomewinner         ** 
PhaseAE:Outcomewinner      ***
PhaseBR:Outcomewinner         
PhaseAR:Outcomewinner      ***
Time:PhaseAE:Outcomewinner ** 
Time:PhaseBR:Outcomewinner ** 
Time:PhaseAR:Outcomewinner ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
--------------------------------------------------------------------- 
fit04cPh: [df0] Agency ~ (Time | Name) + Concreteness + Time * Phase * Outcome
# R2 for Mixed Models

  Conditional R2: 0.103
     Marginal R2: 0.024
--------------------------------------------------------------------- 
fit04cPh: [df0] Agency ~ (Time | Name) + Concreteness + Time * Phase * Outcome
# Intraclass Correlation Coefficient

    Adjusted ICC: 0.081
  Unadjusted ICC: 0.079
--------------------------------------------------------------------- 
fit04cPh: [df0] Agency ~ (Time | Name) + Concreteness + Time * Phase * Outcome
# ICC by Group

Group |   ICC
-------------
Name  | 0.065
--------------------------------------------------------------------- 
Code
model <- "fit04aPh"
suppressWarnings(rm(list = model))
assign(
  model,
  lmerTest::lmer(
    formula = Agency ~ (Time | Name) + Time * Phase * Outcome,
    data = df0,
    REML = REML,
    control = control))

fbase <- get_model_info(model, ofd4)
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: Agency ~ (Time | Name) + Time * Phase * Outcome
   Data: df0
Control: control

REML criterion at convergence: 23540

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-8.1902 -0.5632 -0.0074  0.5639  7.3864 

Random effects:
 Groups   Name        Variance Std.Dev. Corr 
 Name     (Intercept) 0.004798 0.06927       
          Time        0.003348 0.05786  -0.07
 Residual             0.065916 0.25674       
Number of obs: 169997, groups:  Name, 870

Fixed effects:
                             Estimate Std. Error         df t value Pr(>|t|)
(Intercept)                 5.151e-01  4.450e-03  1.471e+03 115.767  < 2e-16
Time                        5.703e-02  5.597e-03  3.426e+03  10.189  < 2e-16
PhaseAE                    -4.245e-02  7.688e-03  1.693e+05  -5.521 3.38e-08
PhaseBR                    -4.966e-01  6.025e-02  1.690e+05  -8.242  < 2e-16
PhaseAR                    -1.195e-01  1.034e-02  1.662e+05 -11.561  < 2e-16
Outcomewinner               2.383e-02  5.853e-03  1.425e+03   4.072 4.92e-05
Time:PhaseAE               -4.906e-01  5.053e-02  1.692e+05  -9.710  < 2e-16
Time:PhaseBR                1.152e+00  1.903e-01  1.689e+05   6.052 1.44e-09
Time:PhaseAR               -5.823e-02  1.523e-02  1.543e+05  -3.824 0.000131
Time:Outcomewinner         -2.039e-02  7.198e-03  3.276e+03  -2.833 0.004646
PhaseAE:Outcomewinner       5.796e-02  9.165e-03  1.692e+05   6.324 2.56e-10
PhaseBR:Outcomewinner      -9.406e-02  6.997e-02  1.689e+05  -1.344 0.178864
PhaseAR:Outcomewinner       1.478e-01  1.178e-02  1.679e+05  12.550  < 2e-16
Time:PhaseAE:Outcomewinner  1.675e-01  5.885e-02  1.692e+05   2.846 0.004424
Time:PhaseBR:Outcomewinner  6.256e-01  2.209e-01  1.688e+05   2.832 0.004623
Time:PhaseAR:Outcomewinner -4.478e-02  1.731e-02  1.602e+05  -2.586 0.009706
                              
(Intercept)                ***
Time                       ***
PhaseAE                    ***
PhaseBR                    ***
PhaseAR                    ***
Outcomewinner              ***
Time:PhaseAE               ***
Time:PhaseBR               ***
Time:PhaseAR               ***
Time:Outcomewinner         ** 
PhaseAE:Outcomewinner      ***
PhaseBR:Outcomewinner         
PhaseAR:Outcomewinner      ***
Time:PhaseAE:Outcomewinner ** 
Time:PhaseBR:Outcomewinner ** 
Time:PhaseAR:Outcomewinner ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
--------------------------------------------------------------------- 
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
# R2 for Mixed Models

  Conditional R2: 0.102
     Marginal R2: 0.021
--------------------------------------------------------------------- 
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
# Intraclass Correlation Coefficient

    Adjusted ICC: 0.083
  Unadjusted ICC: 0.081
--------------------------------------------------------------------- 
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
# ICC by Group

Group |   ICC
-------------
Name  | 0.067
--------------------------------------------------------------------- 

Fit

Code
model <- "fit04aPh"
suppressWarnings(rm(list = model))
assign(
  model,
  lmerTest::lmer(
    formula = Agency ~ (Time | Name) + Time * Phase * Outcome,
    data = df0,
    REML = REML,
    control = control))

fbase <- get_model_info(model, ofd4)
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: Agency ~ (Time | Name) + Time * Phase * Outcome
   Data: df0
Control: control

REML criterion at convergence: 23540

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-8.1902 -0.5632 -0.0074  0.5639  7.3864 

Random effects:
 Groups   Name        Variance Std.Dev. Corr 
 Name     (Intercept) 0.004798 0.06927       
          Time        0.003348 0.05786  -0.07
 Residual             0.065916 0.25674       
Number of obs: 169997, groups:  Name, 870

Fixed effects:
                             Estimate Std. Error         df t value Pr(>|t|)
(Intercept)                 5.151e-01  4.450e-03  1.471e+03 115.767  < 2e-16
Time                        5.703e-02  5.597e-03  3.426e+03  10.189  < 2e-16
PhaseAE                    -4.245e-02  7.688e-03  1.693e+05  -5.521 3.38e-08
PhaseBR                    -4.966e-01  6.025e-02  1.690e+05  -8.242  < 2e-16
PhaseAR                    -1.195e-01  1.034e-02  1.662e+05 -11.561  < 2e-16
Outcomewinner               2.383e-02  5.853e-03  1.425e+03   4.072 4.92e-05
Time:PhaseAE               -4.906e-01  5.053e-02  1.692e+05  -9.710  < 2e-16
Time:PhaseBR                1.152e+00  1.903e-01  1.689e+05   6.052 1.44e-09
Time:PhaseAR               -5.823e-02  1.523e-02  1.543e+05  -3.824 0.000131
Time:Outcomewinner         -2.039e-02  7.198e-03  3.276e+03  -2.833 0.004646
PhaseAE:Outcomewinner       5.796e-02  9.165e-03  1.692e+05   6.324 2.56e-10
PhaseBR:Outcomewinner      -9.406e-02  6.997e-02  1.689e+05  -1.344 0.178864
PhaseAR:Outcomewinner       1.478e-01  1.178e-02  1.679e+05  12.550  < 2e-16
Time:PhaseAE:Outcomewinner  1.675e-01  5.885e-02  1.692e+05   2.846 0.004424
Time:PhaseBR:Outcomewinner  6.256e-01  2.209e-01  1.688e+05   2.832 0.004623
Time:PhaseAR:Outcomewinner -4.478e-02  1.731e-02  1.602e+05  -2.586 0.009706
                              
(Intercept)                ***
Time                       ***
PhaseAE                    ***
PhaseBR                    ***
PhaseAR                    ***
Outcomewinner              ***
Time:PhaseAE               ***
Time:PhaseBR               ***
Time:PhaseAR               ***
Time:Outcomewinner         ** 
PhaseAE:Outcomewinner      ***
PhaseBR:Outcomewinner         
PhaseAR:Outcomewinner      ***
Time:PhaseAE:Outcomewinner ** 
Time:PhaseBR:Outcomewinner ** 
Time:PhaseAR:Outcomewinner ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
--------------------------------------------------------------------- 
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
# R2 for Mixed Models

  Conditional R2: 0.102
     Marginal R2: 0.021
--------------------------------------------------------------------- 
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
# Intraclass Correlation Coefficient

    Adjusted ICC: 0.083
  Unadjusted ICC: 0.081
--------------------------------------------------------------------- 
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
# ICC by Group

Group |   ICC
-------------
Name  | 0.067
--------------------------------------------------------------------- 

Parameters

Code
model <- "fit04aPh"

pp(model);
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
Code
parameters::model_parameters(get(model))
# Fixed Effects

Parameter                              | Coefficient |       SE |         95% CI | t(169977) |      p
-----------------------------------------------------------------------------------------------------
(Intercept)                            |        0.52 | 4.45e-03 | [ 0.51,  0.52] |    115.77 | < .001
Time                                   |        0.06 | 5.60e-03 | [ 0.05,  0.07] |     10.19 | < .001
Phase [AE]                             |       -0.04 | 7.69e-03 | [-0.06, -0.03] |     -5.52 | < .001
Phase [BR]                             |       -0.50 |     0.06 | [-0.61, -0.38] |     -8.24 | < .001
Phase [AR]                             |       -0.12 |     0.01 | [-0.14, -0.10] |    -11.56 | < .001
Outcome [winner]                       |        0.02 | 5.85e-03 | [ 0.01,  0.04] |      4.07 | < .001
Time × Phase [AE]                      |       -0.49 |     0.05 | [-0.59, -0.39] |     -9.71 | < .001
Time × Phase [BR]                      |        1.15 |     0.19 | [ 0.78,  1.52] |      6.05 | < .001
Time × Phase [AR]                      |       -0.06 |     0.02 | [-0.09, -0.03] |     -3.82 | < .001
Time × Outcome [winner]                |       -0.02 | 7.20e-03 | [-0.03, -0.01] |     -2.83 | 0.005 
Phase [AE] × Outcome [winner]          |        0.06 | 9.17e-03 | [ 0.04,  0.08] |      6.32 | < .001
Phase [BR] × Outcome [winner]          |       -0.09 |     0.07 | [-0.23,  0.04] |     -1.34 | 0.179 
Phase [AR] × Outcome [winner]          |        0.15 |     0.01 | [ 0.12,  0.17] |     12.55 | < .001
(Time × Phase [AE]) × Outcome [winner] |        0.17 |     0.06 | [ 0.05,  0.28] |      2.85 | 0.004 
(Time × Phase [BR]) × Outcome [winner] |        0.63 |     0.22 | [ 0.19,  1.06] |      2.83 | 0.005 
(Time × Phase [AR]) × Outcome [winner] |       -0.04 |     0.02 | [-0.08, -0.01] |     -2.59 | 0.010 

# Random Effects

Parameter                  | Coefficient
----------------------------------------
SD (Intercept: Name)       |        0.07
SD (Time: Name)            |        0.06
Cor (Intercept~Time: Name) |       -0.07
SD (Residual)              |        0.26

Summary

Code
model <- "fit04aPh"

pp(model)
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
Code
tbl0 <- gtsummary::tbl_regression(
  get(model),
  add_pairwise_contrasts = TRUE,
  exponentiate = FALSE,
  tidy_fun = broom.mixed::tidy,
)
tbl0
Characteristic Beta 95% CI1 p-value
Time 0.06 0.05, 0.07 <0.001
Phase


    AE - BE 0.01 0.00, 0.03 0.10
    BR - BE -0.64 -0.75, -0.53 <0.001
    BR - AE -0.66 -0.77, -0.55 <0.001
    AR - BE -0.04 -0.06, -0.02 <0.001
    AR - AE -0.05 -0.08, -0.03 <0.001
    AR - BR 0.60 0.49, 0.71 <0.001
Outcome


    winner - loser 0.04 0.00, 0.08 0.069
Time * Phase


    Time * AE -0.49 -0.59, -0.39 <0.001
    Time * BR 1.2 0.78, 1.5 <0.001
    Time * AR -0.06 -0.09, -0.03 <0.001
Time * Outcome


    Time * winner -0.02 -0.03, -0.01 0.005
Phase * Outcome


    AE * winner 0.06 0.04, 0.08 <0.001
    BR * winner -0.09 -0.23, 0.04 0.2
    AR * winner 0.15 0.12, 0.17 <0.001
Time * Phase * Outcome


    Time * AE * winner 0.17 0.05, 0.28 0.004
    Time * BR * winner 0.63 0.19, 1.1 0.005
    Time * AR * winner -0.04 -0.08, -0.01 0.010
Name.sd__(Intercept) 0.07

Name.cor__(Intercept).Time -0.07

Name.sd__Time 0.06

Residual.sd__Observation 0.26

1 CI = Confidence Interval

Effects: Time

Compute

Code
model <- "fit04aPh"
extra <- "1001"
terms <- c("Time")

suppressWarnings(rm(list = ls(pattern = "^ggeff")))
ggeff <- get_eff_null(model, terms, extra, ofd4)
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$pred0, n = Inf)
# Average predicted values of Agency

 Time | Predicted |     95% CI
------------------------------
-1.00 |      0.46 | 0.44, 0.47
-0.50 |      0.48 | 0.47, 0.49
 0.00 |      0.50 | 0.50, 0.51
 0.50 |      0.53 | 0.52, 0.54
 1.00 |      0.55 | 0.54, 0.56
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test0, n = Inf)
# (Average) Linear trend for Time

Slope |     95% CI |      p
---------------------------
0.05  | 0.04, 0.06 | < .001
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test2, n = Inf)
# (Average) Linear trend for Time

Slope |     95% CI |      p
---------------------------
0.05  | 0.04, 0.06 | < .001

Plot: Basic

Code
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- ggeff$pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88 <- gg88 + cogsys::theme0 + timeD + lineE + lineT + lineR + rect3 ## + scaleA

ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.png"), plot = gg88 + cogsys::theme2, width=8, height=24)
ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.svg"), plot = gg88 + cogsys::theme2, width=16, height=48)

gg88

Effects: Phase

Compute

Code
model <- "fit04aPh"
extra <- "1002"
terms <- c("Phase")

suppressWarnings(rm(list = ls(pattern = "^ggeff")))
ggeff <- get_eff_null(model, terms, extra, ofd4)
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$pred0, n = Inf)
# Average predicted values of Agency

Phase | Predicted |       95% CI
--------------------------------
BE    |      0.52 |  0.52,  0.53
AE    |      0.55 |  0.54,  0.57
BR    |     -0.12 | -0.19, -0.04
AR    |      0.51 |  0.50,  0.52
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test0, n = Inf)
Phase | Predicted |       95% CI |      p
-----------------------------------------
BE    |      0.52 |  0.52,  0.53 | < .001
AE    |      0.55 |  0.54,  0.57 | < .001
BR    |     -0.12 | -0.19, -0.04 | 0.004 
AR    |      0.51 |  0.50,  0.52 | < .001
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test2, n = Inf)
# Pairwise comparisons

Phase | Contrast |       95% CI |      p
----------------------------------------
BE-AE |    -0.03 | -0.04, -0.02 | < .001
BE-BR |     0.64 |  0.56,  0.72 | < .001
BE-AR |     0.02 |  0.00,  0.03 | 0.007 
AE-BR |     0.67 |  0.59,  0.75 | < .001
AE-AR |     0.05 |  0.03,  0.06 | < .001
BR-AR |    -0.62 | -0.70, -0.55 | < .001

Plot: Basic

Code
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- ggeff$pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88 <- gg88 + cogsys::theme0 # + timeD + lineE + lineT + lineR + rect4 ## + scaleA

ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.png"), plot = gg88 + cogsys::theme2, width=8, height=24)
ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.svg"), plot = gg88 + cogsys::theme2, width=16, height=48)

gg88

Effects: Time x Phase

Compute

Code
model <- "fit04aPh"
extra <- "1003"
terms <- c("Time","Phase")

suppressWarnings(rm(list = ls(pattern = "^ggeff")))
ggeff <- get_eff_null(model, terms, extra, ofd4)
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$pred0, n = Inf)
# Average predicted values of Agency

Phase: BE

 Time | Predicted |      95% CI
-------------------------------
-1.00 |      0.48 | 0.48,  0.49
-0.50 |      0.51 | 0.50,  0.51
 0.00 |      0.53 | 0.52,  0.53
 0.50 |      0.55 | 0.54,  0.56
 1.00 |      0.57 | 0.56,  0.58

Phase: AE

 Time | Predicted |      95% CI
-------------------------------
-1.00 |      0.86 | 0.80,  0.92
-0.50 |      0.69 | 0.66,  0.72
 0.00 |      0.53 | 0.52,  0.53
 0.50 |      0.36 | 0.34,  0.38
 1.00 |      0.19 | 0.15,  0.24

Phase: BR

 Time | Predicted |       95% CI
--------------------------------
-1.00 |     -1.65 | -1.90, -1.40
-0.50 |     -0.84 | -1.00, -0.69
 0.00 |     -0.03 | -0.09,  0.03
 0.50 |      0.78 |  0.74,  0.81
 1.00 |      1.59 |  1.46,  1.72

Phase: AR

 Time | Predicted |      95% CI
-------------------------------
-1.00 |      0.55 | 0.53,  0.58
-0.50 |      0.53 | 0.51,  0.55
 0.00 |      0.51 | 0.50,  0.52
 0.50 |      0.49 | 0.48,  0.49
 1.00 |      0.47 | 0.46,  0.47
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test0, n = Inf)
# (Average) Linear trend for Time

Phase |     Slope |       95% CI |      p
-----------------------------------------
BE    |      0.06 |  0.05,  0.07 | < .001
AE    |     -0.43 | -0.53, -0.33 | < .001
BR    |      1.21 |  0.84,  1.58 | < .001
AR    | -1.19e-03 | -0.03,  0.03 | 0.936 
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test2, n = Inf)
# (Average) Linear trend for Time

Phase | Contrast |       95% CI |      p
----------------------------------------
BE-AE |     0.49 |  0.39,  0.59 | < .001
BE-BR |    -1.15 | -1.52, -0.78 | < .001
BE-AR |     0.06 |  0.03,  0.09 | < .001
AE-BR |    -1.64 | -2.03, -1.26 | < .001
AE-AR |    -0.43 | -0.53, -0.33 | < .001
BR-AR |     1.21 |  0.84,  1.58 | < .001

Plot: Basic

Code
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- ggeff$pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88 <- gg88 + cogsys::theme0 + timeD + lineE + lineT + lineR + rect3 + scaleA

ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.png"), plot = gg88 + cogsys::theme2, width=8, height=24)
ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.svg"), plot = gg88 + cogsys::theme2, width=16, height=48)

gg88

Effects: Phase x Outcome

Compute

Code
model <- "fit04aPh"
extra <- "1004"
terms <- c("Phase","Outcome")

suppressWarnings(rm(list = ls(pattern = "^ggeff")))
ggeff <- get_eff_null(model, terms, extra, ofd4)
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$pred0, n = Inf)
# Average predicted values of Agency

Outcome: loser

Phase | Predicted |       95% CI
--------------------------------
BE    |      0.51 |  0.50,  0.52
AE    |      0.50 |  0.48,  0.52
BR    |     -0.07 | -0.21,  0.08
AR    |      0.39 |  0.37,  0.42

Outcome: winner

Phase | Predicted |       95% CI
--------------------------------
BE    |      0.53 |  0.53,  0.54
AE    |      0.57 |  0.56,  0.59
BR    |     -0.18 | -0.26, -0.09
AR    |      0.57 |  0.56,  0.58
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test0, n = Inf)
Phase | Outcome | Predicted |       95% CI |      p
---------------------------------------------------
BE    |   loser |      0.51 |  0.50,  0.52 | < .001
AE    |   loser |      0.50 |  0.48,  0.52 | < .001
BR    |   loser |     -0.07 | -0.21,  0.08 | 0.364 
AR    |   loser |      0.39 |  0.37,  0.42 | < .001
BE    |  winner |      0.53 |  0.53,  0.54 | < .001
AE    |  winner |      0.57 |  0.56,  0.59 | < .001
BR    |  winner |     -0.18 | -0.26, -0.09 | < .001
AR    |  winner |      0.57 |  0.56,  0.58 | < .001
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test2, n = Inf)
# Pairwise comparisons

Phase |       Outcome | Contrast |       95% CI |      p
--------------------------------------------------------
BE-AE |   loser-loser | 9.06e-03 | -0.01,  0.03 | 0.404 
BE-BR |   loser-loser |     0.57 |  0.43,  0.72 | < .001
BE-AR |   loser-loser |     0.12 |  0.09,  0.14 | < .001
BE-BE |  loser-winner |    -0.03 | -0.04, -0.01 | < .001
BE-AE |  loser-winner |    -0.06 | -0.08, -0.05 | < .001
BE-BR |  loser-winner |     0.69 |  0.60,  0.77 | < .001
BE-AR |  loser-winner |    -0.06 | -0.08, -0.05 | < .001
AE-BR |   loser-loser |     0.57 |  0.42,  0.71 | < .001
AE-AR |   loser-loser |     0.11 |  0.08,  0.14 | < .001
AE-BE |  loser-winner |    -0.03 | -0.06, -0.01 | 0.003 
AE-AE |  loser-winner |    -0.07 | -0.10, -0.05 | < .001
AE-BR |  loser-winner |     0.68 |  0.59,  0.76 | < .001
AE-AR |  loser-winner |    -0.07 | -0.09, -0.04 | < .001
BR-AR |   loser-loser |    -0.46 | -0.60, -0.31 | < .001
BR-BE |  loser-winner |    -0.60 | -0.74, -0.46 | < .001
BR-AE |  loser-winner |    -0.64 | -0.78, -0.49 | < .001
BR-BR |  loser-winner |     0.11 | -0.06,  0.28 | 0.205 
BR-AR |  loser-winner |    -0.64 | -0.78, -0.49 | < .001
AR-BE |  loser-winner |    -0.14 | -0.16, -0.12 | < .001
AR-AE |  loser-winner |    -0.18 | -0.20, -0.15 | < .001
AR-BR |  loser-winner |     0.57 |  0.48,  0.66 | < .001
AR-AR |  loser-winner |    -0.18 | -0.20, -0.15 | < .001
BE-AE | winner-winner |    -0.04 | -0.05, -0.02 | < .001
BE-BR | winner-winner |     0.71 |  0.63,  0.80 | < .001
BE-AR | winner-winner |    -0.04 | -0.05, -0.02 | < .001
AE-BR | winner-winner |     0.75 |  0.66,  0.83 | < .001
AE-AR | winner-winner | 2.17e-03 | -0.01,  0.02 | 0.800 
BR-AR | winner-winner |    -0.75 | -0.83, -0.66 | < .001

Plot: Basic

Code
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- ggeff$pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88 <- gg88 + cogsys::theme0 # + timeD + lineE + lineT + lineR + rect3 + scaleA

ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.png"), plot = gg88 + cogsys::theme2, width=8, height=24)
ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.svg"), plot = gg88 + cogsys::theme2, width=16, height=48)

gg88

Effects: Time x Phase x Outcome

Compute

Code
model <- "fit04aPh"
extra <- "1005"
terms <- c("Time", "Outcome", "Phase")

suppressWarnings(rm(list = ls(pattern = "^ggeff")))
ggeff <- get_eff_null(model, terms, extra, ofd4)
fit04aPh: [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
Code
## test3 <- ggeffects::test_predictions(ggeff$pred0, test="pairwise", p_adjust="fdr", collapse_levels=TRUE)

cat0(sep0)
===================================================================== 
Code
print(ggeff$pred0, n = Inf)
# Average predicted values of Agency

Outcome: loser
Phase: BE

 Time | Predicted |      95% CI
-------------------------------
-1.00 |      0.45 | 0.44,  0.46
-0.50 |      0.48 | 0.47,  0.49
 0.00 |      0.51 | 0.50,  0.52
 0.50 |      0.54 | 0.53,  0.55
 1.00 |      0.57 | 0.56,  0.59

Outcome: loser
Phase: AE

 Time | Predicted |       95% CI
--------------------------------
-1.00 |      0.90 |  0.79,  1.01
-0.50 |      0.69 |  0.62,  0.75
 0.00 |      0.47 |  0.45,  0.49
 0.50 |      0.25 |  0.22,  0.29
 1.00 |      0.04 | -0.05,  0.13

Outcome: loser
Phase: BR

 Time | Predicted |       95% CI
--------------------------------
-1.00 |     -1.20 | -1.69, -0.70
-0.50 |     -0.59 | -0.89, -0.29
 0.00 |      0.02 | -0.10,  0.13
 0.50 |      0.62 |  0.55,  0.69
 1.00 |      1.23 |  0.97,  1.48

Outcome: loser
Phase: AR

 Time | Predicted |      95% CI
-------------------------------
-1.00 |      0.39 | 0.34,  0.44
-0.50 |      0.39 | 0.36,  0.43
 0.00 |      0.39 | 0.37,  0.41
 0.50 |      0.39 | 0.38,  0.40
 1.00 |      0.39 | 0.38,  0.41

Outcome: winner
Phase: BE

 Time | Predicted |      95% CI
-------------------------------
-1.00 |      0.50 | 0.49,  0.51
-0.50 |      0.52 | 0.51,  0.52
 0.00 |      0.54 | 0.53,  0.54
 0.50 |      0.56 | 0.55,  0.57
 1.00 |      0.58 | 0.56,  0.59

Outcome: winner
Phase: AE

 Time | Predicted |      95% CI
-------------------------------
-1.00 |      0.84 | 0.77,  0.90
-0.50 |      0.69 | 0.66,  0.73
 0.00 |      0.55 | 0.54,  0.56
 0.50 |      0.41 | 0.39,  0.43
 1.00 |      0.27 | 0.22,  0.32

Outcome: winner
Phase: BR

 Time | Predicted |       95% CI
--------------------------------
-1.00 |     -1.87 | -2.16, -1.58
-0.50 |     -0.96 | -1.14, -0.78
 0.00 |     -0.05 | -0.12,  0.02
 0.50 |      0.85 |  0.81,  0.90
 1.00 |      1.76 |  1.61,  1.91

Outcome: winner
Phase: AR

 Time | Predicted |      95% CI
-------------------------------
-1.00 |      0.63 | 0.60,  0.65
-0.50 |      0.60 | 0.58,  0.62
 0.00 |      0.56 | 0.55,  0.58
 0.50 |      0.53 | 0.53,  0.54
 1.00 |      0.50 | 0.49,  0.51
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test0, n = Inf)
# (Average) Linear trend for Time

Outcome | Phase |     Slope |       95% CI |      p
---------------------------------------------------
loser   |    BE |      0.06 |  0.05,  0.07 | < .001
loser   |    AE |     -0.43 | -0.53, -0.33 | < .001
loser   |    BR |      1.21 |  0.84,  1.58 | < .001
loser   |    AR | -1.19e-03 | -0.03,  0.03 | 0.936 
winner  |    BE |      0.04 |  0.03,  0.05 | < .001
winner  |    AE |     -0.29 | -0.35, -0.23 | < .001
winner  |    BR |      1.81 |  1.59,  2.03 | < .001
winner  |    AR |     -0.07 | -0.08, -0.05 | < .001
Code
cat0(sep0)
===================================================================== 
Code
print(ggeff$test2, n = Inf)
# (Average) Linear trend for Time

Outcome       | Phase | Contrast |       95% CI |      p
--------------------------------------------------------
loser-loser   | BE-AE |     0.49 |  0.39,  0.59 | < .001
loser-loser   | BE-BR |    -1.15 | -1.52, -0.78 | < .001
loser-loser   | BE-AR |     0.06 |  0.03,  0.09 | < .001
loser-winner  | BE-BE |     0.02 |  0.01,  0.03 | 0.005 
loser-winner  | BE-AE |     0.34 |  0.28,  0.40 | < .001
loser-winner  | BE-BR |    -1.76 | -1.98, -1.54 | < .001
loser-winner  | BE-AR |     0.12 |  0.10,  0.14 | < .001
loser-loser   | AE-BR |    -1.64 | -2.03, -1.26 | < .001
loser-loser   | AE-AR |    -0.43 | -0.53, -0.33 | < .001
loser-winner  | AE-BE |    -0.47 | -0.57, -0.37 | < .001
loser-winner  | AE-AE |    -0.15 | -0.26, -0.03 | 0.013 
loser-winner  | AE-BR |    -2.25 | -2.49, -2.01 | < .001
loser-winner  | AE-AR |    -0.37 | -0.47, -0.27 | < .001
loser-loser   | BR-AR |     1.21 |  0.84,  1.58 | < .001
loser-winner  | BR-BE |     1.17 |  0.80,  1.55 | < .001
loser-winner  | BR-AE |     1.50 |  1.12,  1.87 | < .001
loser-winner  | BR-BR |    -0.61 | -1.04, -0.17 | 0.007 
loser-winner  | BR-AR |     1.28 |  0.90,  1.65 | < .001
loser-winner  | AR-BE |    -0.04 | -0.07, -0.01 | 0.015 
loser-winner  | AR-AE |     0.29 |  0.22,  0.35 | < .001
loser-winner  | AR-BR |    -1.82 | -2.04, -1.59 | < .001
loser-winner  | AR-AR |     0.07 |  0.03,  0.10 | < .001
winner-winner | BE-AE |     0.32 |  0.26,  0.38 | < .001
winner-winner | BE-BR |    -1.78 | -2.00, -1.56 | < .001
winner-winner | BE-AR |     0.10 |  0.09,  0.12 | < .001
winner-winner | AE-BR |    -2.10 | -2.33, -1.87 | < .001
winner-winner | AE-AR |    -0.22 | -0.28, -0.16 | < .001
winner-winner | BR-AR |     1.88 |  1.66,  2.10 | < .001

Filter test table

Code
ggeff$test3 <- ggeffects::test_predictions(ggeff$pred0, test="pairwise", p_adjust="fdr", collapse_levels=TRUE)
## cat0(sep0)
## print(ggeff$test3, n = Inf)
ggeff$test4 <- ggeff$test3 %>% as_tibble() %>%
  dplyr::mutate(
    PhaseDashCount = str_count(Phase, fixed("-")),
    OutcomeDashCount = str_count(Outcome, fixed("-")),
    TotalDashCount = PhaseDashCount + OutcomeDashCount,
    ) %>%
  dplyr::filter(TotalDashCount==1) %>%
  dplyr::select(-TotalDashCount) %>%
  dplyr::arrange(PhaseDashCount, Outcome, Phase) %>%
  dplyr::select(-c(PhaseDashCount, OutcomeDashCount)) %>%
  identity()

print(ggeff$test4)
# A tibble: 16 × 7
   Time  Outcome      Phase Contrast conf.low conf.high  p.value
   <chr> <chr>        <chr>    <dbl>    <dbl>     <dbl>    <dbl>
 1 slope loser-winner AE     -0.147  -0.262     -0.0321 1.27e- 2
 2 slope loser-winner AR      0.0652  0.0321     0.0982 1.34e- 4
 3 slope loser-winner BE      0.0204  0.00628    0.0345 5.18e- 3
 4 slope loser-winner BR     -0.605  -1.04      -0.172  6.62e- 3
 5 slope loser        AE-AR  -0.432  -0.535     -0.330  2.45e-16
 6 slope loser        AE-BR  -1.64   -2.03      -1.26   1.47e-16
 7 slope loser        BE-AE   0.491   0.392      0.590  7.06e-22
 8 slope loser        BE-AR   0.0582  0.0284     0.0881 1.53e- 4
 9 slope loser        BE-BR  -1.15   -1.52      -0.779  1.82e- 9
10 slope loser        BR-AR   1.21    0.836      1.58   3.23e-10
11 slope winner       AE-AR  -0.220  -0.281     -0.160  1.55e-12
12 slope winner       AE-BR  -2.10   -2.33      -1.87   5.37e-72
13 slope winner       BE-AE   0.323   0.264      0.382  2.74e-26
14 slope winner       BE-AR   0.103   0.0869     0.119  2.74e-35
15 slope winner       BE-BR  -1.78   -2.00      -1.56   9.36e-56
16 slope winner       BR-AR   1.88    1.66       2.10   7.56e-62

Plot: Basic

Code
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- ggeff$pred0 %>% plot(limit_range=FALSE, show_data = FALSE, dot_alpha = 0.05)
gg88 <- gg88 + timeD + lineE + lineT + lineR + rect0 + cogsys::theme0 + scaleA

ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.png"), plot = gg88 + cogsys::theme2, width=8, height=24)

ggsave(file = paste0(ggeff$fbasefig, "-pred0-fig.svg"), plot = gg88 + cogsys::theme2, width=24, height=72, limitsize = FALSE)

ggsave(file = paste0(ggeff$fbasefig, "-pred0-Fig.svg"), plot = gg88 + cogsys::theme2, width=24, height=96, limitsize = FALSE)

gg88

Plot: Nicer

Code
# knitr::opts_chunk$set(fig.width=unit(12,"cm"), fig.height=unit(18,"cm"))
# gg88
suppressWarnings(rm(list = ls(pattern = "^gg99")))
gg99 <- gg88 + cogsys::theme2 + scaleA

ggsave(file = paste0(ggeff$fbasefig, "-pred0-FIG.svg"), plot = gg99 + cogsys::theme2, width=24, height=96, limitsize = FALSE)

## gg99

Save Workspace

Code
save.image(file=file.path(ofd4, "session0.RData"))
## load(file.path(ofd4, "session0.RData"))
## load(file.path(ofd4, "session2.RData"))

Model fit04xPh: Time x Phase x Outcome

Prepare Data for the Re-scaled Model

Code
count8 = 15e3
count8 = 1e3

df8 <- df0 %>% 
  ## dplyr::group_by(Phase) %>%        ## CAUTION 
  ## dplyr::slice_sample(n=count8) %>% ## CAUTION 
  bruceR::grand_mean_center(
    vars=c("Agency", "Time"), 
    std=FALSE, 
    add.suffix="C") %>%
  identity()

contrasts(df8$Phase) <- contr.sum(levels(df8$Phase))
contrasts(df8$Outcome) <- contr.sum(levels(df8$Outcome))

contrasts(df8$Phase)
   [,1] [,2] [,3]
BE    1    0    0
AE    0    1    0
BR    0    0    1
AR   -1   -1   -1
Code
contrasts(df8$Outcome)
       [,1]
loser     1
winner   -1
Code
## attributes(df8$Phase)
## attributes(df8$Outcome)

Fit

Code
model <- "fit04xPh"
suppressWarnings(rm(list = model))
assign(
  model,
  lmerTest::lmer(
    ## formula = AgencyC ~ (TimeC | Name) + TimeC, ## CAUTION
    formula = AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome,
    data = df8,
    REML = REML,
    control = control))

fbase <- get_model_info(model, ofd4)
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
   Data: df8
Control: control

REML criterion at convergence: 23562.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-8.1902 -0.5632 -0.0074  0.5639  7.3864 

Random effects:
 Groups   Name        Variance Std.Dev. Corr 
 Name     (Intercept) 0.004849 0.06963       
          TimeC       0.003347 0.05786  -0.12
 Residual             0.065916 0.25674       
Number of obs: 169997, groups:  Name, 870

Fixed effects:
                        Estimate Std. Error         df t value Pr(>|t|)    
(Intercept)           -1.430e-01  1.111e-02  1.138e+05 -12.873  < 2e-16 ***
TimeC                  2.911e-01  2.871e-02  1.687e+05  10.141  < 2e-16 ***
Phase1                 1.673e-01  1.088e-02  1.689e+05  15.372  < 2e-16 ***
Phase2                 1.815e-01  1.164e-02  1.688e+05  15.591  < 2e-16 ***
Phase3                -4.760e-01  3.189e-02  1.689e+05 -14.925  < 2e-16 ***
Outcome1              -2.021e-02  1.111e-02  1.138e+05  -1.819  0.06893 .  
TimeC:Phase1          -2.443e-01  2.870e-02  1.689e+05  -8.510  < 2e-16 ***
TimeC:Phase2          -6.511e-01  3.535e-02  1.690e+05 -18.419  < 2e-16 ***
TimeC:Phase3           1.220e+00  8.317e-02  1.689e+05  14.671  < 2e-16 ***
TimeC:Outcome1        -8.335e-02  2.871e-02  1.687e+05  -2.904  0.00369 ** 
Phase1:Outcome1        7.600e-03  1.088e-02  1.689e+05   0.698  0.48496    
Phase2:Outcome1       -1.568e-02  1.164e-02  1.688e+05  -1.347  0.17804    
Phase3:Outcome1        7.591e-02  3.189e-02  1.689e+05   2.380  0.01730 *  
TimeC:Phase1:Outcome1  9.355e-02  2.870e-02  1.689e+05   3.259  0.00112 ** 
TimeC:Phase2:Outcome1  9.791e-03  3.535e-02  1.690e+05   0.277  0.78180    
TimeC:Phase3:Outcome1 -2.193e-01  8.317e-02  1.689e+05  -2.636  0.00838 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
--------------------------------------------------------------------- 
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
# R2 for Mixed Models

  Conditional R2: 0.102
     Marginal R2: 0.021
--------------------------------------------------------------------- 
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
# Intraclass Correlation Coefficient

    Adjusted ICC: 0.083
  Unadjusted ICC: 0.081
--------------------------------------------------------------------- 
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
# ICC by Group

Group |   ICC
-------------
Name  | 0.067
--------------------------------------------------------------------- 

Performance: Check Model (EXPERIMENTAL)

Code
model <- "fit04xPh"
pp(model)
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
Code
do_checks <- TRUE
do_checks <- FALSE

if (do_checks) {

  knitr::opts_chunk$set(fig.width=unit(8,"cm"), fig.height=unit(24,"cm"))

  suppressWarnings(rm(list = ls(pattern = "^check8")))
  check8 <- performance::check_model(get(model))

  suppressWarnings(rm(list = ls(pattern = "^gg88")))
  gg88 <- plot(check8)
  ## gg88
}

Save checks plot

Code
model <- "fit04xPh"
pp(model)
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
Code
if (do_checks) {
  model <- "fit04xPh"
  pp(model)

  knitr::opts_chunk$set(fig.width=unit(8,"cm"), fig.height=unit(24,"cm"))

  ggsave(
    file = file.path(ofd4, paste0("summary-check-model-", model, ".png")),
    plot = gg88,
    ## plot = last_plot(),
    width=8,
    height=24)
}

Performance: Check Collinearity

Code
model <- "fit04xPh"
pp(model)
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
Code
## performance::check_collinearity(get(model))

Performance: Check Convergence

Code
model <- "fit04xPh"
pp(model)
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
Code
performance::check_convergence(get(model))
[1] TRUE
attr(,"gradient")
[1] 4.648806e-06

Performance: Check Heteroscedasticity

Code
model <- "fit04xPh"
pp(model)
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
Code
performance::check_heteroscedasticity(get(model))
Warning: Heteroscedasticity (non-constant error variance) detected (p < .001).

Performance: Check Homogeneity

Code
model <- "fit04xPh"
pp(model)
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
Code
## performance::check_homogeneity(get(model))

Performance: Check Outliers

Code
model <- "fit04xPh"
pp(model)
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
Code
performance::check_outliers(get(model))
OK: No outliers detected.
- Based on the following method and threshold: cook (0.7).
- For variable: (Whole model)

Performance: Check Overdispersion

Code
model <- "fit04xPh"
pp(model)
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
Code
performance::check_overdispersion(get(model))
# Overdispersion test

 dispersion ratio = 0.992
          p-value = 0.152

Performance: Check Predictions

Code
model <- "fit04xPh"
pp(model)
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
Code
performance::check_predictions(get(model))
Warning: Minimum value of original data is not included in the
  replicated data.
  Model may not capture the variation of the data.Warning: Maximum value of original data is not included in the
  replicated data.
  Model may not capture the variation of the data.

Performance: Check Singularity

Code
model <- "fit04xPh"
pp(model)
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
Code
performance::check_singularity(get(model))
[1] FALSE

Performance: Check Zeroinflation

Code
model <- "fit04xPh"
pp(model)
fit04xPh: [df8] AgencyC ~ (TimeC | Name) + TimeC * Phase * Outcome
Code
## performance::check_zeroinflation(get(model))

Performance

Reclaim Model fit04aPh

Code
model <- "fit02aPh"
model <- "fit03aPh"
model <- "fit04aPh"
cat0(model)
fit04aPh 

Score

Code
file = file.path(
  ofd4, "summary-performance-score.png")

perf0 <- performance::compare_performance(
  fit01aPh, # [df0] Agency ~ (1 | Name) + 1
  fit02aPh, # [df0] Agency ~ (Time | Name) + Time
  fit03aPh, # [df0] Agency ~ (Time | Name) + Time * Phase
  fit04aPh, # [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
  ## CAUTION: COMMA
  rank = TRUE, verbose = FALSE)

perf0 %>% performance::print_html()
Comparison of Model Performance Indices
Name Model R2 (cond.) R2 (marg.) ICC RMSE Sigma AIC weights AICc weights BIC weights Performance-Score
fit04aPh lmerModLmerTest 0.10 0.02 0.08 0.26 0.26 1.00 1.00 1.00 84.61%
fit03aPh lmerModLmerTest 0.11 6.03e-03 0.10 0.26 0.26 2.51e-118 2.51e-118 7.03e-101 52.18%
fit02aPh lmerModLmerTest 0.10 4.62e-04 0.10 0.26 0.26 9.57e-321 9.58e-321 3.26e-290 40.78%
fit01aPh lmerModLmerTest 0.08 0.00 0.08 0.26 0.26 0.00e+00 0.00e+00 0.00e+00 0.99%
NA
Code
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- perf0 %>% plot()
ggsave(
  file = file,
  plot = gg88,
  width=8,
  height=6)

knitr::opts_chunk$set(fig.width=unit(6,"cm"), fig.height=unit(6,"cm"))
gg88

Performance Table Sorted by R2_conditional

Code
perf0 %>% dplyr::arrange(desc(R2_conditional)) %>% performance::print_html()
Comparison of Model Performance Indices
Name Model R2 (cond.) R2 (marg.) ICC RMSE Sigma AIC weights AICc weights BIC weights Performance-Score
fit03aPh lmerModLmerTest 0.11 6.03e-03 0.10 0.26 0.26 2.51e-118 2.51e-118 7.03e-101 52.18%
fit02aPh lmerModLmerTest 0.10 4.62e-04 0.10 0.26 0.26 9.57e-321 9.58e-321 3.26e-290 40.78%
fit04aPh lmerModLmerTest 0.10 0.02 0.08 0.26 0.26 1.00 1.00 1.00 84.61%
fit01aPh lmerModLmerTest 0.08 0.00 0.08 0.26 0.26 0.00e+00 0.00e+00 0.00e+00 0.99%
NA

Performance Table Sorted by R2_marginal

Code
perf0 %>% dplyr::arrange(desc(R2_marginal)) %>% performance::print_html()
Comparison of Model Performance Indices
Name Model R2 (cond.) R2 (marg.) ICC RMSE Sigma AIC weights AICc weights BIC weights Performance-Score
fit04aPh lmerModLmerTest 0.10 0.02 0.08 0.26 0.26 1.00 1.00 1.00 84.61%
fit03aPh lmerModLmerTest 0.11 6.03e-03 0.10 0.26 0.26 2.51e-118 2.51e-118 7.03e-101 52.18%
fit02aPh lmerModLmerTest 0.10 4.62e-04 0.10 0.26 0.26 9.57e-321 9.58e-321 3.26e-290 40.78%
fit01aPh lmerModLmerTest 0.08 0.00 0.08 0.26 0.26 0.00e+00 0.00e+00 0.00e+00 0.99%
NA

Interpret R2

Code
model <- "fit01aPh" # [df0] Agency ~ (1 | Name) + 1
model <- "fit02aPh" # [df0] Agency ~ (Time | Name) + Time
model <- "fit03aPh" # [df0] Agency ~ (Time | Name) + Time * Phase
model <- "fit04aPh" # [df0] Agency ~ (Time | Name) + Time * Phase * Outcome

cat0(effectsize::interpret_r2(performance::r2(get(model))$R2_conditional, rules="cohen1988"))
weak 
Code
cat0(effectsize::interpret_r2(performance::r2(get(model))$R2_marginal, rules="cohen1988"))
weak 

Plot models

Code
suppressWarnings(rm(list = ls(pattern = "^gg88")))
gg88 <- sjPlot::plot_models(
  ## CAUTION the null model can not be used here 
  ## Thus to keep the numbers consistent I have 
  ## used model 02 as an input twice
  ## fit01aPh, # [df0] Agency ~ (Time | Name) + Time
  fit02aPh, # [df0] Agency ~ (Time | Name) + Time
  fit03aPh, # [df0] Agency ~ (Time | Name) + Time * Phase
  fit04aPh, # [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
  fit04cPh,
  m.labels = c("Model 2", "Model 3", "Model 4", "Model 4concr"),
  legend.title = "Model",
  spacing=1, 
  dot.size=1
) + line0h

ggsave(
  file = file.path(ofd4, "summary-plot-models-i0001-base.png"),
  plot = gg88,
  width=8,
  height=8)

knitr::opts_chunk$set(fig.width=unit(6,"cm"), fig.height=unit(6,"cm"))
gg88

Tabulate Models

Code
## library(sjPlot)
## library(sjmisc)
## library(sjlabelled)

file <- file.path(ofd4, "summary-tab-model-i0001-base.html")
sjPlot::tab_model(
  fit01aPh, # [df0] Agency ~ (1 | Name) + 1
  fit02aPh, # [df0] Agency ~ (Time | Name) + Time
  fit03aPh, # [df0] Agency ~ (Time | Name) + Time * Phase
  fit04aPh, # [df0] Agency ~ (Time | Name) + Time * Phase * Outcome
  show.reflvl = FALSE,
  show.intercept = TRUE,
  show.p = FALSE,
  p.style = "numeric_stars",
  dv.labels = c("Model 1", "Model 2", "Model 3", "Model 4"),
  wrap.labels = 225,  
  file = file)
  Model 1 Model 2 Model 3 Model 4
Predictors Estimates CI Estimates CI Estimates CI Estimates CI
(Intercept) 0.50 *** 0.49 – 0.50 0.50 *** 0.49 – 0.50 0.53 *** 0.52 – 0.53 0.52 *** 0.51 – 0.52
Time -0.01 *** -0.02 – -0.01 0.04 *** 0.04 – 0.05 0.06 *** 0.05 – 0.07
Phase [AE] -0.00 -0.01 – 0.00 -0.04 *** -0.06 – -0.03
Phase [BR] -0.57 *** -0.63 – -0.51 -0.50 *** -0.61 – -0.38
Phase [AR] -0.01 -0.02 – 0.00 -0.12 *** -0.14 – -0.10
Time × Phase [AE] -0.36 *** -0.41 – -0.31 -0.49 *** -0.59 – -0.39
Time × Phase [BR] 1.61 *** 1.42 – 1.80 1.15 *** 0.78 – 1.52
Time × Phase [AR] -0.10 *** -0.11 – -0.09 -0.06 *** -0.09 – -0.03
Outcome [winner] 0.02 *** 0.01 – 0.04
Time × Outcome [winner] -0.02 ** -0.03 – -0.01
Phase [AE] × Outcome [winner] 0.06 *** 0.04 – 0.08
Phase [BR] × Outcome [winner] -0.09 -0.23 – 0.04
Phase [AR] × Outcome [winner] 0.15 *** 0.12 – 0.17
(Time × Phase [AE]) × Outcome [winner] 0.17 ** 0.05 – 0.28
(Time × Phase [BR]) × Outcome [winner] 0.63 ** 0.19 – 1.06
(Time × Phase [AR]) × Outcome [winner] -0.04 ** -0.08 – -0.01
Random Effects
σ2 0.07 0.07 0.07 0.07
τ00 0.01 Name 0.01 Name 0.01 Name 0.00 Name
τ11   0.00 Name.Time 0.00 Name.Time 0.00 Name.Time
ρ01   0.18 Name 0.18 Name -0.07 Name
ICC 0.08 0.10 0.10 0.08
N 870 Name 870 Name 870 Name 870 Name
Observations 169997 169997 169997 169997
Marginal R2 / Conditional R2 0.000 / 0.084 0.000 / 0.102 0.006 / 0.107 0.021 / 0.102
* p<0.05   ** p<0.01   *** p<0.001
Code
## knitr::html
## papaja::
## rmarkdown::render
## rmarkdown::render(tab0$knitr)
## tab0$knitr
cat0(file)
./data/20240428T200156-politicians-aux-analysis/n0001-init//n0001-models-phase-i0008-all/summary-tab-model-i0001-base.html 

Report fit01aPh

Code
result01aPh <- report::report(fit01aPh)
Code
print(result01aPh)
We fitted a constant (intercept-only) linear mixed model (estimated using REML
and Nelder-Mead optimizer) to predict Agency (formula: Agency ~ 1). The model
included Name as random effect (formula: ~1 | Name). The model's intercept is
at 0.50 (95% CI [0.49, 0.50], t(169994) = 177.65, p < .001).

Standardized parameters were obtained by fitting the model on a standardized
version of the dataset. 95% Confidence Intervals (CIs) and p-values were
computed using a Wald t-distribution approximation.

Report fit02aPh

Code
result02aPh <- report::report(fit02aPh)
Code
print(result02aPh)
We fitted a linear mixed model (estimated using REML and Nelder-Mead optimizer)
to predict Agency with Time (formula: Agency ~ Time). The model included Time
as random effects (formula: ~Time | Name). The model's total explanatory power
is weak (conditional R2 = 0.10) and the part related to the fixed effects alone
(marginal R2) is of 4.62e-04. The model's intercept, corresponding to Time = 0,
is at 0.50 (95% CI [0.49, 0.50], t(169991) = 174.88, p < .001). Within this
model:

  - The effect of Time is statistically significant and negative (beta = -0.01,
95% CI [-0.02, -5.07e-03], t(169991) = -3.88, p < .001; Std. beta = -0.02, 95%
CI [-0.03, -0.01])

Standardized parameters were obtained by fitting the model on a standardized
version of the dataset. 95% Confidence Intervals (CIs) and p-values were
computed using a Wald t-distribution approximation.

Report fit03aPh

Code
result03aPh <- report::report(fit03aPh)
Code
print(result03aPh)
We fitted a linear mixed model (estimated using REML and Nelder-Mead optimizer)
to predict Agency with Time and Phase (formula: Agency ~ Time * Phase). The
model included Time as random effects (formula: ~Time | Name). The model's
total explanatory power is weak (conditional R2 = 0.11) and the part related to
the fixed effects alone (marginal R2) is of 6.03e-03. The model's intercept,
corresponding to Time = 0 and Phase = BE, is at 0.53 (95% CI [0.52, 0.53],
t(169985) = 166.75, p < .001). Within this model:

  - The effect of Time is statistically significant and positive (beta = 0.04,
95% CI [0.04, 0.05], t(169985) = 12.19, p < .001; Std. beta = 0.09, 95% CI
[0.08, 0.11])
  - The effect of Phase [AE] is statistically non-significant and negative (beta
= -4.14e-03, 95% CI [-0.01, 4.04e-03], t(169985) = -0.99, p = 0.321; Std. beta
= 0.07, 95% CI [0.03, 0.12])
  - The effect of Phase [BR] is statistically significant and negative (beta =
-0.57, 95% CI [-0.63, -0.51], t(169985) = -18.56, p < .001; Std. beta = -2.51,
95% CI [-2.78, -2.24])
  - The effect of Phase [AR] is statistically non-significant and negative (beta
= -9.12e-03, 95% CI [-0.02, 5.54e-04], t(169985) = -1.85, p = 0.065; Std. beta
= -8.65e-03, 95% CI [-0.05, 0.03])
  - The effect of Time × Phase [AE] is statistically significant and negative
(beta = -0.36, 95% CI [-0.41, -0.31], t(169985) = -13.82, p < .001; Std. beta =
-0.76, 95% CI [-0.86, -0.65])
  - The effect of Time × Phase [BR] is statistically significant and positive
(beta = 1.61, 95% CI [1.42, 1.80], t(169985) = 16.65, p < .001; Std. beta =
3.40, 95% CI [3.00, 3.80])
  - The effect of Time × Phase [AR] is statistically significant and negative
(beta = -0.10, 95% CI [-0.11, -0.09], t(169985) = -13.81, p < .001; Std. beta =
-0.21, 95% CI [-0.24, -0.18])

Standardized parameters were obtained by fitting the model on a standardized
version of the dataset. 95% Confidence Intervals (CIs) and p-values were
computed using a Wald t-distribution approximation.

Report fit04aPh

Code
result04aPh <- report::report(fit04aPh)
Code
print(result04aPh)
We fitted a linear mixed model (estimated using REML and Nelder-Mead optimizer)
to predict Agency with Time, Phase and Outcome (formula: Agency ~ Time * Phase
* Outcome). The model included Time as random effects (formula: ~Time | Name).
The model's total explanatory power is weak (conditional R2 = 0.10) and the
part related to the fixed effects alone (marginal R2) is of 0.02. The model's
intercept, corresponding to Time = 0, Phase = BE and Outcome = loser, is at
0.52 (95% CI [0.51, 0.52], t(169977) = 115.77, p < .001). Within this model:

  - The effect of Time is statistically significant and positive (beta = 0.06,
95% CI [0.05, 0.07], t(169977) = 10.19, p < .001; Std. beta = 0.12, 95% CI
[0.10, 0.14])
  - The effect of Phase [AE] is statistically significant and negative (beta =
-0.04, 95% CI [-0.06, -0.03], t(169977) = -5.52, p < .001; Std. beta = -0.03,
95% CI [-0.11, 0.04])
  - The effect of Phase [BR] is statistically significant and negative (beta =
-0.50, 95% CI [-0.61, -0.38], t(169977) = -8.24, p < .001; Std. beta = -2.12,
95% CI [-2.65, -1.60])
  - The effect of Phase [AR] is statistically significant and negative (beta =
-0.12, 95% CI [-0.14, -0.10], t(169977) = -11.56, p < .001; Std. beta = -0.43,
95% CI [-0.51, -0.35])
  - The effect of Outcome [winner] is statistically significant and positive
(beta = 0.02, 95% CI [0.01, 0.04], t(169977) = 4.07, p < .001; Std. beta =
0.09, 95% CI [0.05, 0.13])
  - The effect of Time × Phase [AE] is statistically significant and negative
(beta = -0.49, 95% CI [-0.59, -0.39], t(169977) = -9.71, p < .001; Std. beta =
-1.04, 95% CI [-1.25, -0.83])
  - The effect of Time × Phase [BR] is statistically significant and positive
(beta = 1.15, 95% CI [0.78, 1.52], t(169977) = 6.05, p < .001; Std. beta =
2.43, 95% CI [1.64, 3.22])
  - The effect of Time × Phase [AR] is statistically significant and negative
(beta = -0.06, 95% CI [-0.09, -0.03], t(169977) = -3.82, p < .001; Std. beta =
-0.12, 95% CI [-0.19, -0.06])
  - The effect of Time × Outcome [winner] is statistically significant and
negative (beta = -0.02, 95% CI [-0.03, -6.28e-03], t(169977) = -2.83, p =
0.005; Std. beta = -0.04, 95% CI [-0.07, -0.01])
  - The effect of Phase [AE] × Outcome [winner] is statistically significant and
positive (beta = 0.06, 95% CI [0.04, 0.08], t(169977) = 6.32, p < .001; Std.
beta = 0.17, 95% CI [0.08, 0.26])
  - The effect of Phase [BR] × Outcome [winner] is statistically non-significant
and negative (beta = -0.09, 95% CI [-0.23, 0.04], t(169977) = -1.34, p = 0.179;
Std. beta = -0.50, 95% CI [-1.12, 0.11])
  - The effect of Phase [AR] × Outcome [winner] is statistically significant and
positive (beta = 0.15, 95% CI [0.12, 0.17], t(169977) = 12.55, p < .001; Std.
beta = 0.56, 95% CI [0.47, 0.65])
  - The effect of (Time × Phase [AE]) × Outcome [winner] is statistically
significant and positive (beta = 0.17, 95% CI [0.05, 0.28], t(169977) = 2.85, p
= 0.004; Std. beta = 0.35, 95% CI [0.11, 0.60])
  - The effect of (Time × Phase [BR]) × Outcome [winner] is statistically
significant and positive (beta = 0.63, 95% CI [0.19, 1.06], t(169977) = 2.83, p
= 0.005; Std. beta = 1.32, 95% CI [0.41, 2.24])
  - The effect of (Time × Phase [AR]) × Outcome [winner] is statistically
significant and negative (beta = -0.04, 95% CI [-0.08, -0.01], t(169977) =
-2.59, p = 0.010; Std. beta = -0.09, 95% CI [-0.17, -0.02])

Standardized parameters were obtained by fitting the model on a standardized
version of the dataset. 95% Confidence Intervals (CIs) and p-values were
computed using a Wald t-distribution approximation.

Save Workspace

Code
save.image(file=file.path(ofd4, "session3.RData"))
## load(file.path(ofd4, "session3.RData")

List important variables

Code
cat0(sep0)
===================================================================== 
Code
for (var0 in ls(pattern = "(^df.*)|(^data.*)")) {cat0(var0)}
df0 
df2 
df3 
df5 
df8 
Code
cat0(sep0)
===================================================================== 
Code
for (var0 in ls(pattern = "(^fit.*)|(^xFit.*)")) {cat0(var0)}
fit01aPh 
fit02aPh 
fit03aPh 
fit04aPh 
fit04cPh 
fit04xPh