Robustness analyses

knitr::opts_chunk$set(error = TRUE)
source("0_helpers.R")
library(knitr) # um diese dokumente zu generieren
library(formr) # formr paket, kann daten laden
opts_chunk$set(warning = F, message = F, error = T, fig.width = 10, fig.height = 10)
library(lubridate) # mit datum-uhrzeit rechnen
library(pander) # schoen formatierte tabellen
library(ggplot2)
library(tidyr) # daten von lang nach breit und zurueck
library(dplyr) # daten zusammenfassen etc. immer als letztes laden
diary <- readRDS("diary_persons.rds")

library(brms)
options(brms.backend = "cmdstanr",
        mc.cores = 4)

time spent with family

model2_family <- brm(time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person), data = diary %>% filter(reasons_for_exclusion == "" | reasons_for_exclusion == "not_single, "), cores = 4, file = "brms_fits/model2_family3")

do_model(model2_family, diary %>% mutate(reasons_for_exclusion = str_replace_all(reasons_for_exclusion, "not_single, ", "")), model_prefix = "family_")

Robustness checks

Basic model

library(effects); library(lme4); library(lmerTest); library(knitr); library(brms)

summary(model)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "" | rea (Number of observations: 24450) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 793) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.49      0.02     0.45     0.54 1.00     2011     2789
## sd(fertile_fab)                0.69      0.06     0.54     0.84 1.00     1204     2107
## cor(Intercept,fertile_fab)    -0.31      0.07    -0.47    -0.13 1.00     3488     3232
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.71      0.03     1.64     1.78 1.00     2155
## premenstrual_phase_fabTRUE                               -0.01      0.03    -0.08     0.05 1.00     5308
## menstruation                                              0.08      0.03     0.01     0.16 1.00     6070
## fertile_fab                                              -0.01      0.06    -0.17     0.15 1.00     4801
## hormonal_contraceptionTRUE                                0.06      0.05    -0.07     0.20 1.00     2318
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.06      0.05    -0.07     0.18 1.00     5131
## menstruation:hormonal_contraceptionTRUE                   0.00      0.06    -0.15     0.16 1.00     5411
## fertile_fab:hormonal_contraceptionTRUE                    0.07      0.12    -0.24     0.37 1.00     4271
##                                                       Tail_ESS
## Intercept                                                 3115
## premenstrual_phase_fabTRUE                                3246
## menstruation                                              3577
## fertile_fab                                               3520
## hormonal_contraceptionTRUE                                3016
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3348
## menstruation:hormonal_contraceptionTRUE                   3506
## fertile_fab:hormonal_contraceptionTRUE                    3671
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.13      0.01     1.11     1.14 1.00     5864     2978
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).
outcome <- model$formula[[1]][[2]]

Full random slopes

add_mod_formula = update.formula(
    formula(model),
    new = as.formula(. ~ . - (1 + fertile_fab | person) + (1 + premenstrual_phase_fab + menstruation + fertile_fab | person ))) # reorder so that the triptych looks nice

 full_random_slopes = update(model, recompile = TRUE, iter = 6000, warmup = 4000, cores = 4, formula = add_mod_formula, newdata = diary %>% filter(reasons_for_exclusion == ""), file= paste0("brms_fits/", model_prefix, "rob_check_full_random_slopes"))

summary(full_random_slopes)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ premenstrual_phase_fab + menstruation + fertile_fab + hormonal_contraception + (1 + premenstrual_phase_fab + menstruation + fertile_fab | person) + premenstrual_phase_fab:hormonal_contraception + menstruation:hormonal_contraception + fertile_fab:hormonal_contraception 
##    Data: diary %>% filter(reasons_for_exclusion == "") (Number of observations: 24450) 
## Samples: 4 chains, each with iter = 6000; warmup = 4000; thin = 1;
##          total post-warmup samples = 8000
## 
## Group-Level Effects: 
## ~person (Number of levels: 793) 
##                                              Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                                    0.51      0.02     0.45     0.57 1.00     2910     4345
## sd(premenstrual_phase_fabTRUE)                   0.32      0.04     0.22     0.41 1.00     1162     2178
## sd(menstruation)                                 0.40      0.04     0.28     0.51 1.00     1313     2325
## sd(fertile_fab)                                  0.76      0.08     0.56     0.95 1.00      975     2601
## cor(Intercept,premenstrual_phase_fabTRUE)       -0.23      0.09    -0.44     0.04 1.00     2123     4471
## cor(Intercept,menstruation)                     -0.20      0.09    -0.42     0.07 1.00     1756     3644
## cor(premenstrual_phase_fabTRUE,menstruation)     0.41      0.13     0.03     0.70 1.01      974     1963
## cor(Intercept,fertile_fab)                      -0.36      0.08    -0.54    -0.14 1.00     2347     4212
## cor(premenstrual_phase_fabTRUE,fertile_fab)      0.37      0.12     0.01     0.65 1.00      739     1885
## cor(menstruation,fertile_fab)                    0.27      0.13    -0.13     0.56 1.00      748     1410
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.71      0.03     1.64     1.79 1.00     3151
## premenstrual_phase_fabTRUE                               -0.02      0.03    -0.09     0.06 1.00     5265
## menstruation                                              0.08      0.04    -0.01     0.17 1.00     5878
## fertile_fab                                              -0.01      0.06    -0.18     0.15 1.00     5406
## hormonal_contraceptionTRUE                                0.07      0.05    -0.07     0.21 1.00     3080
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.06      0.05    -0.08     0.20 1.00     4753
## menstruation:hormonal_contraceptionTRUE                   0.01      0.07    -0.16     0.18 1.00     5772
## fertile_fab:hormonal_contraceptionTRUE                    0.07      0.12    -0.25     0.38 1.00     4832
##                                                       Tail_ESS
## Intercept                                                 4803
## premenstrual_phase_fabTRUE                                6135
## menstruation                                              6119
## fertile_fab                                               5329
## hormonal_contraceptionTRUE                                4257
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     6272
## menstruation:hormonal_contraceptionTRUE                   5629
## fertile_fab:hormonal_contraceptionTRUE                    5444
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.12      0.01     1.10     1.13 1.00     8399     4657
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Full random slopes, no correlations

add_mod_formula = update.formula(
    formula(model),
    new = as.formula(. ~ . - (1 + fertile_fab | person) + (1 + premenstrual_phase_fab + menstruation + fertile_fab || person ))) # reorder so that the triptych looks nice

 full_random_slopes_no_cor = update(model, recompile = TRUE, iter = 6000, warmup = 4000, cores = 4, formula = add_mod_formula, newdata = diary %>% filter(reasons_for_exclusion == ""), file= paste0("brms_fits/", model_prefix, "rob_check_full_random_slopes_no_cor"))

