-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0__selective_episodes.html
194 lines (168 loc) · 11.4 KB
/
0__selective_episodes.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
<!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> Selective Episodes</title>
<script src="library/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="library/bootstrap-3.3.5/css/paper.min.css" rel="stylesheet" />
<script src="library/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="library/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="library/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="library/navigation-1.1/tabsets.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<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;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<div class="row">
<div class="col-md-2" style="border-top:solid #E2A674 20px"></div>
<div class="col-md-2 rpqa" style="border-top:solid #9F3B2B 20px"></div>
<div class="col-md-4" style="background:black;text-align:center"><a href="index.html" style="color:white"><i class="glyphicon glyphicon-th-list"></i> Back to index</a></div>
<div class="col-md-2 hist_sweden" style="border-top:solid #21523B 20px"></div>
<div class="col-md-2 mod_sweden" style="border-top:solid #8A846C 20px"></div>
</div>
</div>
<div class="container-fluid main-container">
<div id="model-description" class="section level3">
<h3>Model description</h3>
<p>All of the following models have the following in common:</p>
<div id="estimation" class="section level4">
<h4>Estimation</h4>
<p>We fit all models using <code>brms</code> v. 1.2.0, a Bayesian regression analysis statistical package. <code>brms</code> uses <code>Stan</code>, a probabilistic programming langugage to fit models using Hamiltonian Monte Carlo.</p>
</div>
<div id="covariates" class="section level4">
<h4>Covariates</h4>
<p>As in our main models we adjust for average paternal age in the family, birth cohort (birth years in five equally large bins), for male sex, for age at paternal and maternal loss (0-1, 2-5, 6-10, …, 41-45, 45+, unknown), for maternal age (bins of 14-20, 20-35 and 35-50), for the number of siblings, for the number of older siblings (0-5, 5+) and for being last born.</p>
</div>
<div id="model-stratification" class="section level4">
<h4>Model stratification</h4>
<p>We added random intercepts for each family (father-mother dyad). We then controlled for the average paternal age in the family. Hence, the paternal age effects in the plot are split into those between families and those within families or between siblings. We are interested in the effect of paternal age between siblings, as this effect cannot be explained by e.g. genetic propensities of the father to reproduce late.</p>
</div>
</div>
<div id="e1_survive1y" class="section level2 tab-content">
<h2><em>e1</em>: Survival to first year</h2>
<p>Here, we predict the probability that the anchor survives the first year of life. All children born to this father are compared, if their death date is known or their survival can be inferred (from later marriage or children).</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">model_filename =<span class="st"> </span><span class="kw">make_path</span>(<span class="st">"e1_survive1y"</span>)
<span class="kw">summarise_model</span>()
e1 =<span class="st"> </span>model</code></pre></div>
</div>
<div id="e2_surviveR" class="section level2 tab-content">
<h2><em>e2</em>: Probability of surviving the first 15 years of life</h2>
<p>Here, we predict the probability that the anchor survives the first fifteen of life. All children born to this father who lived at least one year are compared, if their death date is known or their survival can be inferred (from later marriage or children).</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">model_filename =<span class="st"> </span><span class="kw">make_path</span>(<span class="st">"e2_surviveR"</span>)
<span class="kw">summarise_model</span>()
e2 =<span class="st"> </span>model</code></pre></div>
</div>
<div id="e3_ever_married" class="section level2 tab-content">
<h2><em>e3</em>: Probability of ever marrying</h2>
<p>Here, we predict the probability that the anchor ever marries. All anchors who reached reproductive age (15) are included.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">model_filename =<span class="st"> </span><span class="kw">make_path</span>(<span class="st">"e3_ever_married"</span>)
<span class="kw">summarise_model</span>()
e3 =<span class="st"> </span>model</code></pre></div>
</div>
<div id="e4_children" class="section level2 tab-content">
<h2><em>e4</em>: Number of children</h2>
<p>Here, we predict the number of children that the anchor had. To separate this effect from previous selective episodes, we include only ever-married anchors and control for their number of spouses (interacted with sex, because men tend to have more additional children from further spouses).</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">model_filename =<span class="st"> </span><span class="kw">make_path</span>(<span class="st">"e4_children"</span>)
<span class="kw">summarise_model</span>()
e4 =<span class="st"> </span>model</code></pre></div>
</div>
<div id="e5_divorce" class="section level2 tab-content">
<h2><em>e5</em>: Probability of ever divorcing</h2>
<p>Here, we predict the probability of ever divorcing. To separate this effect from previous selective episodes, we include only ever-married anchors. Divorce data was only analysed in modern Sweden.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">model_filename =<span class="st"> </span><span class="kw">make_path</span>(<span class="st">"e5_divorce"</span>)
if(<span class="kw">file.exists</span>(model_filename)) {
<span class="kw">cat</span>(<span class="kw">summarise_model</span>())
e5 =<span class="st"> </span>model
}</code></pre></div>
</div>
<div id="all-episodes" class="section level2">
<h2>All episodes</h2>
<p>Here we show the effect of paternal age for each episode.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">episodes =<span class="st"> </span><span class="kw">bind_rows</span>(
<span class="dt">e1 =</span> <span class="kw">paternal_age_10y_effect</span>(e1),
<span class="dt">e2 =</span> <span class="kw">paternal_age_10y_effect</span>(e2),
<span class="dt">e3 =</span> <span class="kw">paternal_age_10y_effect</span>(e3),
<span class="dt">e4 =</span> <span class="kw">paternal_age_10y_effect</span>(e4),
<span class="dt">e5 =</span> if( <span class="kw">exists</span>(<span class="st">"e5"</span>) ) { <span class="kw">paternal_age_10y_effect</span>(e5) } else { <span class="kw">data.frame</span>() },
<span class="dt">.id =</span> <span class="st">"episode"</span>
)
episodes$median_estimate =<span class="st"> </span><span class="kw">as.numeric</span>(episodes$median_estimate)
episodes$lower95 =<span class="st"> </span><span class="kw">as.numeric</span>(<span class="kw">str_match</span>(episodes$ci_95, <span class="st">"</span><span class="ch">\\</span><span class="st">[(-?[0-9.]+);"</span>)[,<span class="dv">2</span>])
episodes$upper95 =<span class="st"> </span><span class="kw">as.numeric</span>(<span class="kw">str_match</span>(episodes$ci_95, <span class="st">";(-?[0-9.]+)]"</span>)[,<span class="dv">2</span>])
<span class="kw">ggplot</span>(episodes %>%<span class="st"> </span><span class="kw">filter</span>(effect ==<span class="st"> "percentage change"</span>) %>%<span class="st"> </span><span class="kw">mutate</span>(<span class="dt">episode =</span> <span class="kw">factor</span>(episode,<span class="dt">levels =</span> <span class="kw">rev</span>(<span class="kw">unique</span>(episode)))), <span class="kw">aes</span>(<span class="dt">x =</span> episode, <span class="dt">y =</span> median_estimate, <span class="dt">ymin =</span> lower95, <span class="dt">ymax =</span> upper95)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_hline</span>(<span class="dt">yintercept =</span> <span class="dv">0</span>, <span class="dt">linetype =</span> <span class="st">'dashed'</span>) +
<span class="st"> </span><span class="kw">geom_pointrange</span>() +<span class="st"> </span>
<span class="st"> </span><span class="kw">xlab</span>(<span class="st">"Selective episode"</span>) +
<span class="st"> </span><span class="kw">ylab</span>(<span class="st">"Percentage change in outcome by paternal age"</span>) +
<span class="st"> </span><span class="kw">coord_flip</span>()
<span class="kw">saveRDS</span>(episodes, <span class="dt">file =</span> <span class="kw">make_path</span>(<span class="st">"episodes"</span>))</code></pre></div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
$(document).ready(function () {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
});
</script>
</body>
</html>