-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_robustness_checks_table.html
706 lines (588 loc) · 41 KB
/
3_robustness_checks_table.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<title>Robustness checks table</title>
<script src="site_libs/jquery-1.12.4/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/paper.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<script src="site_libs/navigation-1.1/codefolding.js"></script>
<link href="site_libs/highlightjs-1.1/default.css" rel="stylesheet" />
<script src="site_libs/highlightjs-1.1/highlight.js"></script>
<script src="site_libs/htmlwidgets-0.8/htmlwidgets.js"></script>
<script src="site_libs/datatables-binding-0.2/datatables.js"></script>
<link href="site_libs/dt-core-1.10.12/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="site_libs/dt-core-1.10.12/css/jquery.dataTables.extra.css" rel="stylesheet" />
<script src="site_libs/dt-core-1.10.12/js/jquery.dataTables.min.js"></script>
<link href="site_libs/nouislider-7.0.10/jquery.nouislider.min.css" rel="stylesheet" />
<script src="site_libs/nouislider-7.0.10/jquery.nouislider.min.js"></script>
<link href="site_libs/selectize-0.12.0/selectize.bootstrap3.css" rel="stylesheet" />
<script src="site_libs/selectize-0.12.0/selectize.min.js"></script>
<script src="library/auto_tab_first_section.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<script type="text/javascript">
if (window.hljs && document.readyState && document.readyState === "complete") {
window.setTimeout(function() {
hljs.initHighlighting();
}, 0);
}
</script>
<style type="text/css">
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}
</style>
<link rel="stylesheet" href="library/custom_styles.css" type="text/css" />
</head>
<body>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
.tabbed-pane {
padding-top: 12px;
}
button.code-folding-btn:focus {
outline: none;
}
</style>
<style type="text/css">
/* padding for bootstrap navbar */
body {
padding-top: 64px;
padding-bottom: 40px;
}
/* offset scroll position for anchor links (for fixed navbar) */
.section h1 {
padding-top: 69px;
margin-top: -69px;
}
.section h2 {
padding-top: 69px;
margin-top: -69px;
}
.section h3 {
padding-top: 69px;
margin-top: -69px;
}
.section h4 {
padding-top: 69px;
margin-top: -69px;
}
.section h5 {
padding-top: 69px;
margin-top: -69px;
}
.section h6 {
padding-top: 69px;
margin-top: -69px;
}
</style>
<script>
// manage active state of menu based on current page
$(document).ready(function () {
// active menu anchor
href = window.location.pathname
href = href.substr(href.lastIndexOf('/') + 1)
if (href === "")
href = "index.html";
var menuAnchor = $('a[href="' + href + '"]');
// mark it active
menuAnchor.parent().addClass('active');
// if it's got a parent navbar menu mark it active as well
menuAnchor.closest('li.dropdown').addClass('active');
});
</script>
<div class="container-fluid main-container">
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
</script>
<!-- code folding -->
<style type="text/css">
.code-folding-btn { margin-bottom: 4px; }
</style>
<script>
$(document).ready(function () {
window.initializeCodeFolding("show" === "show");
});
</script>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">Fertility diary</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="1_power_analysis.html">Power analysis</a>
</li>
<li>
<a href="1_researcher_df_analysis.html">Researcher degree of freedom simulation</a>
</li>
<li>
<a href="1_wrangle_data.html">Data wrangling</a>
</li>
<li>
<a href="2_descriptives.html">Descriptives</a>
</li>
<li>
<a href="3_fertility_as_prereg.html">Preregistered analyses</a>
</li>
<li>
<a href="3_fertility_robustness.html">Robustness tests</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div class="fluid-row" id="header">
<div class="btn-group pull-right">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span>Code</span> <span class="caret"></span></button>
<ul class="dropdown-menu" style="min-width: 50px;">
<li><a id="rmd-show-all-code" href="#">Show All Code</a></li>
<li><a id="rmd-hide-all-code" href="#">Hide All Code</a></li>
</ul>
</div>
<h1 class="title toc-ignore">Robustness checks table</h1>
</div>
<div id="table-with-descriptions" class="section level2">
<h2>Table with descriptions</h2>
<p>When a cell is empty, this reflects no difference to M_1.</p>
<div id="htmlwidget-5d0f4ea11ea87c0bdd88" style="width:100%;height:auto;" class="datatables html-widget"></div>
<script type="application/json" data-for="htmlwidget-5d0f4ea11ea87c0bdd88">{"x":{"filter":"top","filterHTML":"<tr>\n <td data-type=\"character\" style=\"vertical-align: top;\">\n <div class=\"form-group has-feedback\" style=\"margin-bottom: auto;\">\n <input type=\"search\" placeholder=\"All\" class=\"form-control\" style=\"width: 100%;\"/>\n <span class=\"glyphicon glyphicon-remove-circle form-control-feedback\">\u003c/span>\n \u003c/div>\n \u003c/td>\n <td data-type=\"character\" style=\"vertical-align: top;\">\n <div class=\"form-group has-feedback\" style=\"margin-bottom: auto;\">\n <input type=\"search\" placeholder=\"All\" class=\"form-control\" style=\"width: 100%;\"/>\n <span class=\"glyphicon glyphicon-remove-circle form-control-feedback\">\u003c/span>\n \u003c/div>\n \u003c/td>\n <td data-type=\"character\" style=\"vertical-align: top;\">\n <div class=\"form-group has-feedback\" style=\"margin-bottom: auto;\">\n <input type=\"search\" placeholder=\"All\" class=\"form-control\" style=\"width: 100%;\"/>\n <span class=\"glyphicon glyphicon-remove-circle form-control-feedback\">\u003c/span>\n \u003c/div>\n \u003c/td>\n <td data-type=\"character\" style=\"vertical-align: top;\">\n <div class=\"form-group has-feedback\" style=\"margin-bottom: auto;\">\n <input type=\"search\" placeholder=\"All\" class=\"form-control\" style=\"width: 100%;\"/>\n <span class=\"glyphicon glyphicon-remove-circle form-control-feedback\">\u003c/span>\n \u003c/div>\n \u003c/td>\n\u003c/tr>","data":[["M_1/M_e1","M_r1","M_e2","M_e3","M_e4","M_e5","M_e6","M_p1","M_p2","M_p3","M_p4","M_p5","M_p6","M_p7","M_p8","M_c1","M_c2","M_c3","M_c4","M_c5","M_c6","M_c7","M_c8","M_c9","M_d1","M_d2","M_d3","M_d4","M_d5","M_m1","M_m2","M_m3","M_m4","M_m5","M_m6","M_m7","M_m8","M_m9","M_m10"],["Baseline robustness check model. A random intercept for the participant, fixed effects for hormonal contraception, (pre-)menstruation, fertility (backward-counted from the observed or inferred next menstrual onset), and average fertility (to ensure within-subject estimates).","Test for individual differences in fertility effect. Added a random slope for the fertile window probability, the premenstruation dummy, and the menstruation dummy.","First preregistered set of exclusion criteria (see below).","Amended preregistered set of exclusion criteria except for two criteria.","As above + excluding those who felt stressed and those who said they might have irregular cycles, but were very unsure.","excluded 1251 diary days (4% of all) where participants a) gave the same answer to all Likert items (n=23), b) accessed the diary later or earlier than intended due to technical problems (n=896), or c) took more than 24 hours (n=376) or less than a minute (n=30) to finish filling out the diary","An exclusion criterion we had not preregistered","The fertility predictor was based on *confirmed* next menstrual onsets, without onsets *inferred* from average cycle length.","The fertility predictor was based on last menstrual onsets, i.e. forward-counting.","The fertility predictor was backward-counted from confirmed onsets, and a broad window (i.e. not continuous). Using windowed predictors, modelling menstruation and average fertility become unstable, so was omitted.","The fertility predictor was backward-counted from confirmed onsets, and a narrow window (i.e. not continuous). Using windowed predictors, modelling menstruation and average fertility become unstable, so was omitted.","The fertility predictor was forward-counted from last onsets, and a narrow window (i.e. not continuous). Using windowed predictors, modelling menstruation and average fertility become unstable, so was omitted.","The fertility predictor was forward-counted from last onsets, and a broad window (i.e. not continuous). Using windowed predictors, modelling menstruation and average fertility become unstable, so was omitted.","The fertility predictor was based on *inferred* next onsets based on reported average cycle length.","Excluded women with very long and very short cycles.","Adjusted for self esteem.","No adjustment for average fertile window probability.","No adjustment for menstruation dummies and average fertile window probability","Adjusted for week day and number of weeks since starting the diary.","Adjusted for time of response and time taken for response (log10+1).","Model autocorrelation of order 1 using `nlme::corAR1`","Model autocorrelation using moving averages of order 1 using `nlme::corARMA`","Like M_p3, but with the adjustments for (pre-)menstruation etc. Did not always converge.","Tested whether measurement reactivity might confound our results, by adjusting for splines for the number of days since the diary began (one variable for days filled out and one including missing days), different splines for hormonal contraceptive (non-)users","Between-subject design, forward-counted predictor.","Within-subject design with one high- and one low-fertility day per participant. Narrow window forward-counted predictor.","Within-subject design with two high- and two low-fertility day per participant. Narrow window forward-counted predictor.","No (observed) cycle lengths shorter than 20 days.","Within-subject design with high- and low-fertility averaged separately per participant. Backward-counted broad window predictor.","Instead of letting hormonal contraception status moderate the fertility and menstruation predictors, we differentiated by: hormonal, fertility awareness, barrier/abstinence, none","We let age group (18-20, 20-25, 25-30, 30-35, 35 and older) moderate the strength of the fertility predictor.","We let a week end dummy moderate the strength of the fertility predictor.","We let week day dummies moderate the strength of the fertility predictor.","We let maximal applicable exclusion threshold (all, lax, conservative, strict) moderate the strength of the fertility predictor.","We let cycle length (19-25, 25-30, 30-35, 35-40) moderate the strength of the fertility predictor.","We let self-reported certainty about menstruation regularity/cycle length moderate the strength of the fertility predictor.","We let self-reported menstruation regularity moderate the strength of the fertility predictor.","We let cohabitation status (same apartment, same city, long-distance) moderate the strength of the fertility predictor.","We let relationship status (partnered, engaged, married) moderate the strength of the fertility predictor."],["Minimal (\"all\")","","lax","conservative","strict","Without potentially unreliable data.","No women who were trying to get pregnant.","","","","","","","","No women with cycle lengths outside 20-40","","","","","","","","","Only people with more than 37 days filled out.","Took only the first day of the diary for every participant.","Only one high- and one low-fertility day per participant.","Only two high- and two low-fertility day per participant.","If time between menstrual onsets was lower than 20 days, excluded.","All days used, but averaged (so ignoring varying number of days per participant).","Excluding women who use other methods than these (e.g. partner sterilisation).","","","","","","","","",""],["outcome ~ (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 + fertile_window_probability + premenstrual_phase + menstruation | person)","","","","","","","","outcome ~ fertile_window_probability * hormonal_contraceptive_user + (1 | person)","outcome ~ fertile_window_probability * hormonal_contraceptive_user + (1 | person)","outcome ~ fertile_window_probability * hormonal_contraceptive_user + (1 | person)","outcome ~ fertile_window_probability * hormonal_contraceptive_user + (1 | person)","","","outcome ~ self_esteem + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + (1 | person)","outcome ~ fertile_window_probability * hormonal_contraceptive_user + (1 | person)","outcome ~ week_day + week_number + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ time_of_response + log10(time_for_response+1) + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","","","outcome ~ (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ s(days_filled_out, by = hormonal_contraceptive_user) + s(day_nr, by = hormonal_contraceptive_user) + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ fertile_window_probability * hormonal_contraceptive_user","outcome ~ fertile_window_probability * hormonal_contraceptive_user + (1 | person)","outcome ~ fertile_window_probability * hormonal_contraceptive_user + (1 | person)","","outcome ~ fertile_window_probability * hormonal_contraceptive_user + (1 | person)","","outcome ~ fertile_window_probability * age_groups + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ fertile_window_probability * week_end + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ fertile_window_probability * week_day + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ fertile_window_probability * exclusion_threshold + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ fertile_window_probability * cycle_length + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ fertile_window_probability * certainty_menstruation + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ fertile_window_probability * menstruation_regularity + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ fertile_window_probability * cohabitation + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)","outcome ~ fertile_window_probability * relationship_status + (fertile_window_probability + premenstrual_phase + menstruation) * hormonal_contraceptive_user + average_fertile_window_probability+ (1 | person)"]],"container":"<table class=\"display\">\n <thead>\n <tr>\n <th>Model\u003c/th>\n <th>Description\u003c/th>\n <th>Exclusion criteria\u003c/th>\n <th>in Wilkinson notation\u003c/th>\n \u003c/tr>\n \u003c/thead>\n\u003c/table>","options":{"pageLength":50,"autoWidth":true,"order":[],"orderClasses":false,"orderCellsTop":true}},"evals":[],"jsHooks":[]}</script>
<div id="legend-predictors" class="section level3">
<h3>Legend predictors</h3>
<p>To see predictor definitions, see this <a href="2_descriptives.html#predictors">table</a> (Table 3 in the manuscript).</p>
</div>
<div id="legend-exclusion-criteria" class="section level3">
<h3>Legend exclusion criteria:</h3>
<p>Stricter exclusion criteria (further down), subsume the ones above.</p>
<div id="all" class="section level4">
<h4>all</h4>
<ul>
<li>menopausal (indirectly defined by us still observing periods)</li>
<li>use hormonal contraception</li>
<li>pregnant</li>
</ul>
</div>
<div id="lax" class="section level4">
<h4>lax</h4>
<ul>
<li>age >= 40</li>
<li>use hormonal contraception</li>
<li>switched to hormonal contraception</li>
<li>certain medication</li>
<li>took pill/hormonal antibiotics during the last three months</li>
<li>certain illnesses</li>
<li>breastfeeding</li>
<li>pregnant</li>
<li>irregular cycle</li>
<li>guessed the hypothesis</li>
</ul>
</div>
<div id="conservative" class="section level4">
<h4>conservative</h4>
<ul>
<li>BMI</li>
<li>weight loss</li>
<li>cigs</li>
<li>intensive sports</li>
<li>those with irregular cycle but only if they are fairly sure about regularity</li>
</ul>
</div>
<div id="strict" class="section level4">
<h4>strict</h4>
<ul>
<li>stressed</li>
<li>those with irregular cycle even if they are basically guessing about regularity</li>
</ul>
</div>
</div>
</div>
<div id="code-for-automatically-conducting-robustness-checks-based-on-the-baseline-model" class="section level2">
<h2>Code for automatically conducting robustness checks based on the baseline model</h2>
<p>See also <a href="0_helpers.html">0_helpers.R</a></p>
<pre class="r"><code>robustness_check_ovu_shift = function(obj, diary) {
library(lme4); library(lmerTest); library(sjPlot)
get_coefs = function(fit, model_name) {
library(broom)
if (class(fit) == "lme") {
obj_coef = tryCatch({my_tidy.lme(fit, effects = 'fixed') }, error = function(e) { cat_message(e, "danger") })
} else {
obj_coef = tryCatch({tidy(fit, conf.int = TRUE, effects = "fixed")}, error = function(e) { cat_message(e, "danger") })
}
obj_coef$model = model_name
obj_coef
}
outcome = as.character(formula(obj)[2])
outcome_label = recode(str_replace_all(str_replace_all(str_replace_all(outcome, "_", " "), " pair", "-pair"), " 1", ""),
"desirability" = "self-perceived desirability",
"NARQ admiration" = "narcissistic admiration",
"NARQ rivalry" = "narcissistic rivalry",
"extra-pair" = "extra-pair desire & behaviour",
"had sexual intercourse" = "sexual intercourse")
less_ctrl_formula = update.formula(formula(obj), new = . ~ . - included * menstruation - fertile_mean)
tryCatch({
update(obj, formula = less_ctrl_formula) -> fewer_controls
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
one_ctrl_formula = update.formula(formula(obj), new = . ~ . - fertile_mean)
update(obj, formula = one_ctrl_formula) -> dontcontrolavg
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
diary_nododgy = diary %>% filter(dodgy_data == F)
update(obj, data = diary_nododgy) -> nododgy
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
diary_nopreg = diary %>% filter(trying_to_get_pregnant == 'no')
update(obj, data = diary_nopreg) -> notrypreg
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
diary_broad = diary %>% mutate(fertile = fertile_broad)
update(obj, formula = less_ctrl_formula, data = diary_broad) -> broad_window
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
diary_broad = diary %>% mutate(fertile = fertile_broad)
update(obj, data = diary_broad) -> broad_window_ctrl
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
diary_bci = diary %>% mutate(fertile = prc_stirn_b_backward_inferred)
update(obj, formula = less_ctrl_formula, data = diary_bci) -> backward_inferred
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
diary_narrow = diary %>% mutate(fertile = fertile_narrow)
update(obj, formula = less_ctrl_formula, data = diary_narrow) -> narrow_window
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
diary_cont_fc = diary %>% mutate(fertile = prc_stirn_b_forward_counted)
update(obj, data = diary_cont_fc) -> forward_counting
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
diary_narrow_fc = diary %>% mutate(fertile = fertile_narrow_forward_counted)
update(obj, formula = less_ctrl_formula, data = diary_narrow_fc) -> forward_counting_narrow
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
diary_broad_fc = diary %>% mutate(fertile = fertile_broad_forward_counted)
update(obj, formula = less_ctrl_formula, data = diary_broad_fc) -> forward_counting_broad
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
diary_cont = diary %>% mutate(fertile = prc_stirn_b)
update(obj, data = diary_cont) -> backward
}, error = function(e) { cat_message(e, "danger") })
# tryCatch({
# diary %>% mutate(fertile = prc_wcx_b) %>%
# update(obj, data = .) -> wilcox
# }, error = function(e) { cat_message(e, "danger") })
tryCatch({
ilax = diary %>% mutate(included = included_lax)
update(obj, data = ilax) -> included_lax
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
if(outcome != 'self_esteem_1') {
update(obj, formula = update.formula(formula(obj), new = . ~ . + self_esteem_1)) -> control_self_esteem
}
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
iconser = diary %>% mutate(included = included_conservative)
update(obj, data = iconser) -> included_conservative
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
istrict = diary %>% mutate(included = included_strict)
update(obj, data = istrict) -> included_strict
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
no_short = diary %>% filter(is.na(cycle_length_diary) | cycle_length_diary >= 20)
update(obj, data = no_short) -> no_cycles_shorter_than_20
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
no_long = diary %>% filter(is.na(cycle_length_diary) | (cycle_length_diary >= 20 & cycle_length_diary <= 40))
update(obj, data = no_long) -> cycles_between_20_40
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
update(obj, formula = update.formula(formula(obj), new = . ~ . + weekday + week_number)) -> control_week
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
update(obj, formula = update.formula(formula(obj), new = . ~ . + time_of_response + log10(time_for_response+1))) -> control_time_of_response
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
diary %>%
mutate(fertile = prc_stirn_b_forward_counted) %>%
filter(!is.na(fertile) & !is.na(included) & menstruation == "no") %>%
filter_(lazyeval::interp( ~ !is.na(outcome), outcome = as.name(obj@frame %>% names() %>% .[1]))) %>%
filter(!duplicated(person)) -> diary_tmp2
form = update.formula(formula(obj), new = . ~ . - fertile_mean - menstruation - included:menstruation - (1 | person))
environment(form) = environment()
lm(formula = form, data = diary_tmp2) -> between_person
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
four_occ = diary %>%
mutate(fertile = fertile_narrow_forward_counted,
person_occasion = paste(person, fertile)) %>%
filter(!is.na(fertile) & !is.na(included) & menstruation == "no") %>%
filter_(lazyeval::interp( ~ !is.na(outcome), outcome = as.name(obj@frame %>% names() %>% .[1]))) %>%
mutate(row_nr_even = row_number(person) %% 2,
person_occasion = paste(person_occasion, row_nr_even)) %>%
filter(!duplicated(person_occasion)) %>%
group_by(person) %>%
mutate(nr_days = n()) %>%
filter(nr_days == 4)
update(obj, formula = update.formula(formula(obj), new = . ~ . - fertile_mean - included:menstruation - menstruation) , data = four_occ) -> within_person_four_occasions
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
avg_twotime = diary %>%
mutate(fertile = fertile_broad) %>%
filter(!is.na(fertile) & !is.na(included) & menstruation == "no") %>%
select(person, fertile, included, one_of(outcome)) %>%
group_by(included, person, fertile) %>%
summarise_all(funs(mean(.,na.rm = T)))
update(obj, formula = less_ctrl_formula , data = avg_twotime) -> within_person_avg_hilow
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
two_occ = diary %>%
mutate(fertile = fertile_narrow_forward_counted,
person_occasion = paste(person, fertile)) %>%
filter(!is.na(fertile) & !is.na(included) & menstruation == "no") %>%
filter_(lazyeval::interp( ~ !is.na(outcome), outcome = as.name(obj@frame %>% names() %>% .[1]))) %>%
filter(!duplicated(person_occasion)) %>%
group_by(person) %>%
mutate(nr_days = n()) %>%
filter(nr_days == 2)
update(obj, formula = update.formula(formula(obj), new = . ~ . - fertile_mean - included:menstruation - menstruation) , data = two_occ) -> within_person_two_occasions
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
# findbars(formula(obj))[[1]]
reactive = diary %>% group_by(person) %>% mutate(days_filled_out = row_number(day_number)) %>% filter(day_number < 40, days_filled_out < 37)
new_form = update.formula(nobars(formula(obj)), . ~ . + s(day_number, by = included) + s(days_filled_out, by = included))
gamm4::gamm4(new_form, random = ~ (1 | person), data = reactive, family = family(obj)) -> control_reactivity
control_reactivity_mer = control_reactivity$mer
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
# findbars(formula(obj))[[1]]
if (class(obj) != "glmerMod") {
nlme::lme(fixed = nobars(formula(obj)), random = ~ 1 | person, data = diary, na.action = na.exclude, correlation = nlme::corAR1(form = ~ day_number | person), method = "REML") -> control_autocorrelation
control_autocorrelation$call$fixed = control_autocorrelation$terms
}
}, error = function(e) { cat_message(e, "danger") })
tryCatch({
if (class(obj) != "glmerMod") {
nlme::lme(fixed = nobars(formula(obj)), random = ~ 1 | person, data = diary, na.action = na.exclude, correlation = nlme::corARMA(form = ~ day_number | person, p = 1, q = 1), method = "REML") -> autocorrelation_moving_avg
autocorrelation_moving_avg$call$fixed = autocorrelation_moving_avg$terms
}
}, error = function(e) { cat_message(e, "danger") })
models_in_function = ls_type(c('lmerMod','glmerMod','bglmerMod','blmerMod','merModLmerTest','lme','lm'))
coefs = rbindlist(lapply(models_in_function, FUN = function(x) { get_coefs(get(x), x) }), fill = TRUE)
# eff_coefs = rbindlist(lapply(models_in_function, FUN = function(x) { get_eff_coefs(get(x), x) }), fill = TRUE)
coefs$model = dplyr::recode_factor(factor(coefs$model),
'obj' = 'M_1. Main model (all), BC+BCi',
'included_lax' = 'M_e2. Lax exclusion criteria',
'included_conservative' = 'M_e3. Conservative exclusion criteria',
'included_strict' = 'M_e4. Strict exclusion criteria',
'nododgy' = 'M_e5. Exclude potentially dodgy data',
'notrypreg' = 'M_e6. Exclude those trying to get pregnant',
'backward' = 'M_p1. Continuous, BC',
'forward_counting' = 'M_p2. Continuous, FC',
'broad_window' = 'M_p3. Broad window, BC',
'narrow_window' = 'M_p4. Narrow window, BC',
'forward_counting_narrow' = 'M_p5. Narrow window, FC',
'forward_counting_broad' = 'M_p6. Broad window, FC',
'backward_inferred' = 'M_p7. BC from rep. cycle length, when onset unknown',
'cycles_between_20_40' = 'M_p8. Only cycles 20-40 days long',
'between_person' = 'M_d1. Between, FC (first obs. only)',
'within_person_two_occasions' = 'M_d2. Within, FC, high/low 2 obs.',
'within_person_four_occasions' = 'M_d3. Within, FC, two high/low 4 obs.',
'no_cycles_shorter_than_20' = 'M_d4. No cycles shorter than 20 days',
'within_person_avg_hilow' = 'M_d5. Within, BC, average high/low all',
'control_self_esteem' = 'M_c1. Adjust for self esteem',
'dontcontrolavg' = 'M_c2. No adjustment for avg. fertility',
'fewer_controls' = 'M_c3. No adjustment for menstruation & avg. fertility',
'control_week' = 'M_c4. Control week day and number',
'control_time_of_response' = 'M_c5. Adjust for time of/for response',
'control_autocorrelation' = 'M_c6. Model autocorrelation, lag 1',
'autocorrelation_moving_avg' = 'M_c7. Model autocorrelation, moving avg., lag 1',
'broad_window_ctrl' = 'M_c8. Broad BC, adj. menstruation',
'control_reactivity_mer' = 'M_c9. Adjust for reactivity', .ordered = T)
coefs$model = factor(coefs$model, levels = rev(levels(coefs$model)))
coefs = coefs %>% mutate(term = recode(term, "fertile:includedhorm_contra" = "includedhorm_contra:fertile", "Xfertile" = "fertile", "Xincludedhorm_contra:fertile" = "includedhorm_contra:fertile"))
# eff_coefs$model = factor( car::Recode(eff_coefs$model, modeltranslate ))
coefs_all = coefs
coefs = coefs %>% filter(term == "fertile" | term == "includedhorm_contra:fertile")
cat("\n\n\n#### M_e: Exclusion criteria \n\n")
plote = ggplot(coefs %>% filter(model %begins_with% "M_e" | model %begins_with% "M_1. "), aes(x = model, y = estimate, ymax = conf.high, ymin = conf.low, colour = term), group = 1) +
geom_hline(yintercept = 0, linetype = "dotted", color = "gray70") +
geom_text(aes(label = round(estimate,2), y = estimate), position = position_dodge(width = 0.6), vjust = -0.7) +
geom_pointrange( position = position_dodge(width = 0.6), size = 1) +
scale_color_manual("Contraception status", values = c("includedhorm_contra:fertile"="black","fertile" = "red"), labels = c("includedhorm_contra:fertile"="hormonally\ncontracepting","fertile" = "fertile"), guide = F) +
xlab("Model") +
ylab(paste("Regression slope + 95 CI%")) +
ggtitle(outcome_label) +
coord_flip()
print(plote)
# cat("\n\n\n")
# coefs_all %>%
# filter(model %begins_with% "M_e" | model %begins_with% "M_1. ") %>%
# select(model, term, estimate, conf.low, conf.high) %>%
# pander() %>%
# cat()
cat("\n\n\n#### M_p: Predictors \n\n")
plotp = ggplot( coefs %>% filter(model %begins_with% "M_p" | model %begins_with% "M_1. "), aes(x = model, y = estimate, ymax = conf.high, ymin = conf.low, colour = term), group = 1) +
geom_hline(yintercept = 0, linetype = "dotted", color = "gray70") +
geom_text(aes(label = round(estimate,2), y = estimate), position = position_dodge(width = 0.6), vjust = -0.7) +
geom_pointrange( position = position_dodge(width = 0.6), size = 1) +
scale_color_manual("Contraception status", values = c("includedhorm_contra:fertile"="black","fertile"= "red"), labels = c("includedhorm_contra:fertile"="hormonally\ncontracepting","fertile"="fertile"), guide = F) +
xlab("Model") +
ylab(paste("Regression slope + 95 CI%")) +
ggtitle(outcome_label) +
coord_flip()
print(plotp)
#
cat("\n\n\n#### M_c: Covariates, controls, autocorrelation \n\n")
plotc = ggplot(coefs %>% filter(model %begins_with% "M_c" | model %begins_with% "M_1. "), aes(x = model, y = estimate, ymax = conf.high, ymin = conf.low, colour = term), group = 1) +
geom_hline(yintercept = 0, linetype = "dotted", color = "gray70") +
geom_text(aes(label = round(estimate,2), y = estimate), position = position_dodge(width = 0.6), vjust = -0.7) +
geom_pointrange( position = position_dodge(width = 0.6), size = 1) +
scale_color_manual("Contraception status", values = c("includedhorm_contra:fertile"="black","fertile"= "red"), labels = c("includedhorm_contra:fertile"="hormonally\ncontracepting","fertile"="fertile"), guide = F) +
xlab("Model") +
ylab(paste("Regression slope + 95 CI%")) +
ggtitle(outcome_label) +
coord_flip()
print(plotc)
tryCatch({
print_summary(control_reactivity$mer)
print_summary(control_reactivity$gam)
plot(control_reactivity$gam, pages = 1)
if (class(obj) != "glmerMod") {
print_summary(control_autocorrelation)
print_summary(autocorrelation_moving_avg)
} else {
cat_message("No AR1/ARMA autocorrelation models were fitted for binomial outcomes.", "info")
}
}, error = function(e) { cat_message(e, "danger") })
cat("\n\n\n#### M_d: Other designs \n\n")
plotd = ggplot( coefs %>% filter(model %begins_with% "M_d" | model %begins_with% "M_1. "), aes(x = model, y = estimate, ymax = conf.high, ymin = conf.low, colour = term), group = 1) +
geom_hline(yintercept = 0, linetype = "dotted", color = "gray70") +
geom_text(aes(label = round(estimate,2), y = estimate), position = position_dodge(width = 0.6), vjust = -0.7) +
geom_pointrange( position = position_dodge(width = 0.6), size = 1) +
scale_color_manual("Contraception status", values = c("includedhorm_contra:fertile"="black","fertile"= "red"), labels = c("includedhorm_contra:fertile"="hormonally\ncontracepting","fertile"="fertile"), guide = F) +
xlab("Model") +
ylab(paste("Estimate of effect on", outcome)) +
coord_flip()
print(plotd)
cat("\n\n\n#### _M_m1_: Moderation by contraceptive method \n\n
Based on the sample with lax exclusion criteria. Users who used any hormonal contraception are classified as hormonal, users who use any awareness-based methods (counting, temperature-based) are classified as 'fertility-awareness', women who don't fall into the before groups and use condoms, pessars, coitus interruptus etc. are classified as 'barrie or abstinence'. Women who don't use contraception or use other methods such as sterilisation are excluded from this analysis.
\n\n")
tryCatch({
update(obj, formula = . ~ . - included * (menstruation + fertile) + contraceptive_methods + (fertile + menstruation) + included:(fertile + menstruation),
data = diary, subset = !is.na(included_lax) & contraceptive_method != "other") -> add_main
update(obj, formula = . ~ . - included * (menstruation + fertile) + contraceptive_methods * (fertile + menstruation),
data = diary, subset = !is.na(included_lax) & contraceptive_method != "other") -> by_method
method_eff_coefs = sjp.int(by_method, type = "eff", showCI = F, printPlot = F)$data.list[[1]]
rec = c("hormonal" = "hormonally\ncontracepting","barrier_or_abstinence" = "only barrier\n(condoms, ...)\nor abstinence", "fertility_awareness" = "potentially\nfertility aware", "none" = "not using contraception")
method_eff_coefs$method = rec[as.character(method_eff_coefs$grp)]
eff_plot = ggplot(method_eff_coefs,
aes(x = x, y = y, ymax = conf.high, ymin = conf.low)) +
geom_smooth( size = 1, stat = "identity", color = 'black') +
xlab("Conception probability") +
facet_wrap(~ method) +
ylab(outcome)
print(eff_plot)
coefs = get_coefs(by_method, "by method") %>% filter(term != "(Intercept)")
plot = ggplot(coefs, aes(x = term, y = estimate, ymax = conf.high, ymin = conf.low, group = term)) +
geom_hline(yintercept = 0, linetype = "dotted", color = "gray70") +
geom_text(aes(label = round(estimate,2), y = estimate), position = position_dodge(width = 0.6), vjust = -0.7) +
geom_pointrange( position = position_dodge(width = 0.6), size = 1) +
xlab("Model") +
ylab(paste("Estimate of effect on", outcome)) +
coord_flip()
print(plot)
print_summary(by_method)
cat(pander(anova(add_main, by_method)))
}, error = function(e) { cat_message(e, "danger") })
invisible(obj)
}
#' ## Test a moderator
test_moderator = function (obj, moderator, diary, multiline = F, xlevels = 3) {
tryCatch({
add_main = update.formula(formula(obj), new = as.formula(paste0(". ~ . + ", moderator, " * included "))) # reorder so that the triptych looks nice
add_mod_formula = update.formula(update.formula(formula(obj), new = . ~ . - included * fertile), new = as.formula(paste0(". ~ . + ", moderator, " * included * fertile"))) # reorder so that the triptych looks nice
update(obj, formula = add_main) -> with_main
update(obj, formula = add_mod_formula) -> with_mod
cat(pander(anova(with_main, with_mod)))
plot_triptych(with_mod, x.var = "fertile", multiline = multiline, xlevels = xlevels)
print_summary(with_mod)
}, error = function(e) { cat_message(e, "danger") })
invisible(obj)
}</code></pre>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>