summary(full_random_slopes_no_cor)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ premenstrual_phase_fab + menstruation + fertile_fab + hormonal_contraception + (1 + premenstrual_phase_fab + menstruation + fertile_fab || person) + premenstrual_phase_fab:hormonal_contraception + menstruation:hormonal_contraception + fertile_fab:hormonal_contraception 
##    Data: diary %>% filter(reasons_for_exclusion == "") (Number of observations: 24450) 
## Samples: 4 chains, each with iter = 6000; warmup = 4000; thin = 1;
##          total post-warmup samples = 8000
## 
## Group-Level Effects: 
## ~person (Number of levels: 793) 
##                                Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                      0.46      0.02     0.42     0.50 1.00     3389     4898
## sd(premenstrual_phase_fabTRUE)     0.26      0.03     0.18     0.33 1.00     2140     3490
## sd(menstruation)                   0.35      0.04     0.25     0.44 1.00     2645     4655
## sd(fertile_fab)                    0.58      0.06     0.41     0.72 1.00     1933     3265
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.71      0.03     1.64     1.78 1.00     3861
## premenstrual_phase_fabTRUE                               -0.02      0.03    -0.09     0.05 1.00     8864
## menstruation                                              0.08      0.03    -0.01     0.17 1.00     8537
## fertile_fab                                              -0.02      0.06    -0.17     0.14 1.00     8306
## hormonal_contraceptionTRUE                                0.07      0.05    -0.06     0.20 1.00     3736
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.06      0.05    -0.08     0.19 1.00     7263
## menstruation:hormonal_contraceptionTRUE                   0.00      0.06    -0.16     0.17 1.00     7634
## fertile_fab:hormonal_contraceptionTRUE                    0.06      0.11    -0.24     0.35 1.00     7404
##                                                       Tail_ESS
## Intercept                                                 5268
## premenstrual_phase_fabTRUE                                6931
## menstruation                                              6777
## fertile_fab                                               6725
## hormonal_contraceptionTRUE                                4868
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     6016
## menstruation:hormonal_contraceptionTRUE                   6302
## fertile_fab:hormonal_contraceptionTRUE                    6655
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.12      0.01     1.11     1.13 1.00    10762     6072
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Without random slopes

no_varying_slope = update(model, recompile = TRUE, formula = . ~ . - (1 + fertile_fab | person) + (1|person), cores = 4, file = paste0("brms_fits/", model_prefix, "rob_check_no_varying_slope"))

summary(no_varying_slope)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ premenstrual_phase_fab + menstruation + fertile_fab + hormonal_contraception + (1 | person) + premenstrual_phase_fab:hormonal_contraception + menstruation:hormonal_contraception + fertile_fab:hormonal_contraception 
##    Data: diary %>% filter(reasons_for_exclusion == "" | rea (Number of observations: 24450) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 793) 
##               Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.47      0.02     0.43     0.51 1.00      657     1096
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.71      0.03     1.64     1.78 1.00      870
## premenstrual_phase_fabTRUE                               -0.01      0.03    -0.08     0.05 1.00     2413
## menstruation                                              0.08      0.03     0.01     0.16 1.00     2630
## fertile_fab                                              -0.01      0.06    -0.16     0.13 1.00     2329
## hormonal_contraceptionTRUE                                0.07      0.05    -0.06     0.20 1.01      833
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.06      0.05    -0.07     0.18 1.00     1867
## menstruation:hormonal_contraceptionTRUE                  -0.00      0.06    -0.15     0.15 1.00     2130
## fertile_fab:hormonal_contraceptionTRUE                    0.05      0.11    -0.23     0.32 1.00     1851
##                                                       Tail_ESS
## Intercept                                                 1493
## premenstrual_phase_fabTRUE                                2664
## menstruation                                              2884
## fertile_fab                                               2671
## hormonal_contraceptionTRUE                                1487
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     2338
## menstruation:hormonal_contraceptionTRUE                   2685
## fertile_fab:hormonal_contraceptionTRUE                    2241
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.14      0.01     1.12     1.15 1.00     7181     2760
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Only women with outcome variability

with_outcome_var = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "") %>% group_by(session) %>% filter(sd(!!outcome, na.rm = T) > 0), file = paste0("brms_fits/", model_prefix, "rob_check_with_outcome_var"))

summary(with_outcome_var)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 24326) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 775) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.49      0.02     0.44     0.53 1.00     2216     2943
## sd(fertile_fab)                0.70      0.06     0.55     0.84 1.00     1307     2166
## cor(Intercept,fertile_fab)    -0.32      0.07    -0.47    -0.13 1.00     4274     3331
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.71      0.03     1.64     1.78 1.00     1992
## premenstrual_phase_fabTRUE                               -0.01      0.03    -0.08     0.05 1.00     5374
## menstruation                                              0.08      0.03     0.01     0.16 1.00     6014
## fertile_fab                                              -0.01      0.06    -0.17     0.16 1.00     4759
## hormonal_contraceptionTRUE                                0.07      0.05    -0.07     0.21 1.00     1981
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.06      0.05    -0.06     0.18 1.00     4337
## menstruation:hormonal_contraceptionTRUE                  -0.00      0.06    -0.15     0.15 1.00     5884
## fertile_fab:hormonal_contraceptionTRUE                    0.07      0.12    -0.24     0.38 1.00     4080
##                                                       Tail_ESS
## Intercept                                                 2599
## premenstrual_phase_fabTRUE                                3305
## menstruation                                              2977
## fertile_fab                                               3409
## hormonal_contraceptionTRUE                                2613
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3109
## menstruation:hormonal_contraceptionTRUE                   3263
## fertile_fab:hormonal_contraceptionTRUE                    2981
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.13      0.01     1.12     1.14 1.00     5312     2547
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Ordinal model

if(identical(model$family$family, "gaussian")) {
  ordinal_model = update(model, recompile = TRUE, family = cumulative(), newdata = diary %>% mutate(time_family = as.integer(1 + time_family)) %>% filter(reasons_for_exclusion == ""), file= paste0("brms_fits/", model_prefix, "rob_check_full_ordinal_model"))
  summary(ordinal_model)
} 
##  Family: cumulative 
##   Links: mu = logit; disc = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% mutate(time_family = as.integer(1 + time (Number of observations: 24450) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 793) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.87      0.03     0.80     0.95 1.00     1631     2916
## sd(fertile_fab)                1.16      0.10     0.93     1.40 1.00     1285     2138
## cor(Intercept,fertile_fab)    -0.29      0.07    -0.46    -0.11 1.00     3753     2995
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept[1]                                             -1.50      0.05    -1.63    -1.36 1.00     2010
## Intercept[2]                                             -0.23      0.05    -0.36    -0.10 1.00     1964
## Intercept[3]                                              1.22      0.05     1.09     1.34 1.00     2026
## Intercept[4]                                              2.60      0.05     2.47     2.74 1.00     2169
## premenstrual_phase_fabTRUE                               -0.03      0.04    -0.13     0.07 1.00     5368
## menstruation                                              0.12      0.05     0.00     0.24 1.00     6239
## fertile_fab                                              -0.02      0.10    -0.29     0.25 1.00     3936
## hormonal_contraceptionTRUE                                0.09      0.09    -0.14     0.33 1.00     2133
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.11      0.08    -0.09     0.30 1.00     5031
## menstruation:hormonal_contraceptionTRUE                   0.02      0.09    -0.21     0.27 1.00     5385
## fertile_fab:hormonal_contraceptionTRUE                    0.15      0.20    -0.35     0.67 1.00     3949
##                                                       Tail_ESS
## Intercept[1]                                              2626
## Intercept[2]                                              2461
## Intercept[3]                                              2593
## Intercept[4]                                              2709
## premenstrual_phase_fabTRUE                                3124
## menstruation                                              3726
## fertile_fab                                               3175
## hormonal_contraceptionTRUE                                2453
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3386
## menstruation:hormonal_contraceptionTRUE                   3134
## fertile_fab:hormonal_contraceptionTRUE                    3390
## 
## Family Specific Parameters: 
##      Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## disc     1.00      0.00     1.00     1.00 1.00     4000     4000
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Gaussian model

if(identical(model$family$family, "poisson")) {
  gaussian_model = update(model, recompile = TRUE, family = gaussian(), file= paste0("brms_fits/", model_prefix, "rob_check_full_ordinal_model"))
  summary(gaussian_model)
}

No exclusions

no_exclusions = update(model, recompile = TRUE, cores = 4, newdata = diary, file=paste0("brms_fits/", model_prefix, "rob_check_no_exclusions"))

