-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathback-pain.qmd
272 lines (147 loc) · 4.47 KB
/
back-pain.qmd
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
---
title: "Back pain: four outcomes"
author: "Ty and Kaja"
format:
pdf:
toc: true
highlight-style: atom-one
number-sections: true
editor: source
---
<!-- highlight-style supported themes: arrow, pygments, tango, espresso, zenburn, kate, monochrome, breezedark, haddock, atom-one, ayu, breeze, dracula, github, gruvbox, monokai, nord, oblivion, printing, radical, solarized, and vim. -->
```{R}
#| include: false
knitr::read_chunk('back-pain.R')
```
\newpage
# Approach
For each outcome, the simplest model that has appropriate fit will be sought. Models have been classified in rough ordering from "simplest" below using A, B, C, or D with A representing the common/easily understood models
<!-- thanks to https://www.tablesgenerator.com/markdown_tables -->
| **Outcome variable**/*Model* | *Multiple linear regression* (A) | *Ordinal logistic regression* (B${}^{*}$) | *Logistic regression* (B) | *Poisson/negative binomial regression* (C) | *Beta regression* (D) |
|---|---|---|---|---|---|
| **Binary** | - | - | + | - | - |
| | | | | | |
| **Ordinal** | - | + | + (if outcome made binary) | - | - |
| | | | | | |
| **Values from 0 to 100** | + (outcome potentially transformed) | - (if outcome made ordinal but bad option) | + (if outcome made binary) | + | + |
${}^{*}$Probably "C" not "B" but is basically multiple logistic regressions performed with different dichotomisations of the order levels in the outcome
\newpage
# Set up
## Packages
```{R, libs}
```
## Constants
```{R, consts}
```
\newpage
# Data wrangling
## Read data
```{R, read}
```
## Tidy data
```{R, tidy}
```
## Impute missing values in compositions
This code is thanks to Kaja!
Missing data is assumed to be below detectable threshold and imputed.
```{R, impute}
```
## Compositions transformation to *ilr*s
The below function will allow us to automatically add ilrs to a dataset
```{R, ilr_create}
```
\newpage
# Exploratory analysis
## Missing/`NA` value summaries
```{R, explore1}
#| warning: false
#| fig-height: 4
#| fig-width: 8
```
## Pairwise plots between *ilr*s and outcome variables
```{R, explore2}
#| warning: false
#| fig-height: 15
#| fig-width: 15
```
\newpage
# Statistical analysis
## Outcome 0: binary outcome of `Pain = "yes"`
### Model fit
```{R, outcome0}
```
### Model diagnostics
```{R, outcome0_diag}
```
### Model predictions
```{R, outcome0_pred}
#| fig-height: 8
#| fig-width: 8
```
\newpage
## Note for outcomes 1 to 2
The dataset for the remain outcomes will be limited to people who responded:
```{R, update_data}
```
\newpage
## Outcome 1: `LBP_frequency_year`
### Model fit
```{R, outcome1}
```
Ordinal logistic regression has fit the model:
<!-- logit (\hat{P}(Y \le \texttt{0days})) & = \hat{\beta}_{0,\texttt{0days|1-7days}} – \hat{\beta}_1 (age == \texttt{2\_middle}) – \ldots – \hat{\beta}_p {\times} \texttt{ilr(..+-)} \\ -->
$$
\begin{aligned}
logit (\hat{P}(Y \le \texttt{1-7days})) & = \hat{\beta}_{0,\texttt{1-7days|8-30days}} – \hat{\beta}_1 {\times}(age ) – \ldots – \hat{\beta}_p {\times} \texttt{ilr(..+-)} \\
logit (\hat{P}(Y \le \texttt{8-30days})) & = \hat{\beta}_{0,\texttt{8-30days|31-90days }} – \hat{\beta}_1 {\times}(age ) – \ldots – \hat{\beta}_p {\times} \texttt{ilr(..+-)} \\
logit (\hat{P}(Y \le \texttt{31-90days})) & = \hat{\beta}_{0,\texttt{31-90days|91+\_not\_evday}} – \hat{\beta}_1 {\times}(age) – \ldots – \hat{\beta}_p {\times} \texttt{ilr(..+-)} \\
logit (\hat{P}(Y \le \texttt{91+\_not\_evday})) & = \hat{\beta}_{0,\texttt{91+\_not\_evday|everyday}} – \hat{\beta}_1 (age == \texttt{2\_middle}) – \ldots – \hat{\beta}_p {\times} \texttt{ilr(..+-)} \\
\end{aligned}
$$
### Model diagnostics
```{R, outcome1_diag}
```
### Model predictions
```{R, outcome1_pred_a}
#| fig-height: 10
#| fig-width: 10
```
```{R, outcome1_pred_b}
#| fig-height: 10
#| fig-width: 10
```
\newpage
## Outcome 2: `LBP_intensity_year`
### Model fit
```{R, outcome2}
#| fig-height: 6
#| fig-width: 6
```
### Model diagnostics
```{R, outcome2_diag}
#| fig-height: 12
#| fig-width: 8
```
### Model predictions
```{R, outcome2_pred_a}
#| fig-height: 8
#| fig-width: 8
```
\newpage
#### Absolute scale
```{R, outcome2_pred_b_abs}
#| fig-height: 8
#| fig-width: 8
```
\newpage
#### Ratio scale
```{R, outcome2_pred_b_rat}
#| fig-height: 8
#| fig-width: 8
```
\newpage
# Session information
```{R}
format(Sys.time(), '%d %b %Y')
sessionInfo()
```