-
Notifications
You must be signed in to change notification settings - Fork 2
/
MrOS-Falls.Rmd
1897 lines (1566 loc) · 67.3 KB
/
MrOS-Falls.Rmd
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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Falls in MrOS"
author:
Marty Arrigotti^[OHSU-PSU School of Public Health]
Tyler Bennett^[OHSU-PSU School of Public Health]
Anna Booman^[OHSU-PSU School of Public Health]
Colin Hawkinson^[OHSU-PSU School of Public Health]
Matthew Hoctor^[OHSU-PSU School of Public Health]
date: "6/2/2021"
output:
html_document:
number_sections: no
theme: lumen
toc: yes
toc_float:
collapsed: yes
smooth_scroll: no
pdf_document:
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, libraries, include=FALSE}
library(tidyverse)
library(purrr)
library(readxl)
library(knitr)
library(lmtest)
library(dplyr)
library(gtsummary)
library(mfp)
library(LogisticDx)
library(ResourceSelection)
library(multcomp)
library(gridExtra)
library(DescTools)
library(GGally)
```
```{r, user defined functions, include=FALSE}
regression_CI = function(pe, se, alpha) {
# returns log odds from regression coefficients;
# just quick_CI with the necessary reordering of bounds
ub = pe + qnorm(1-alpha/2)*se
lb = pe - qnorm(1-alpha/2)*se
if (ub < lb){
return(data.frame(
"point_estimate" = pe,
"lower_bound" = ub,
"upper_bound" = lb))
}
return(data.frame(
"point_estimate" = pe,
"lower_bound" = lb,
"upper_bound" = ub))
}
```
# Data Exploration
## glimpse & skimr output:
```{r import data}
MrOs <- readxl::read_excel("MrOS_Baseline_Falls_Project.xlsx")
glimpse(MrOs)
skimr::skim(MrOs)
obj_classes <- c()
for(i in seq(1:length(MrOs))) {
obj_classes = c(obj_classes, class(MrOs[[1,i]]))
}
obj_classes
```
## Creation of site & qlhealth dummy variables and outcome variable
We'll consider every variable in the data frame other than patient ID as a candidate variable for the model. We'll use Portland as the referent group for when site is considered as a categorical variable. The **outcome** of interest is having more than one fall in a given year.
```{r 1. variable }
# unique(MrOs$site)
MrOs <- MrOs %>%
mutate(st_1 = case_when(
site == "PO" ~ 0,
site == "BI" ~ 1,
site == "MN" ~ 0,
site == "PA" ~ 0,
site == "PI" ~ 0,
site == "SD" ~ 0
)) %>%
mutate(st_2 = case_when(
site == "PO" ~ 0,
site == "BI" ~ 0,
site == "MN" ~ 1,
site == "PA" ~ 0,
site == "PI" ~ 0,
site == "SD" ~ 0
)) %>%
mutate(st_3 = case_when(
site == "PO" ~ 0,
site == "BI" ~ 0,
site == "MN" ~ 0,
site == "PA" ~ 1,
site == "PI" ~ 0,
site == "SD" ~ 0
)) %>%
mutate(st_4 = case_when(
site == "PO" ~ 0,
site == "BI" ~ 0,
site == "MN" ~ 0,
site == "PA" ~ 0,
site == "PI" ~ 1,
site == "SD" ~ 0
))%>%
mutate(st_5 = case_when(
site == "PO" ~ 0,
site == "BI" ~ 0,
site == "MN" ~ 0,
site == "PA" ~ 0,
site == "PI" ~ 0,
site == "SD" ~ 1
)) %>%
mutate(falls = case_when( # outcome coding
mhfalln2 > 1 ~ 1,
mhfalln2 <= 1 ~ 0
))
```
Creating the qlhealth dummy variables; 'Excellent' subjective health rating is used as the referent category:
```{r}
MrOs$qlh2 <- ifelse(MrOs$qlhealth == 2,1,0)
MrOs$qlh3 <- ifelse(MrOs$qlhealth == 3,1,0)
MrOs$qlh4 <- ifelse(MrOs$qlhealth == 4,1,0)
MrOs$qlh5 <- ifelse(MrOs$qlhealth == 5,1,0)
```
## Check Groups sizes for each unique value of each categorical variable
```{r check group sizes}
MrOs_group_check = MrOs %>%
dplyr::select(site, mhdiab, mhstrk,
mhpark, mhcopd, mharth, mhcancer,
st_1, st_2, st_3, st_4, st_5,
qlh2, qlh3, qlh4, qlh5)
counts_list <- map(.x = as.list(MrOs_group_check), .f = function(x) {
vector = unique(x)
q = c()
for (i in vector) {
v = x[x == i]
obs = length(v)
q = c(q, obs)
}
return(q)
})
counts_list
```
Note that when the length of the unique level is 5994 (the number of total rows in the dataset) it's due to the way R handles `NA` in boolean operations. The presence of this number in the above output is a signifier of missingness.
This also serves as a sanity check for the above dummy variable generation. We see that the correct number of observations exist in each dummy variable by comparing the lower count in the dummy variables to the counts in `site`.
There are only 52 subjects with a history of Parkinson's. That may be an issue later.
# Collinearity
```{r}
# colnames(MrOs)
MrOs_coll <- MrOs %>% dplyr::select(giage1, pascore, hwbmi, gsgrpavg, nfwlkspd, b1fnd, b1thd) %>% drop_na()
ggpairs(MrOs_coll)
```
# Variable Seleciton
## Step 1: Univariate Analysis
We employ a type 1 error rate of $\alpha = 0.20$ for univariate Wald Tests and construct 95% confidence intervals for each candidate variable's slope coefficient and one-unit odds ratio.
The null hypothesis for the Wald test, which is repeatedly used throughout this report, is that the beta coefficient in question $\hat \beta_i$ is equal to zero. The test statistic for the Wald test is $W = \frac{\hat \beta_1}{\widehat{SE} (\hat \beta_1)} \sim N(0,1)$. In output tables from `R`, the Wald statistic $W$ is represented by `z.value`. The criteria to reject is $P(|z| > W) < \alpha$, where alpha is the type one error rate specified for the particular test. Here, as has been already stated, we'll use a p-value of 0.20 as our cutoff for statistical significance, but other values for $\alpha$ will be specified throughout.
```{r}
models = list(
glm(falls ~ st_1 + st_2 +
st_3 + st_4 + st_5, data = MrOs, family = binomial()),
glm(falls ~ qlh2 + qlh3 + qlh4 + qlh5
, data = MrOs, family = binomial()),
glm(falls ~ qlhealth, data = MrOs, family = binomial()),
glm(falls ~ giage1, data = MrOs, family = binomial()),
glm(falls ~ mhdiab, data = MrOs, family = binomial()),
glm(falls ~ mhstrk, data = MrOs, family = binomial()),
glm(falls ~ mhcopd, data = MrOs, family = binomial()),
glm(falls ~ mhpark, data = MrOs, family = binomial()),
glm(falls ~ mharth, data = MrOs, family = binomial()),
glm(falls ~ mhcancer, data = MrOs, family = binomial()),
glm(falls ~ pascore, data = MrOs, family = binomial()),
glm(falls ~ qlhealth, data = MrOs, family = binomial()),
glm(falls ~ hwbmi, data = MrOs, family = binomial()),
glm(falls ~ b1tbfkg, data = MrOs, family = binomial()),
glm(falls ~ b1tblkg, data = MrOs, family = binomial()),
glm(falls ~ gsgrpavg, data = MrOs, family = binomial()),
glm(falls ~ nfwlkspd, data = MrOs, family = binomial()),
glm(falls ~ b1fnd, data = MrOs, family = binomial()),
glm(falls ~ b1thd, data = MrOs, family = binomial()))
# kable looks better in pdf
# map(.x =
# map(.x =
# models,
# .f =
# function(x)
# {data.frame(summary(x)$coefficients)}),
# .f =
# function(x) {kable(x)})
map(.x =
models,
.f =
function(x)
{data.frame(summary(x)$coefficients)})
```
Slope coefficients pass our univariate Wald test ($p < 0.2 = \alpha$) for study site, subjective health assessment, age at enrollment, history of diabetes, history of stroke, history of COPD, history of Parkinson's, history of arthritis, history of cancer, PASE score, body mass index (BMI), total body fat mass, average grip strength, walk speed, corrected femoral neck bone minderal density (BMD). The only variables excluded here are total body lean mass and corrected total hip BMD.
### Computing Wald p-value for each selected variable
```{r beta CI, OR CI, and Wald p-value for each model}
models = list(
glm(falls ~ giage1, data = MrOs, family = binomial()),
glm(falls ~ mhdiab, data = MrOs, family = binomial()),
glm(falls ~ mhstrk, data = MrOs, family = binomial()),
glm(falls ~ mhcopd, data = MrOs, family = binomial()),
glm(falls ~ mhpark, data = MrOs, family = binomial()),
glm(falls ~ mharth, data = MrOs, family = binomial()),
glm(falls ~ mhcancer, data = MrOs, family = binomial()),
glm(falls ~ pascore, data = MrOs, family = binomial()),
glm(falls ~ hwbmi, data = MrOs, family = binomial()),
glm(falls ~ b1tbfkg, data = MrOs, family = binomial()),
glm(falls ~ gsgrpavg, data = MrOs, family = binomial()),
glm(falls ~ nfwlkspd, data = MrOs, family = binomial()),
glm(falls ~ b1fnd, data = MrOs, family = binomial()))
map(.x = models, .f = function(x) {
coeffs = summary(x)$coefficients # table coefficients...
p = coeffs[2,4] # beta_1 p-val...
b = coeffs[,1][2] # beta_1...
se = coeffs[2,2] # beta_1 se...
beta_CI = regression_CI(pe = b, se = se, alpha = 0.05)
OR_CI = exp(beta_CI)
table = rbind(beta_CI, OR_CI)
table$p = c(p, NA)
rownames(table) = c(rownames(table)[1], "OR")
return((table)) # put kable() back
})
```
> For each of the above tables, the beta coefficient CI is labeled with the name of the variable being assessed in the table. The odds ratio is on the second row. The p-value for the Wald test is in the first entry of the last column *Note*: NA simply signifies the cell as empty.
Since site & health quality are multilevel and categorical, they are computed separately.
```{r}
site_model <- glm(falls ~ st_1 + st_2 +
st_3 + st_4 + st_5, data = MrOs, family = binomial())
# slope coefficients
betas <- site_model$coef[2:6]
# standard errors
ses <- as.data.frame(summary(site_model)$coef)$`Std. Error`[2:6]
# confidence interval beta & CI
beta_upper_bounds <- betas + qnorm(1-0.05/2)*ses
beta_lower_bounds <- betas - qnorm(1-0.05/2)*ses
OR_upper_bounds <- exp(betas + qnorm(1-0.05/2)*ses)
OR_lower_bounds <- exp(betas - qnorm(1-0.05/2)*ses)
OR <- exp(betas)
# formatting
tbl <- rbind(betas,
beta_upper_bounds,
beta_lower_bounds,
OR,
OR_upper_bounds,
OR_lower_bounds)
# output
as.data.frame(t(tbl))
```
Subjective health status:
```{r}
qlhealth_model <- glm(falls ~ qlh2 + qlh3 + qlh4 + qlh5,
data = MrOs,
family = binomial())
# slope coefficients
betas <- qlhealth_model$coef[2:5]
# standard errors
ses <- as.data.frame(summary(qlhealth_model)$coef)$`Std. Error`[2:5]
# confidence interval beta & CI
beta_upper_bounds <- betas + qnorm(1-0.05/2)*ses
beta_lower_bounds <- betas - qnorm(1-0.05/2)*ses
OR_upper_bounds <- exp(betas + qnorm(1-0.05/2)*ses)
OR_lower_bounds <- exp(betas - qnorm(1-0.05/2)*ses)
OR <- exp(betas)
# formatting
tbl <- rbind(betas,
beta_upper_bounds,
beta_lower_bounds,
OR,
OR_upper_bounds,
OR_lower_bounds)
# output
as.data.frame(t(tbl))
```
Drawing up the odds ratios and confidence intervals hasn't brought us to any separate conclusion than the univariate Wald tests did as to which variables are retained at the end of this step.
**Note**: if we use an alternative alpha of 0.05 for our univariate Wald tests, we would exclude `b1fnd`. Nothing else would change.
### initial gtsummary output with ORs & p-values
We can use the 'tbl_uvregression' function from the 'gtsummary' package to create a publishable table with the above information:
```{r}
MrOs %>%
dplyr::select(
giage1, mhdiab, mhstrk, mhpark, mhcopd, mharth, mhcancer, pascore, hwbmi, gsgrpavg, nfwlkspd, b1fnd, b1thd, b1tbfkg, b1tblkg,
falls,
st_1,st_2,st_3,st_4,st_5,
qlh2, qlh3, qlh4, qlh5) %>%
tbl_uvregression(
method = glm,
y = falls,
hide_n = TRUE,
exponentiate = TRUE,
method.args = list(family = 'binomial'),
label = list(
giage1 ~ "Age"
,mhdiab ~ "Diabetes"
,mhstrk ~ "Stroke"
,mhpark ~ "Parkinsons"
,mhcopd ~ "COPD"
,mharth ~ "Arthritis or Gout"
,mhcancer ~ "Cancer"
,pascore ~ "PASE Score"
,hwbmi ~ "Body Mass Index"
,b1tbfkg ~ "Total Body Fat"
,b1tblkg ~ "Lean Body Mass"
,gsgrpavg ~ "Average Grip Strength"
,nfwlkspd ~ "Walking Speed"
,b1fnd ~ "Corrected Femoral Neck BMD"
,b1thd ~ "Corrected Total Hip BMD"
,st_1 ~ "Birmingham Site (vs PO)"
,st_2 ~ "Minneapolis Site (vs PO)"
,st_3 ~ "Palo Alto Site (vs PO)"
,st_4 ~ "Pittsburg Site (vs PO)"
,st_5 ~ "San Diego Site (vs PO)"
,qlh2 ~ "Good Preceived Health (vs Excellent)"
,qlh3 ~ "Fair Preceived Health (vs Excellent)"
,qlh4 ~ "Poor Preceived Health (vs Excellent)"
,qlh5 ~ "Very Poor Preceived Health (vs Excellent)"
),
)%>%
modify_caption("**Initial Univariate Analysis**") %>%
bold_labels()
```
### Collapsing 'qlhealth'
Considering that 'good' subjective overall health is essentially the same as 'excellent' overall health (p=0.8), we can collapse the subjective overall health status variables into a single binary variable with value 0 for 'excellent'-'good health' ('qlhealth' = 1-2), and value 1 for 'fair' to 'very poor' health ('qlhealth' = 3-5):
```{r}
MrOs$qlh <- ifelse(MrOs$qlhealth == 1 | MrOs$qlhealth == 2, 0, 1)
```
### gtsummary output for paper with ORs & p-values
We can use the 'tbl_uvregression' function from the 'gtsummary' package to create a table for the current set of variables (i.e. collapsed subjective health status, but not the ordinal subjective health status variable):
```{r}
MrOs %>%
dplyr::select(giage1, mhdiab, mhstrk, mhpark, mhcopd, mharth, mhcancer, pascore, hwbmi, gsgrpavg, nfwlkspd, b1fnd, b1thd, b1tbfkg, b1tblkg, falls, st_1,st_2,st_3,st_4,st_5, qlh) %>%
tbl_uvregression(
method = glm,
y = falls,
exponentiate = TRUE,
hide_n = TRUE,
label = list(giage1 ~ "Age"
,mhdiab ~ "Diabetes"
,mhstrk ~ "Stroke"
,mhpark ~ "Parkinsons"
,mhcopd ~ "COPD"
,mharth ~ "Arthritis or Gout"
,mhcancer ~ "Cancer"
,pascore ~ "PASE Score"
,qlh ~ "Subjective Health Rating"
,hwbmi ~ "Body Mass Index"
,b1tbfkg ~ "Total Body Fat"
,b1tblkg ~ "Lean Body Mass"
,gsgrpavg ~ "Average Grip Strength"
,nfwlkspd ~ "Walking Speed"
,b1fnd ~ "Corrected Femoral Neck BMD"
,b1thd ~ "Corrected Total Hip BMD"
,st_1 ~ "Birmingham Site (vs PO)"
,st_2 ~ "Minneapolis Site (vs PO)"
,st_3 ~ "Palo Alto Site (vs PO)"
,st_4 ~ "Pittsburg Site (vs PO)"
,st_5 ~ "San Diego Site (vs PO)"
),
method.args = list(family = 'binomial'),
)%>%
modify_caption("**Univariate Analysis**") %>%
bold_labels()
```
## Step 2: First Multivariable Model
### Creating a dataset with NA observations removed
Throughout our handling of multivariate models, we'll use the following structure to subset the data to only the variables we're considering *before* censoring observations with incomplete fields.
```{r}
step2_narm <- MrOs %>%
dplyr::select(-b1tblkg,-b1thd,-mhfallv2) %>%
drop_na()
```
### Creating the full model
We'll add all the variables identified as important in step one to form our *full model*. Then we'll form a *reduced model* with every variable associated with a Wald test p-value less than 0.05 and compare the full and reduced model with the likelihood ratio test. The null hypothesis for the likelihood ratio test is $H_0: \beta_{inf} = 0$, $H_1: \beta_{inf} \neq 0$, where the criteria to reject is a p-value less than 0.05.
```{r}
full_model <-
glm(falls ~ giage1 + mhdiab + mhstrk + mhpark + mhcopd + mharth + mhcancer + pascore + qlh + hwbmi + gsgrpavg + nfwlkspd + b1fnd + b1tbfkg + st_1 + st_2 + st_3 + st_4 + st_5,
family = "binomial",
data = step2_narm)
kable(summary(full_model)$coef)
summary(full_model)$coef[,4] < 0.05
```
#### Full model table for presentation
```{r}
tbl_regression(full_model,
label = list(
giage1 ~ "Age"
,mhdiab ~ "Diabetes"
,mhstrk ~ "Stroke"
,mhpark ~ "Parkinsons"
,mhcopd ~ "COPD"
,mharth ~ "Arthritis or Gout"
,mhcancer ~ "Cancer"
,pascore ~ "PASE Score"
,hwbmi ~ "Body Mass Index"
,b1tbfkg ~ "Total Body Fat"
# ,b1tblkg ~ "Lean Body Mass"
,gsgrpavg ~ "Average Grip Strength"
,nfwlkspd ~ "Walking Speed"
,b1fnd ~ "Corrected Femoral Neck BMD"
# ,b1thd ~ "Corrected Total Hip BMD"
,st_1 ~ "Birmingham Site (vs PO)"
,st_2 ~ "Minneapolis Site (vs PO)"
,st_3 ~ "Palo Alto Site (vs PO)"
,st_4 ~ "Pittsburg Site (vs PO)"
,st_5 ~ "San Diego Site (vs PO)"
,qlh ~ "Subjective Health Rating"
),
exponentiate = FALSE)
```
### Creating the reduced model
Based on the above output we will exclude site, hx. diabetes, hx stroke, hx cancer, PACE score from the reduced model, and perform the liklihood ratio test between the full and reduced models. We will utilize the 'lrtest' function from the 'lmtest' package to perform this computation:
```{r}
reduced_model <-
glm(falls ~ giage1 + mhpark +
mhcopd + mharth + qlh +
hwbmi + gsgrpavg + nfwlkspd + b1fnd + b1tbfkg,
family = "binomial",
data = step2_narm)
kable(summary(reduced_model)$coef)
lrtest(full_model, reduced_model) # can't throw them all away
```
The reduced model does *not* provide a better fit than the full model. Therefore, we'll use the same full model, but reduce the model by only one variable before taking the likelihood ratio.
### Removing one variable at a time:
#### site
```{r}
# exclude site,
reduced_model <-
glm(falls ~ giage1 + mhdiab + mhstrk + mhpark + mhcopd + mharth + mhcancer + pascore + qlh + hwbmi + gsgrpavg + nfwlkspd + b1fnd + b1tbfkg,
family = "binomial",
data = step2_narm)
kable(summary(reduced_model)$coef)
lrtest(full_model, reduced_model) # exclude site
```
Exclude site.
#### DM2
```{r}
# exclude hx. diabetes,
reduced_model <-
glm(falls ~ giage1 + mhstrk + mhpark + mhcopd + mharth + mhcancer + pascore + qlh + hwbmi + gsgrpavg + nfwlkspd + b1fnd + b1tbfkg + st_1 + st_2 + st_3 + st_4 + st_5,
family = "binomial",
data = step2_narm)
kable(summary(reduced_model)$coef)
lrtest(full_model, reduced_model) # exclude hx. diabetes
```
Exclude hx dm2.
#### Stroke
```{r}
# exclude hx stroke
reduced_model <-
glm(falls ~ giage1 + mhdiab + mhpark + mhcopd + mharth + mhcancer + pascore + qlh + hwbmi + gsgrpavg + nfwlkspd + b1fnd + b1tbfkg + st_1 + st_2 + st_3 + st_4 + st_5,
family = "binomial",
data = step2_narm)
kable(summary(reduced_model)$coef)
lrtest(full_model, reduced_model) # exclude hx stroke
```
Exclude stroke hx.
#### Cancer
```{r}
# exclude hx cancer
reduced_model <-
glm(falls ~ giage1 + mhdiab + mhstrk + mhpark + mhcopd + mharth + pascore + qlh + hwbmi + gsgrpavg + nfwlkspd + b1fnd + b1tbfkg + st_1 + st_2 + st_3 + st_4 + st_5,
family = "binomial",
data = step2_narm)
kable(summary(reduced_model)$coef)
lrtest(full_model, reduced_model) # exclude hx cancer
```
Exclude cancer hx.
#### PACE score
```{r}
# exclude PACE score.
reduced_model <-
glm(falls ~ giage1 + mhpark +
mhcopd + mharth + qlh +
hwbmi + gsgrpavg + nfwlkspd + b1fnd + b1tbfkg,
family = "binomial",
data = step2_narm)
kable(summary(reduced_model)$coef)
lrtest(full_model, reduced_model) # don't exclude PACE score
```
Include PACE score.
### Adding back in PACE score
```{r}
# exclude site, hx. diabetes, hx stroke, hx cancer, PACE score.
full_model$call
# step2_narm$
reduced_model <-
glm(formula = falls ~ giage1 + mhpark + mhcopd +
mharth + pascore + qlh + hwbmi + gsgrpavg +
nfwlkspd + b1fnd + b1tbfkg,
family = "binomial",
data = step2_narm)
kable(summary(reduced_model)$coef)
lrtest(full_model, reduced_model)
```
We've added back PACE score to achieve the most parsimonious model for which the full model does not provide significant advantage in performance by the likelihood ratio test.
### Reduced model table for presentation
```{r}
tbl_regression(reduced_model,
label = list(
giage1 ~ "Age"
# ,mhdiab ~ "Diabetes"
# ,mhstrk ~ "Stroke"
,mhpark ~ "Parkinsons"
,mhcopd ~ "COPD"
,mharth ~ "Arthritis or Gout"
# ,mhcancer ~ "Cancer"
,pascore ~ "PASE Score"
,hwbmi ~ "Body Mass Index"
,b1tbfkg ~ "Total Body Fat"
# ,b1tblkg ~ "Lean Body Mass"
,gsgrpavg ~ "Average Grip Strength"
,nfwlkspd ~ "Walking Speed"
,b1fnd ~ "Corrected Femoral Neck BMD"
# ,b1thd ~ "Corrected Total Hip BMD"
# ,st_1 ~ "Birmingham Site (vs PO)"
# ,st_2 ~ "Minneapolis Site (vs PO)"
# ,st_3 ~ "Palo Alto Site (vs PO)"
# ,st_4 ~ "Pittsburg Site (vs PO)"
# ,st_5 ~ "San Diego Site (vs PO)"
,qlh ~ "Subjective Health Rating"
),
exponentiate = FALSE)
```
## Step 3: Check Removed Covariate(s) Using the Change in $\beta_i$ Method
We'll solve for a percent change in beta coefficients not including the intercept common in the full and reduced using a simple formula:
$$
\Delta = \left(\frac{final-initial}{final}\right )\times 100\%
$$
And we'll say that a $\Delta > 20\%$ is significant. If an individual coefficient is altered by more than 20%, at least one of the excluded coefficients may be an important confounder of the association between the outcome and a variable whose slope coefficient was altered.
```{r}
# reorder $call...
full_model <-
glm(formula = falls ~ # make sure the $call is ordered correctly
giage1 + mhpark + mhcopd + mharth + qlh + hwbmi +
gsgrpavg + nfwlkspd + b1fnd + b1tbfkg + mhstrk + pascore +
mhdiab + mhcancer + st_1 + st_2 + st_3 + st_4 + st_5,
family = "binomial",
data = step2_narm)
reduced_model <-
glm(formula = falls ~ # make sure the $call is ordered correctly
giage1 + mhpark + mhcopd + mharth + qlh + hwbmi +
gsgrpavg + nfwlkspd + b1fnd + b1tbfkg + mhstrk + pascore,
family = "binomial",
data = step2_narm)
# the change in beta
(reduced_model$coef[2:13]-full_model$coef[2:13])/reduced_model$coefficients[2:13]
# bool if change in beta exceeds 20%
abs((reduced_model$coef[2:13]-full_model$coef[2:13])/reduced_model$coefficients[2:13]) > 0.2
```
### Step 3 model
It appears that none of the variables excluded in step two are confounders in this model. We'll retain the reduced model from step two at this stage.
```{r}
step3_model <- reduced_model
summary(step3_model)$coef[,4] < 0.05
kable(summary(step3_model)$coef)
```
## Step 4: Checking Removed Covariates & Regrouping of Cagetorical Covariates
We'll add back the subjects' lean body mass and cancer status to determine if their joint significance by the Wald test is sufficient to include them in the model. We'll again use $\alpha = 0.05$ for the type one error rate of our Wald Test. We'll add the variables individually, then together.
### 'b1tblkg', lean body mass
```{r}
step3_narm1 <- MrOs %>%
dplyr::select(-b1thd,-mhfallv2) %>%
drop_na()
# add back b1tblkg
check_again_lean <- glm(formula = falls ~ giage1 + mhstrk + mhpark + mhcopd + mharth +
pascore + qlh + hwbmi + gsgrpavg + nfwlkspd + b1fnd +
b1tbfkg + b1tblkg,
family = "binomial",
data = step3_narm1)
summary(check_again_lean)$coef
summary(check_again_lean)$coef[14,4] < 0.05 # lean body mass now significant
```
lean body mass now significant
### 'b1thd', corrected hip bone mineral
```{r}
step3_narm2 <- MrOs %>%
dplyr::select(-b1tblkg,-mhfallv2) %>%
drop_na()
# add back b1tblkg
check_again_hipBMD <- glm(formula = falls ~ giage1 + mhstrk + mhpark + mhcopd + mharth +
pascore + qlh + hwbmi + gsgrpavg + nfwlkspd + b1fnd +
b1tbfkg + b1thd,
family = "binomial",
data = step3_narm2)
summary(check_again_hipBMD)$coef
summary(check_again_hipBMD)$coef[14,4] < 0.05 # corrected hip bone mineral now significant
```
Corrected hip bone mineral not significant.
### 'b1thd + b1tblkg', total lean body mass & hip BMD
```{r}
step3_narm3 <- MrOs %>%
dplyr::select(-mhfallv2) %>%
drop_na()
# add back b1tblkg
check_again_both <- glm(formula = falls ~ giage1 + mhstrk + mhpark + mhcopd + mharth +
pascore + qlh + hwbmi + gsgrpavg + nfwlkspd + b1fnd +
b1tbfkg + b1thd + b1tblkg,
family = "binomial",
data = step3_narm3)
summary(check_again_both)$coef
summary(check_again_both)$coef[14,4] < 0.05 # corrected hip bone mineral density not significant even when lean body mass considered
```
Only total LBM, 'b1tblkg', is significant, even when both are considered.
### step 4 model
We'll add lean body mass to the model from the last step to end step four. Addition of these variables does *not* make the variables added back at the previous stage pass a univaraite Wald test where $\alpha = 0.05$, but that's inconsequential.
```{r}
step4_model <- check_again_lean
df_1 <- as.data.frame(summary(step4_model)$coef)
df_1$pass <- df_1[,4] < 0.05
df_1
```
## Step 5: Check Linearity Assumption for Concinuous Variables
### Identifying continuous variables
```{r}
glimpse(step3_narm1)
```
### Graphical approach
We'll employ the loess approach to screen for linearity in the log odds across the range of each continuous independent variable. For variables that are obviously nonlinear by loess, we'll use the fractional polynomial approach to identify the best transformation.
```{r, loess checks}
# loess subject age
step3_narm1 = step3_narm1 %>% # #
arrange(desc(giage1)) %>%
map_df(rev)
gg1 <-
ggplot(data = step3_narm1) +
stat_smooth(formula = y~x,mapping = aes(x = giage1, y = falls), method = "loess") +
stat_smooth(formula = y~x,mapping = aes(x = giage1, y = falls), method = "lm", color = "red") +
labs(title = "Mult. Falls by Age") +
theme_minimal()
# loess PACE score
step3_narm1 = step3_narm1 %>%
arrange(desc(pascore)) %>%
map_df(rev)
gg2 <-
ggplot(data = step3_narm1) +
stat_smooth(formula = y~x,mapping = aes(x = pascore, y = falls), method = "loess") +
stat_smooth(formula = y~x,mapping = aes(x = pascore, y = falls), method = "lm", color = "red") +
labs(title = "Mult. Falls by PACE score") +
theme_minimal()
# loess BMI
step3_narm1 = step3_narm1 %>%
arrange(desc(hwbmi)) %>%
map_df(rev)
gg3 <-
ggplot(data = step3_narm1) +
stat_smooth(formula = y~x,mapping = aes(x = hwbmi, y = falls), method = "loess") +
stat_smooth(formula = y~x,mapping = aes(x = hwbmi, y = falls), method = "lm", color = "red") +
labs(title = "Mult. Falls by BMI") +
theme_minimal()
# loess grip strength
step3_narm1 = step3_narm1 %>%
arrange(desc(gsgrpavg)) %>%
map_df(rev)
gg4 <-
ggplot(data = step3_narm1) +
stat_smooth(formula = y~x,mapping = aes(x = gsgrpavg, y = falls), method = "loess") +
stat_smooth(formula = y~x,mapping = aes(x = gsgrpavg, y = falls), method = "lm", color = "red") +
labs(title = "Mult. Falls by Grip Strength") +
theme_minimal()
# loess walk speed
step3_narm1 = step3_narm1 %>%
arrange(desc(nfwlkspd)) %>%
map_df(rev)
gg5 <-
ggplot(data = step3_narm1) +
stat_smooth(formula = y~x,mapping = aes(x = nfwlkspd, y = falls), method = "loess") +
stat_smooth(formula = y~x,mapping = aes(x = nfwlkspd, y = falls), method = "lm", color = "red") +
labs(title = "Mult. Falls by Walk Speed") +
theme_minimal()
# loess corrected neck BMD
step3_narm1 = step3_narm1 %>%
arrange(desc(b1fnd)) %>%
map_df(rev)
gg6 <-
ggplot(data = step3_narm1) +
stat_smooth(formula = y~x,mapping = aes(x = b1fnd, y = falls), method = "loess") +
stat_smooth(formula = y~x,mapping = aes(x = b1fnd, y = falls), method = "lm", color = "red") +
labs(title = "Mult. Falls by Femoral Neck BMD") +
theme_minimal()
# loess body fat mass
step3_narm1 = step3_narm1 %>%
arrange(desc(b1tbfkg)) %>%
map_df(rev)
gg7 <-
ggplot(data = step3_narm1) +
stat_smooth(formula = y~x,mapping = aes(x = b1tbfkg, y = falls), method = "loess") +
stat_smooth(formula = y~x,mapping = aes(x = b1tbfkg, y = falls), method = "lm", color = "red") +
labs(title = "Mult. Falls by Total Fat Mass") +
theme_minimal()
# loess body lean mass
step3_narm1 = step3_narm1 %>%
arrange(desc(b1tblkg)) %>%
map_df(rev)
gg8 <-
ggplot(data = step3_narm1) +
stat_smooth(formula = y~x,mapping = aes(x = b1tblkg, y = falls), method = "loess") +
stat_smooth(formula = y~x,mapping = aes(x = b1tblkg, y = falls), method = "lm", color = "red") +
labs(title = "Mult. Falls by Total Lean Mass") +
theme_minimal()
grid.arrange(gg1,
gg2,
gg3,
gg4,
gg5,
gg6,
gg7,
gg8, nrow = 4)
```
### Checking fractional polynomials
We'll check the fractional polynomials for walk speed, corrected femoral neck bone mineral density, average left/right grip strength, BMI, and subject age.
```{r, fractional polynomial screening}
step4_model$call
fracpoly_age <- mfp(
falls ~ fp(giage1, df = 4) +
mhstrk + mhpark + mhcopd + mharth +
pascore + qlh + hwbmi + gsgrpavg + nfwlkspd + b1fnd +
b1tbfkg + b1tblkg, data = step3_narm1,
family = binomial(),
alpha = 0.1,
verbose = T # use ident for age
)
# frac_PACEscore <- mfp(
# falls ~ fp(pascore, df = 4) +
# giage1 + mhstrk + mhpark + mhcopd + mharth +
# qlh + hwbmi + gsgrpavg + nfwlkspd + b1fnd +
# b1tbfkg + b1tblkg, data = step3_narm1,
# family = binomial(),
# alpha = 0.1,
# verbose = T # use ident for PACE score
# )
frac_BMI <- mfp(
falls ~ fp(hwbmi, df = 4) +
giage1 + mhstrk + pascore + mhpark + mhcopd + mharth +
qlh + gsgrpavg + nfwlkspd + b1fnd +
b1tbfkg + b1tblkg, data = step3_narm1,
family = binomial(),
alpha = 0.1,
verbose = T # use ident for hwbmi
)
frac_grip <- mfp(
falls ~ fp(gsgrpavg, df = 4) +
giage1 + mhstrk + pascore + mhpark + mhcopd + mharth +
qlh + hwbmi + nfwlkspd + b1fnd +
b1tbfkg + b1tblkg, data = step3_narm1,
family = binomial(),
alpha = 0.1,
verbose = T # I((gsgrpavg/100)^-2)+I((gsgrpavg/100)^-2*log((gsgrpavg/100)))
)
frac_walkspeed <- mfp(
falls ~ fp(nfwlkspd, df = 4) +
giage1 + mhstrk + pascore + mhpark + mhcopd + mharth +
qlh + hwbmi + gsgrpavg + b1fnd +
b1tbfkg + b1tblkg, data = step3_narm1,
family = binomial(),
alpha = 0.1,
verbose = T # inverse square for nfwlkspd
)
frac_neckBMD <- mfp(
falls ~ fp(b1fnd, df = 4) +
giage1 + mhstrk + pascore + mhpark + mhcopd + mharth +
qlh + hwbmi + gsgrpavg + nfwlkspd +
b1tbfkg + b1tblkg, data = step3_narm1,
family = binomial(),
alpha = 0.1,
verbose = T # idnet for b1fnd
)
frac_fatMass <- mfp(
falls ~ fp(b1tbfkg, df = 4) +
giage1 + mhstrk + pascore + mhpark + mhcopd + mharth +
qlh + hwbmi + gsgrpavg + nfwlkspd +
b1fnd + b1tblkg, data = step3_narm1,
family = binomial(),
alpha = 0.1,
verbose = T # idnet for b1tbfkg
)
frac_fatMass <- mfp(
falls ~ fp(b1tblkg, df = 4) +
giage1 + mhstrk + pascore + mhpark + mhcopd + mharth +
qlh + hwbmi + gsgrpavg + nfwlkspd +
b1fnd + b1tbfkg, data = step3_narm1,
family = binomial(),
alpha = 0.1,
verbose = T # idnet for b1tblkg
)
```
### Creating transformed variables
```{r, encode transformation}
step4_narm <- step3_narm1 %>%
mutate(inv_sq_walk = nfwlkspd^-2) %>%
mutate(
grip_trform =
(gsgrpavg/100)^-2 + ((gsgrpavg/100)^-2 * log(gsgrpavg/100)))
```
### Visualizing transformed variables
```{r}
plot(step4_narm$nfwlkspd, step4_narm$inv_sq_walk)
plot(step4_narm$nfwlkspd, (step4_narm$nfwlkspd+1)^-2)
```
```{r}
plot(step4_narm$gsgrpavg,step4_narm$grip_trform)
```
From the above plots, we can formulate an offset transformation of inverse squared walking speed, which decreases the disproportionate values given to small absolute values of walking speed:
```{r}
step4_narm <- step4_narm %>%
mutate(offsetinv_sq_walk = (nfwlkspd+1)^-2)
```
```{r, loess for transforms}
step4_narm = step4_narm %>%
arrange(desc(inv_sq_walk)) %>%