summary(no_exclusions)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary (Number of observations: 30472) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 964) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.48      0.01     0.44     0.51 1.00     1545     2553
## sd(fertile_fab)                0.68      0.05     0.54     0.81 1.00     1064     1526
## cor(Intercept,fertile_fab)    -0.30      0.06    -0.45    -0.14 1.00     2830     3072
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.71      0.03     1.65     1.78 1.00     1116
## premenstrual_phase_fabTRUE                               -0.01      0.02    -0.07     0.05 1.00     3371
## menstruation                                              0.10      0.03     0.03     0.17 1.00     3567
## fertile_fab                                               0.01      0.06    -0.14     0.15 1.00     2645
## hormonal_contraceptionTRUE                                0.07      0.05    -0.04     0.18 1.00     1230
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.07      0.04    -0.04     0.17 1.00     2818
## menstruation:hormonal_contraceptionTRUE                  -0.05      0.05    -0.17     0.08 1.00     3716
## fertile_fab:hormonal_contraceptionTRUE                    0.02      0.10    -0.23     0.29 1.00     2805
##                                                       Tail_ESS
## Intercept                                                 2212
## premenstrual_phase_fabTRUE                                2958
## menstruation                                              2910
## fertile_fab                                               2786
## hormonal_contraceptionTRUE                                2107
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3429
## menstruation:hormonal_contraceptionTRUE                   3289
## fertile_fab:hormonal_contraceptionTRUE                    2898
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.12      0.00     1.11     1.13 1.00     4924     2857
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Exclude cycles shorter than 25 days

rob_check_mens_length = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "") %>% filter(cycle_length >= 25), file=paste0("brms_fits/", model_prefix, "rob_check_mens_length"))

summary(rob_check_mens_length)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 22506) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 766) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.49      0.02     0.45     0.54 1.00     1888     2432
## sd(fertile_fab)                0.76      0.06     0.60     0.92 1.00     1090     2232
## cor(Intercept,fertile_fab)    -0.31      0.06    -0.46    -0.13 1.00     3232     3064
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.71      0.03     1.63     1.79 1.00     1757
## premenstrual_phase_fabTRUE                               -0.00      0.03    -0.07     0.06 1.00     3620
## menstruation                                              0.08      0.03    -0.01     0.16 1.00     3505
## fertile_fab                                              -0.03      0.07    -0.22     0.15 1.00     2768
## hormonal_contraceptionTRUE                                0.05      0.05    -0.09     0.19 1.00     1658
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.07      0.05    -0.05     0.20 1.00     3125
## menstruation:hormonal_contraceptionTRUE                   0.03      0.06    -0.12     0.19 1.00     2725
## fertile_fab:hormonal_contraceptionTRUE                    0.13      0.12    -0.18     0.44 1.00     2123
##                                                       Tail_ESS
## Intercept                                                 2357
## premenstrual_phase_fabTRUE                                3107
## menstruation                                              3057
## fertile_fab                                               2655
## hormonal_contraceptionTRUE                                2644
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3195
## menstruation:hormonal_contraceptionTRUE                   2219
## fertile_fab:hormonal_contraceptionTRUE                    2889
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.12      0.01     1.11     1.14 1.00     5271     2831
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Exclude women who report cycles outside 25-35

rob_check_selfrepcycle_length = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "") %>% filter(menstruation_length >= 25, menstruation_length <= 35), file=paste0("brms_fits/", model_prefix, "rob_check_selfrepcycle_length"))

summary(rob_check_selfrepcycle_length)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 23048) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 745) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.49      0.02     0.44     0.53 1.00     2265     2386
## sd(fertile_fab)                0.68      0.06     0.51     0.84 1.00     1211     1922
## cor(Intercept,fertile_fab)    -0.27      0.07    -0.45    -0.07 1.00     3779     3078
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.71      0.03     1.63     1.79 1.00     1902
## premenstrual_phase_fabTRUE                               -0.00      0.03    -0.07     0.06 1.00     4988
## menstruation                                              0.09      0.03     0.01     0.16 1.00     4908
## fertile_fab                                               0.02      0.06    -0.14     0.18 1.00     3882
## hormonal_contraceptionTRUE                                0.06      0.05    -0.08     0.20 1.00     2078
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.05      0.05    -0.07     0.17 1.00     4804
## menstruation:hormonal_contraceptionTRUE                  -0.02      0.06    -0.16     0.14 1.00     5097
## fertile_fab:hormonal_contraceptionTRUE                    0.07      0.12    -0.25     0.39 1.00     4338
##                                                       Tail_ESS
## Intercept                                                 2468
## premenstrual_phase_fabTRUE                                3479
## menstruation                                              3269
## fertile_fab                                               3327
## hormonal_contraceptionTRUE                                2632
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3686
## menstruation:hormonal_contraceptionTRUE                   3485
## fertile_fab:hormonal_contraceptionTRUE                    3224
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.12      0.01     1.11     1.14 1.00     5560     2442
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Exclude women who report cycles varying more than 1-2 days

rob_check_menstruation_regularity = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "") %>% filter(menstruation_regularity <= 2), file=paste0("brms_fits/", model_prefix, "rob_check_menstruation_regularity"))

summary(rob_check_menstruation_regularity)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 17089) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 557) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.48      0.02     0.43     0.53 1.00     1758     2696
## sd(fertile_fab)                0.64      0.07     0.43     0.82 1.00     1236     1814
## cor(Intercept,fertile_fab)    -0.34      0.08    -0.53    -0.11 1.00     4745     3587
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.69      0.04     1.60     1.78 1.00     2176
## premenstrual_phase_fabTRUE                                0.01      0.03    -0.07     0.09 1.00     5131
## menstruation                                              0.11      0.04     0.02     0.21 1.00     6109
## fertile_fab                                              -0.00      0.08    -0.22     0.19 1.00     4585
## hormonal_contraceptionTRUE                                0.11      0.06    -0.04     0.26 1.00     2578
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.03      0.05    -0.11     0.16 1.00     4874
## menstruation:hormonal_contraceptionTRUE                   0.00      0.06    -0.16     0.17 1.00     5439
## fertile_fab:hormonal_contraceptionTRUE                    0.08      0.13    -0.26     0.41 1.00     4158
##                                                       Tail_ESS
## Intercept                                                 2766
## premenstrual_phase_fabTRUE                                3542
## menstruation                                              3485
## fertile_fab                                               3559
## hormonal_contraceptionTRUE                                3041
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3254
## menstruation:hormonal_contraceptionTRUE                   3590
## fertile_fab:hormonal_contraceptionTRUE                    3359
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.13      0.01     1.12     1.15 1.00     5616     2878
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Exclude women who report uncertainty larger than ±2 days

Across three items (last menstrual onset, cycle length, menstruation regularity).

diary$menstruation_certainty <- rowMeans(diary %>% select(menstruation_last_certainty, menstruation_regularity_certainty, menstruation_length_certainty), na.rm = T)
rob_check_menstruation_certainty = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "") %>% filter(menstruation_certainty <= 3), file=paste0("brms_fits/", model_prefix, "rob_check_menstruation_certainty"))

summary(rob_check_menstruation_certainty)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 22385) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 727) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.50      0.02     0.45     0.55 1.00     1403     2128
## sd(fertile_fab)                0.68      0.06     0.52     0.85 1.00      934     1836
## cor(Intercept,fertile_fab)    -0.31      0.07    -0.48    -0.13 1.00     3421     3223
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.72      0.03     1.64     1.79 1.00     1564
## premenstrual_phase_fabTRUE                               -0.02      0.03    -0.09     0.05 1.00     3940
## menstruation                                              0.08      0.03    -0.00     0.16 1.00     4261
## fertile_fab                                              -0.02      0.07    -0.19     0.15 1.00     3406
## hormonal_contraceptionTRUE                                0.07      0.06    -0.08     0.21 1.00     1389
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.06      0.05    -0.07     0.19 1.00     3083
## menstruation:hormonal_contraceptionTRUE                   0.01      0.06    -0.14     0.17 1.00     3636
## fertile_fab:hormonal_contraceptionTRUE                    0.06      0.12    -0.28     0.37 1.00     2531
##                                                       Tail_ESS
## Intercept                                                 2301
## premenstrual_phase_fabTRUE                                3263
## menstruation                                              2987
## fertile_fab                                               3414
## hormonal_contraceptionTRUE                                2226
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     2960
## menstruation:hormonal_contraceptionTRUE                   3046
## fertile_fab:hormonal_contraceptionTRUE                    2615
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.13      0.01     1.12     1.15 1.00     6495     2619
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Exclude women who report not feeling healthy

rob_check_health = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "") %>% filter(self_rated_health <= 2), file=paste0("brms_fits/", model_prefix, "rob_check_health"))

summary(rob_check_health)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 21452) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 687) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.49      0.02     0.44     0.54 1.00     2102     2880
## sd(fertile_fab)                0.68      0.06     0.51     0.84 1.00     1164     1963
## cor(Intercept,fertile_fab)    -0.32      0.07    -0.50    -0.12 1.00     4163     3227
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.73      0.03     1.65     1.81 1.00     2313
## premenstrual_phase_fabTRUE                               -0.02      0.03    -0.09     0.05 1.00     5064
## menstruation                                              0.09      0.03     0.00     0.17 1.00     5539
## fertile_fab                                              -0.05      0.07    -0.24     0.12 1.00     4221
## hormonal_contraceptionTRUE                                0.05      0.06    -0.10     0.19 1.00     2640
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.08      0.05    -0.05     0.21 1.00     5220
## menstruation:hormonal_contraceptionTRUE                   0.00      0.06    -0.16     0.16 1.00     5133
## fertile_fab:hormonal_contraceptionTRUE                    0.12      0.13    -0.20     0.46 1.00     4197
##                                                       Tail_ESS
## Intercept                                                 2882
## premenstrual_phase_fabTRUE                                3358
## menstruation                                              3276
## fertile_fab                                               3234
## hormonal_contraceptionTRUE                                2940
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3400
## menstruation:hormonal_contraceptionTRUE                   3272
## fertile_fab:hormonal_contraceptionTRUE                    3284
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.13      0.01     1.12     1.15 1.00     5857     3043
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Exclude women trying for pregnancy

pregnant_trying = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "") %>% filter(pregnant_trying < 4), file=paste0("brms_fits/", model_prefix, "rob_check_pregnant_trying"))

summary(pregnant_trying)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 23782) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 767) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.49      0.02     0.45     0.53 1.00     1445     2508
## sd(fertile_fab)                0.69      0.06     0.54     0.85 1.00     1080     1857
## cor(Intercept,fertile_fab)    -0.30      0.07    -0.46    -0.10 1.00     2968     2775
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.71      0.03     1.64     1.78 1.00     1272
## premenstrual_phase_fabTRUE                               -0.01      0.03    -0.08     0.06 1.00     3501
## menstruation                                              0.08      0.03     0.00     0.16 1.00     3588
## fertile_fab                                               0.00      0.06    -0.16     0.17 1.00     2976
## hormonal_contraceptionTRUE                                0.06      0.05    -0.07     0.19 1.00     1475
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.06      0.05    -0.07     0.17 1.00     3456
## menstruation:hormonal_contraceptionTRUE                  -0.01      0.06    -0.15     0.14 1.00     4004
## fertile_fab:hormonal_contraceptionTRUE                    0.06      0.12    -0.26     0.38 1.00     3098
##                                                       Tail_ESS
## Intercept                                                 2203
## premenstrual_phase_fabTRUE                                2905
## menstruation                                              2683
## fertile_fab                                               3421
## hormonal_contraceptionTRUE                                1907
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3233
## menstruation:hormonal_contraceptionTRUE                   3309
## fertile_fab:hormonal_contraceptionTRUE                    3433
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.13      0.01     1.11     1.14 1.00     5066     2570
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Include women living with parents

rob_check_parents = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "" | reasons_for_exclusion == "living_with_parents, "), file=paste0("brms_fits/", model_prefix, "rob_check_parents"))

summary(rob_check_parents)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "" | rea (Number of observations: 26793) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 870) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.49      0.02     0.45     0.52 1.00     2079     2705
## sd(fertile_fab)                0.68      0.06     0.54     0.83 1.00     1154     2317
## cor(Intercept,fertile_fab)    -0.30      0.06    -0.45    -0.13 1.00     3886     3305
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.71      0.03     1.64     1.78 1.00     1957
## premenstrual_phase_fabTRUE                               -0.01      0.02    -0.07     0.05 1.00     5248
## menstruation                                              0.09      0.03     0.02     0.16 1.00     5426
## fertile_fab                                              -0.01      0.06    -0.16     0.14 1.00     4050
## hormonal_contraceptionTRUE                                0.07      0.05    -0.06     0.19 1.00     2002
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.05      0.04    -0.06     0.17 1.00     4937
## menstruation:hormonal_contraceptionTRUE                  -0.03      0.05    -0.17     0.11 1.00     5116
## fertile_fab:hormonal_contraceptionTRUE                    0.05      0.11    -0.23     0.36 1.00     4392
##                                                       Tail_ESS
## Intercept                                                 2488
## premenstrual_phase_fabTRUE                                2892
## menstruation                                              3268
## fertile_fab                                               3247
## hormonal_contraceptionTRUE                                2547
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3363
## menstruation:hormonal_contraceptionTRUE                   3787
## fertile_fab:hormonal_contraceptionTRUE                    3099
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.12      0.01     1.11     1.14 1.00     5170     2615
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Exclude non-singles

if(outcome != "person_is_related_man_seen") {
  rob_check_singles = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "", hetero_relationship == 0, relationship_status == 1), file=paste0("brms_fits/", model_prefix, "rob_check_singles"))

summary(rob_check_singles)
}
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "", hete (Number of observations: 8512) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 262) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.48      0.03     0.41     0.56 1.00      872     2077
## sd(fertile_fab)                0.88      0.10     0.61     1.14 1.00      740     1549
## cor(Intercept,fertile_fab)    -0.31      0.10    -0.55    -0.02 1.00     1189     2554
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.63      0.04     1.52     1.75 1.01      861
## premenstrual_phase_fabTRUE                                0.05      0.04    -0.06     0.15 1.00     2407
## menstruation                                              0.13      0.05     0.01     0.25 1.00     2832
## fertile_fab                                               0.05      0.11    -0.24     0.32 1.00     1446
## hormonal_contraceptionTRUE                                0.08      0.11    -0.18     0.34 1.00      941
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.03      0.10    -0.24     0.28 1.00     1951
## menstruation:hormonal_contraceptionTRUE                   0.00      0.11    -0.28     0.30 1.00     2211
## fertile_fab:hormonal_contraceptionTRUE                   -0.13      0.26    -0.79     0.54 1.00     1322
##                                                       Tail_ESS
## Intercept                                                 1941
## premenstrual_phase_fabTRUE                                2879
## menstruation                                              2449
## fertile_fab                                               2397
## hormonal_contraceptionTRUE                                1170
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     2610
## menstruation:hormonal_contraceptionTRUE                   2614
## fertile_fab:hormonal_contraceptionTRUE                    1976
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.14      0.01     1.12     1.16 1.00     4223     2649
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Moderation by weekend

weekend = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "") %>% filter(weekend == 1), file=paste0("brms_fits/", model_prefix, "rob_check_weekend"))
weekday = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "") %>% filter(weekend == 0), file=paste0("brms_fits/", model_prefix, "rob_check_weekday"))

summary(weekend)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 10182) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 780) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.55      0.02     0.50     0.62 1.00     1697     2313
## sd(fertile_fab)                0.99      0.09     0.74     1.23 1.00     1153     2002
## cor(Intercept,fertile_fab)    -0.40      0.07    -0.57    -0.19 1.00     2834     3086
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.88      0.04     1.78     1.98 1.00     2259
## premenstrual_phase_fabTRUE                               -0.08      0.04    -0.19     0.03 1.00     4046
## menstruation                                              0.02      0.05    -0.10     0.15 1.00     4403
## fertile_fab                                              -0.10      0.10    -0.37     0.17 1.00     2934
## hormonal_contraceptionTRUE                                0.09      0.07    -0.10     0.29 1.00     1971
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.11      0.08    -0.08     0.30 1.00     3176
## menstruation:hormonal_contraceptionTRUE                   0.07      0.09    -0.17     0.32 1.00     3675
## fertile_fab:hormonal_contraceptionTRUE                   -0.03      0.19    -0.51     0.49 1.00     2645
##                                                       Tail_ESS
## Intercept                                                 2687
## premenstrual_phase_fabTRUE                                3306
## menstruation                                              3146
## fertile_fab                                               2923
## hormonal_contraceptionTRUE                                2302
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3135
## menstruation:hormonal_contraceptionTRUE                   3052
## fertile_fab:hormonal_contraceptionTRUE                    2967
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.16      0.01     1.14     1.18 1.00     4851     3129
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).
summary(weekday)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 14268) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 792) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.50      0.02     0.45     0.55 1.00     1875     2574
## sd(fertile_fab)                0.64      0.08     0.40     0.84 1.00      824     1357
## cor(Intercept,fertile_fab)    -0.21      0.09    -0.43     0.07 1.00     3142     2269
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.59      0.03     1.51     1.68 1.00     2851
## premenstrual_phase_fabTRUE                                0.03      0.03    -0.05     0.11 1.00     4989
## menstruation                                              0.11      0.04     0.01     0.21 1.00     5933
## fertile_fab                                               0.03      0.07    -0.17     0.22 1.00     5123
## hormonal_contraceptionTRUE                                0.05      0.06    -0.10     0.20 1.00     2805
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.01      0.06    -0.13     0.17 1.00     4732
## menstruation:hormonal_contraceptionTRUE                  -0.04      0.07    -0.22     0.14 1.00     5095
## fertile_fab:hormonal_contraceptionTRUE                    0.14      0.14    -0.21     0.52 1.00     4400
##                                                       Tail_ESS
## Intercept                                                 2520
## premenstrual_phase_fabTRUE                                3134
## menstruation                                              3028
## fertile_fab                                               3361
## hormonal_contraceptionTRUE                                2676
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3487
## menstruation:hormonal_contraceptionTRUE                   3578
## fertile_fab:hormonal_contraceptionTRUE                    3046
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.07      0.01     1.05     1.09 1.00     4103     2773
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Moderation by age group

older25 = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "") %>% filter(age > 25), file=paste0("brms_fits/", model_prefix, "rob_check_older25"))
younger25 = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == "") %>% filter(age <= 25), file=paste0("brms_fits/", model_prefix, "rob_check_younger25"))

summary(younger25)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 13727) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 446) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.46      0.02     0.41     0.52 1.00     1077     1563
## sd(fertile_fab)                0.62      0.09     0.37     0.85 1.00      945     1862
## cor(Intercept,fertile_fab)    -0.25      0.11    -0.50     0.06 1.00     2962     2914
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.72      0.04     1.61     1.83 1.00     1380
## premenstrual_phase_fabTRUE                                0.01      0.04    -0.09     0.10 1.00     3323
## menstruation                                              0.06      0.04    -0.05     0.17 1.00     3321
## fertile_fab                                               0.05      0.09    -0.19     0.28 1.00     2848
## hormonal_contraceptionTRUE                                0.09      0.07    -0.07     0.26 1.00     1432
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.06      0.06    -0.10     0.22 1.00     3054
## menstruation:hormonal_contraceptionTRUE                   0.06      0.07    -0.13     0.24 1.00     3585
## fertile_fab:hormonal_contraceptionTRUE                   -0.01      0.15    -0.39     0.39 1.00     2651
##                                                       Tail_ESS
## Intercept                                                 2066
## premenstrual_phase_fabTRUE                                2931
## menstruation                                              2696
## fertile_fab                                               3104
## hormonal_contraceptionTRUE                                2017
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3139
## menstruation:hormonal_contraceptionTRUE                   3407
## fertile_fab:hormonal_contraceptionTRUE                    3067
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.17      0.01     1.15     1.19 1.00     4991     2874
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).
summary(older25)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 10723) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 347) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.52      0.03     0.46     0.60 1.00     1055     1763
## sd(fertile_fab)                0.76      0.08     0.55     0.98 1.00      877     1332
## cor(Intercept,fertile_fab)    -0.35      0.09    -0.56    -0.11 1.00     2252     2903
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.69      0.04     1.59     1.81 1.00      805
## premenstrual_phase_fabTRUE                               -0.03      0.03    -0.11     0.06 1.00     2781
## menstruation                                              0.11      0.04     0.01     0.21 1.00     3103
## fertile_fab                                              -0.07      0.09    -0.29     0.16 1.00     1780
## hormonal_contraceptionTRUE                               -0.03      0.09    -0.29     0.20 1.00      711
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.04      0.08    -0.17     0.24 1.00     2519
## menstruation:hormonal_contraceptionTRUE                  -0.12      0.10    -0.37     0.13 1.00     2977
## fertile_fab:hormonal_contraceptionTRUE                    0.21      0.21    -0.30     0.76 1.00     1525
##                                                       Tail_ESS
## Intercept                                                 1416
## premenstrual_phase_fabTRUE                                2917
## menstruation                                              3028
## fertile_fab                                               2508
## hormonal_contraceptionTRUE                                 916
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     2582
## menstruation:hormonal_contraceptionTRUE                   2803
## fertile_fab:hormonal_contraceptionTRUE                    2460
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.07      0.01     1.06     1.09 1.00     5306     2692
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Excluding women who used psychopharmacological, hormonal, or antibiotic medication

diary <- diary %>% filter(reasons_for_exclusion == "") %>% ungroup() %>% 
  mutate(medication_psychopharmacological = if_else(is.na(medication_psychopharmacological), 0, medication_psychopharmacological),
         medication_hormonal = if_else(is.na(medication_hormonal), 0, medication_hormonal),
         medication_antibiotics = if_else(is.na(medication_antibiotics), 0, medication_antibiotics))

exclude_meds = update(model, recompile = TRUE, cores = 4, newdata= diary %>% filter(reasons_for_exclusion == "") %>% filter(medication_psychopharmacological == 0, medication_hormonal == 0, medication_antibiotics == 0), file=paste0("brms_fits/", model_prefix, "rob_check_meds"))

summary(exclude_meds)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 21768) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 706) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.50      0.02     0.45     0.55 1.00     1564     2394
## sd(fertile_fab)                0.71      0.06     0.55     0.87 1.00     1306     2312
## cor(Intercept,fertile_fab)    -0.31      0.07    -0.46    -0.11 1.00     3892     3273
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.72      0.03     1.63     1.80 1.00     2331
## premenstrual_phase_fabTRUE                               -0.01      0.03    -0.08     0.06 1.00     5341
## menstruation                                              0.08      0.03     0.01     0.16 1.00     5495
## fertile_fab                                               0.01      0.07    -0.17     0.19 1.00     4538
## hormonal_contraceptionTRUE                                0.06      0.06    -0.08     0.20 1.00     2421
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.04      0.05    -0.09     0.17 1.00     4820
## menstruation:hormonal_contraceptionTRUE                  -0.01      0.06    -0.17     0.13 1.00     5256
## fertile_fab:hormonal_contraceptionTRUE                    0.04      0.13    -0.28     0.37 1.00     4159
##                                                       Tail_ESS
## Intercept                                                 2722
## premenstrual_phase_fabTRUE                                3590
## menstruation                                              3358
## fertile_fab                                               3581
## hormonal_contraceptionTRUE                                2622
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3552
## menstruation:hormonal_contraceptionTRUE                   3186
## fertile_fab:hormonal_contraceptionTRUE                    3576
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.12      0.01     1.10     1.13 1.00     5125     2741
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Excluding hypothesis guessers

hyp_guess = update(model, recompile = TRUE, cores = 4,newdata = diary %>% filter(reasons_for_exclusion == "") %>% filter(hypothesis_guess_topic == "no_guess"), file=paste0("brms_fits/", model_prefix, "_rob_check_hyp_guess"))

summary(hyp_guess)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 20529) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 680) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.51      0.02     0.46     0.56 1.00     1291     2271
## sd(fertile_fab)                0.71      0.06     0.55     0.87 1.00     1245     2012
## cor(Intercept,fertile_fab)    -0.32      0.07    -0.49    -0.15 1.00     3210     3214
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.70      0.03     1.61     1.78 1.00     1520
## premenstrual_phase_fabTRUE                               -0.00      0.03    -0.08     0.07 1.00     3986
## menstruation                                              0.10      0.03     0.02     0.18 1.00     4214
## fertile_fab                                               0.07      0.07    -0.11     0.25 1.00     2996
## hormonal_contraceptionTRUE                                0.06      0.06    -0.08     0.21 1.00     1449
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.03      0.05    -0.10     0.16 1.00     3421
## menstruation:hormonal_contraceptionTRUE                  -0.01      0.06    -0.16     0.15 1.00     4254
## fertile_fab:hormonal_contraceptionTRUE                   -0.02      0.13    -0.34     0.32 1.00     2964
##                                                       Tail_ESS
## Intercept                                                 2483
## premenstrual_phase_fabTRUE                                2688
## menstruation                                              3458
## fertile_fab                                               3086
## hormonal_contraceptionTRUE                                1975
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     2985
## menstruation:hormonal_contraceptionTRUE                   2953
## fertile_fab:hormonal_contraceptionTRUE                    2631
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.12      0.01     1.11     1.13 1.00     5955     2152
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Excluding women using awareness-based methods

unaware = update(model, recompile = TRUE, cores = 4,newdata = diary %>% filter(reasons_for_exclusion == "") %>% filter(contraception_approach != "awareness", contraception_app == 0), file=paste0("brms_fits/", model_prefix, "rob_check_unaware"))

summary(unaware)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 14817) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 499) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.49      0.02     0.44     0.54 1.00     2048     2924
## sd(fertile_fab)                0.79      0.07     0.60     0.98 1.00     1384     2470
## cor(Intercept,fertile_fab)    -0.31      0.08    -0.50    -0.09 1.00     3592     3343
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.73      0.04     1.63     1.83 1.00     2627
## premenstrual_phase_fabTRUE                               -0.01      0.03    -0.10     0.08 1.00     5495
## menstruation                                              0.04      0.04    -0.06     0.15 1.00     5681
## fertile_fab                                               0.00      0.09    -0.23     0.25 1.00     4647
## hormonal_contraceptionTRUE                                0.07      0.06    -0.09     0.24 1.00     2561
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.02      0.06    -0.12     0.17 1.00     5560
## menstruation:hormonal_contraceptionTRUE                  -0.00      0.07    -0.18     0.17 1.00     5584
## fertile_fab:hormonal_contraceptionTRUE                   -0.00      0.15    -0.39     0.38 1.00     4377
##                                                       Tail_ESS
## Intercept                                                 2660
## premenstrual_phase_fabTRUE                                3281
## menstruation                                              3384
## fertile_fab                                               3728
## hormonal_contraceptionTRUE                                2896
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3426
## menstruation:hormonal_contraceptionTRUE                   3542
## fertile_fab:hormonal_contraceptionTRUE                    3472
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.13      0.01     1.12     1.15 1.00     6175     3055
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Don’t adjust for menstruation

dont_adjust = update.formula(formula(model), new = . ~ . - menstruation*hormonal_contraception - premenstrual_phase_fab*hormonal_contraception + hormonal_contraception)
no_mens = update(model, recompile = TRUE, cores = 4, formula = dont_adjust, file=paste0("brms_fits/", model_prefix, "rob_check_no_mens2"))


summary(no_mens)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ fertile_fab + (1 + fertile_fab | person) + hormonal_contraception + fertile_fab:hormonal_contraception 
##    Data: diary %>% filter(reasons_for_exclusion == "" | rea (Number of observations: 24450) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 793) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.49      0.02     0.45     0.54 1.00     1737     2747
## sd(fertile_fab)                0.69      0.06     0.55     0.85 1.00     1198     2326
## cor(Intercept,fertile_fab)    -0.31      0.07    -0.46    -0.12 1.00     4051     3251
## 
## Population-Level Effects: 
##                                        Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## Intercept                                  1.72      0.02     1.66     1.78 1.00     1790     2557
## fertile_fab                               -0.03      0.06    -0.17     0.12 1.00     4775     3375
## hormonal_contraceptionTRUE                 0.09      0.05    -0.02     0.21 1.00     1955     2530
## fertile_fab:hormonal_contraceptionTRUE     0.01      0.10    -0.26     0.27 1.00     4657     2926
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.13      0.01     1.11     1.14 1.00     6258     2421
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Don’t adjust for menstruation interaction (bad pre-reg model)

We originally preregistered a model, in which we did not fit an interaction between hormonal contraception and (pre-)menstruation. However, if we want to adjust the effect of the probability of being in the fertile window for (pre-)menstruation, we need to include “interaction controls”. This robustness check shows that this decision makes little difference to the results.

dont_adjust = update.formula(formula(model), new = . ~ . - menstruation:hormonal_contraception - premenstrual_phase_fab:hormonal_contraception)
no_mens_int = update(model, recompile = TRUE, cores = 4, newdata = diary %>% filter(reasons_for_exclusion == ""), formula = dont_adjust, file=paste0("brms_fits/", model_prefix, "rob_check_no_mens_int"))

summary(no_mens_int)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ premenstrual_phase_fab + menstruation + fertile_fab + hormonal_contraception + (1 + fertile_fab | person) + fertile_fab:hormonal_contraception 
##    Data: diary %>% filter(reasons_for_exclusion == "") (Number of observations: 24450) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 793) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.49      0.02     0.45     0.54 1.00     2244     2645
## sd(fertile_fab)                0.69      0.06     0.53     0.84 1.00     1091     2269
## cor(Intercept,fertile_fab)    -0.31      0.07    -0.47    -0.13 1.00     3812     3420
## 
## Population-Level Effects: 
##                                        Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## Intercept                                  1.70      0.03     1.63     1.77 1.00     2219     2941
## premenstrual_phase_fabTRUE                 0.00      0.02    -0.05     0.06 1.00     6523     3473
## menstruation                               0.08      0.03     0.02     0.15 1.00     7492     3242
## fertile_fab                                0.01      0.06    -0.15     0.16 1.00     5066     3319
## hormonal_contraceptionTRUE                 0.09      0.04    -0.03     0.20 1.00     1912     2534
## fertile_fab:hormonal_contraceptionTRUE     0.01      0.10    -0.25     0.26 1.00     4243     3166
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.13      0.01     1.11     1.14 1.00     4960     2614
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Using forward counting

forward_counted = update(model, 
                         recompile = TRUE, cores = 4,
                         newdata = diary %>% 
                           filter(reasons_for_exclusion == "fertility_never_estimable, next_menstrual_onset_unobserved, " | reasons_for_exclusion == "next_menstrual_onset_unobserved, " | reasons_for_exclusion == "") %>% 
                           mutate(fertile_fab = prc_stirn_b_forward_counted, premenstrual_phase_fab = premenstrual_phase_forward_counted),
                         file=paste0("brms_fits/", model_prefix, "rob_check_forward_counted2"))

summary(forward_counted)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "fertili (Number of observations: 26008) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 841) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.50      0.02     0.46     0.54 1.00     1614     2693
## sd(fertile_fab)                0.71      0.06     0.56     0.86 1.01     1330     2257
## cor(Intercept,fertile_fab)    -0.35      0.06    -0.50    -0.18 1.00     3554     3190
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.69      0.03     1.62     1.77 1.00     2015
## premenstrual_phase_fabTRUE                                0.05      0.03    -0.02     0.11 1.00     5552
## menstruation                                              0.10      0.03     0.03     0.18 1.00     6492
## fertile_fab                                               0.04      0.06    -0.12     0.20 1.00     4620
## hormonal_contraceptionTRUE                                0.08      0.05    -0.05     0.21 1.00     2150
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.00      0.05    -0.12     0.13 1.00     5123
## menstruation:hormonal_contraceptionTRUE                  -0.03      0.06    -0.17     0.12 1.00     6617
## fertile_fab:hormonal_contraceptionTRUE                   -0.02      0.11    -0.29     0.27 1.00     4047
##                                                       Tail_ESS
## Intercept                                                 2643
## premenstrual_phase_fabTRUE                                3004
## menstruation                                              3503
## fertile_fab                                               3450
## hormonal_contraceptionTRUE                                2688
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3148
## menstruation:hormonal_contraceptionTRUE                   3620
## fertile_fab:hormonal_contraceptionTRUE                    3238
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.13      0.01     1.11     1.14 1.00     5077     2716
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Using forward counted narrow window

forward_counted_window = update(model, 
                         recompile = TRUE, cores = 4,
                         newdata = diary %>% 
                           filter(reasons_for_exclusion == "fertility_never_estimable, next_menstrual_onset_unobserved, " | reasons_for_exclusion == "next_menstrual_onset_unobserved, " | reasons_for_exclusion == "") %>% 
                           mutate(fertile_fab = fertile_narrow_forward_counted), 
                         formula = . ~ . - (premenstrual_phase_fab + menstruation) * hormonal_contraception,
                         file = paste0("brms_fits/", model_prefix, "rob_check_forward_counted_window"))

summary(forward_counted_window)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ fertile_fab + (1 + fertile_fab | person) + fertile_fab:hormonal_contraception 
##    Data: diary %>% filter(reasons_for_exclusion == "fertili (Number of observations: 12992) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 825) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.54      0.02     0.48     0.59 1.00     1787     2618
## sd(fertile_fab)                0.83      0.07     0.64     1.02 1.00      906     1347
## cor(Intercept,fertile_fab)    -0.44      0.06    -0.59    -0.26 1.00     2210     2824
## 
## Population-Level Effects: 
##                                        Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## Intercept                                  1.73      0.02     1.67     1.79 1.00     1913     2538
## fertile_fab                               -0.02      0.06    -0.19     0.15 1.00     3116     2706
## fertile_fab:hormonal_contraceptionTRUE     0.14      0.10    -0.13     0.39 1.00     3527     2748
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.11      0.01     1.09     1.13 1.00     4224     3054
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Using backward counted narrow window

backward_counted_window = update(model, 
                         recompile = TRUE, cores = 4,
                         newdata = diary %>% 
                           filter(reasons_for_exclusion == "") %>% 
                           mutate(fertile_fab = fertile_narrow), 
                         formula = . ~ . - (premenstrual_phase_fab + menstruation) * hormonal_contraception,
                         file = paste0("brms_fits/", model_prefix, "rob_check_backward_counted_window"))

summary(backward_counted_window)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ fertile_fab + (1 + fertile_fab | person) + fertile_fab:hormonal_contraception 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 12743) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 779) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.52      0.02     0.47     0.58 1.01     1554     2672
## sd(fertile_fab)                0.84      0.07     0.63     1.02 1.00     1037     1827
## cor(Intercept,fertile_fab)    -0.40      0.07    -0.56    -0.20 1.00     1956     2413
## 
## Population-Level Effects: 
##                                        Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## Intercept                                  1.74      0.02     1.68     1.80 1.00     1560     2127
## fertile_fab                               -0.04      0.07    -0.21     0.13 1.00     3011     2941
## fertile_fab:hormonal_contraceptionTRUE     0.24      0.11    -0.04     0.52 1.00     2329     2852
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.12      0.01     1.10     1.13 1.00     3660     2599
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Using backward-counting squished

bc_squished = update(model, recompile = TRUE, cores = 4,newdata = diary %>% filter(reasons_for_exclusion == "") %>% mutate(fertile_fab = prc_stirn_b_squished, premenstrual_phase_fab = premenstrual_phase_squished), file=paste0("brms_fits/", model_prefix, "rob_check_bc_squished"))

summary(bc_squished)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "") %>%  (Number of observations: 24450) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 793) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.49      0.02     0.45     0.54 1.00     1374     2409
## sd(fertile_fab)                0.70      0.06     0.54     0.85 1.00     1102     1932
## cor(Intercept,fertile_fab)    -0.32      0.07    -0.48    -0.14 1.00     2708     3336
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.71      0.03     1.64     1.79 1.01     1527
## premenstrual_phase_fabTRUE                               -0.02      0.03    -0.09     0.05 1.00     3717
## menstruation                                              0.08      0.03    -0.00     0.16 1.00     3762
## fertile_fab                                              -0.01      0.07    -0.19     0.15 1.00     2952
## hormonal_contraceptionTRUE                                0.06      0.05    -0.08     0.19 1.00     1187
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     0.06      0.05    -0.06     0.18 1.00     3479
## menstruation:hormonal_contraceptionTRUE                   0.01      0.06    -0.15     0.16 1.00     3686
## fertile_fab:hormonal_contraceptionTRUE                    0.09      0.12    -0.24     0.40 1.00     2643
##                                                       Tail_ESS
## Intercept                                                 1661
## premenstrual_phase_fabTRUE                                3586
## menstruation                                              3151
## fertile_fab                                               2641
## hormonal_contraceptionTRUE                                1175
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     3066
## menstruation:hormonal_contraceptionTRUE                   3003
## fertile_fab:hormonal_contraceptionTRUE                    2600
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.13      0.01     1.11     1.14 1.00     4351     2675
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Using inferred backward-counting

bc_inferred = update(model, recompile = TRUE, cores = 4,newdata = diary  %>% filter(reasons_for_exclusion == "fertility_never_estimable, next_menstrual_onset_unobserved, " | reasons_for_exclusion == "next_menstrual_onset_unobserved, " | reasons_for_exclusion == "")  %>% mutate(fertile_fab = prc_stirn_b_inferred, premenstrual_phase_fab = premenstrual_phase_inferred), file=paste0("brms_fits/", model_prefix, "rob_check_bc_inferred"))

summary(bc_inferred)
##  Family: gaussian 
##   Links: mu = identity; sigma = identity 
## Formula: time_family ~ (premenstrual_phase_fab + menstruation + fertile_fab) * hormonal_contraception + (1 + fertile_fab | person) 
##    Data: diary %>% filter(reasons_for_exclusion == "fertili (Number of observations: 24667) 
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
##          total post-warmup samples = 4000
## 
## Group-Level Effects: 
## ~person (Number of levels: 835) 
##                            Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)                  0.50      0.02     0.46     0.55 1.00     1587     2545
## sd(fertile_fab)                0.71      0.06     0.56     0.86 1.00      824     1408
## cor(Intercept,fertile_fab)    -0.35      0.06    -0.50    -0.18 1.00     2422     3108
## 
## Population-Level Effects: 
##                                                       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS
## Intercept                                                 1.69      0.03     1.62     1.77 1.00     1218
## premenstrual_phase_fabTRUE                                0.05      0.03    -0.02     0.11 1.00     2955
## menstruation                                              0.11      0.03     0.03     0.18 1.00     3698
## fertile_fab                                               0.02      0.06    -0.13     0.18 1.00     2057
## hormonal_contraceptionTRUE                                0.12      0.05    -0.02     0.26 1.00     1153
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE    -0.05      0.05    -0.17     0.08 1.00     2579
## menstruation:hormonal_contraceptionTRUE                  -0.06      0.06    -0.20     0.08 1.00     3053
## fertile_fab:hormonal_contraceptionTRUE                   -0.08      0.12    -0.39     0.23 1.00     2077
##                                                       Tail_ESS
## Intercept                                                 2120
## premenstrual_phase_fabTRUE                                3150
## menstruation                                              3189
## fertile_fab                                               2529
## hormonal_contraceptionTRUE                                1563
## premenstrual_phase_fabTRUE:hormonal_contraceptionTRUE     2980
## menstruation:hormonal_contraceptionTRUE                   3042
## fertile_fab:hormonal_contraceptionTRUE                    2408
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-99% CI u-99% CI Rhat Bulk_ESS Tail_ESS
## sigma     1.12      0.01     1.11     1.14 1.00     5508     3063
## 
## Samples were drawn using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Summary plot

library(broom.mixed)
robchecks_e <- list(
  `A1. Original model` = model,
  `E1. No exclusions` = no_exclusions,
  `E2. No hypothesis guessing` = hyp_guess,
  `E3. No medication` = exclude_meds,
  `E4. No cycle-aware` = unaware,
  `E5a. No irregular cycles (>± 2 days)` = rob_check_menstruation_regularity,
  `E5b. Avg. cycles inside 25-35 days` = rob_check_selfrepcycle_length,
  `E5c. No cycles < 25 days` = rob_check_mens_length,
  `E5d. Low uncertainty about cycle (<±2 days)` = rob_check_menstruation_certainty,
  `E6. No planned pregnancy` = pregnant_trying,
  `E7. No unhealthy women` = rob_check_health,
  `E8a. Women 18-25` = younger25,
  `E8b. Women older than 25` = older25,
  `E9a. Friday-Saturday only` = weekend,
  `E9b. Monday-Thursday only` = weekday,
  `E10. Include living with parents` = rob_check_parents
  )
if(outcome != "person_is_related_man_seen") {
  robchecks_e[["E11. Singles only"]] = rob_check_singles 
}
robchecks_e <- robchecks_e %>%
  map(function(x) {
          b <- broom::tidy(x, conf.level = 0.99)
          b$n_days = nrow(x$data)
          b$n_persons = max(n_distinct(x$data$person),
                            n_distinct(x$data$short))
          b$category = "exclusions"
          b
          }) %>% 
  bind_rows(.id = "check")

robchecks_e %>% 
  filter(term == "fertile_fab") %>% 
  mutate(check = fct_rev(fct_inorder(paste0('atop("",atop("', check,'",',
                                'phantom(0)^"(',n_persons, ' women, ',n_days,' days)"))')))) %>% 
  ggplot(aes(check, estimate, ymin = conf.low, ymax = conf.high)) + 
  geom_hline(yintercept = 0, linetype = 'dashed') +
  scale_x_discrete("Robustness check", labels = function(x) {parse(text=x)}) +
  ylab("Fertile window effect with 99% CI") +
  geom_pointrange() + 
  coord_flip() +
  theme(axis.text.y = element_text(size = 11))

ggsave(paste0("figures/", model_prefix,"_robustness_checks_exclusions.png"), width =5, height = 7)
ggsave(paste0("figures/", model_prefix,"_robustness_checks_exclusions.pdf"), width =5, height = 7)

robchecks_p <- list(
  `A1. Original model` = model,
  `P1. Not adj. for (pre-)mens.` = no_mens,
  `P2. No HC×(pre-)mens. interaction` = no_mens_int,
  `P3. Forward counting` = forward_counted,
  `P4. Squished backward-counting` = bc_squished,
  `P5. Inferred backward-counting` = bc_inferred,
  `P6. Forward counted window` = forward_counted_window,
  `P7. Backward counted window` = backward_counted_window,
  `M1. Full random slopes` = full_random_slopes,
  `M2. Uncorrelated random slopes` = full_random_slopes_no_cor,
  `M3. No random slopes` = no_varying_slope,
  `M4. Require outcome variance` = with_outcome_var
  )

if(model$family$family == "gaussian") {
  robchecks_p[["M6. Ordinal regression"]] = ordinal_model 
} else {
  robchecks_p[["M5. Gaussian regression"]] = gaussian_model 
}

if(outcome == "person_is_related_man_seen") {
  robchecks_p[["O1. Inferred male relatives"]] = related_men_inferred
  robchecks_p[["O2. Related men thought about"]] = related_men_thoughts
  robchecks_p[["O3. Related men seen/thought about"]] = related_men
}

robchecks_p <- robchecks_p %>%
  map(function(x) {
          b <- broom::tidy(x, conf.level = 0.99)
          b$n_days = nrow(x$data)
          b$n_persons = max(n_distinct(x$data$person),
                            n_distinct(x$data$short))
          b$category = "model"
          b
          }) %>% 
  bind_rows(.id = "check")

robchecks_p %>% 
  filter(term == "fertile_fab") %>% 
  mutate(check = fct_rev(paste0('atop("",atop("', check,'",',
                                'phantom(0)^"(',n_persons, ' women, ',n_days,' days)"))'))) %>% 
  ggplot(aes(check, estimate, ymin = conf.low, ymax = conf.high)) + 
  geom_hline(yintercept = 0, linetype = 'dashed') +
  scale_x_discrete("Robustness check", labels = function(x) {parse(text=x)}) +
  ylab("Fertile window effect with 99% CI") +
  geom_pointrange() + 
  coord_flip() +
  theme(axis.text.y = element_text(size = 11))

ggsave(paste0("figures/", model_prefix,"_robustness_checks_model.png"), width =5, height = 7)
ggsave(paste0("figures/", model_prefix,"_robustness_checks_model.pdf"), width =5, height = 7)



bind_rows(robchecks_e, robchecks_p) %>% 
  filter(term == "fertile_fab") %>% 
  mutate(check = fct_rev(fct_inorder(paste0('atop("",atop("', check,'",',
                                'phantom(0)^"(',n_persons, ' women, ',n_days,' days)"))')))) %>% 
  ggplot(aes(check, estimate, ymin = conf.low, ymax = conf.high)) + 
  geom_hline(yintercept = 0, linetype = 'dashed') +
  scale_x_discrete("Robustness check", labels = function(x) {parse(text=x)}) +
  ylab("Fertile window effect with 99% CI") +
  geom_pointrange() + 
  coord_flip() +
  facet_wrap(~ category, scales = "free_y") + 
  theme(axis.text.y = element_text(size = 11),
        strip.text = element_blank())

ggsave(paste0("figures/", model_prefix,"_robustness_checks.png"), width = 7, height = 7)
ggsave(paste0("figures/", model_prefix,"_robustness_checks.pdf"), width = 7, height = 7)