forked from strengejacke/paper-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#02 - Regression Einfluss auf Fixierung.R
137 lines (104 loc) · 3.58 KB
/
#02 - Regression Einfluss auf Fixierung.R
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
suppressMessages(suppressWarnings({
library(ggplot2) # Abbildungen
library(sjPlot) # Abbildungen / Tabellen
library(ggeffects) # Abbildungen Estimated Marginal Means
library(see) # Abbildungen manipulieren
library(performance) # Modelldiagnostik
library(emmeans) # Multiples Testen
}))
# Daten laden ----
load("david.RData")
# Variiert Outcome 2 in Abhängigkeit der Hauptdiagnose? ----
ggplot2::theme_set(theme_sjplot2())
sjp.xtab(
david$Hauptdiagnose,
david$Fixierung_d,
show.values = F,
show.total = F,
ylim = c(0, .4),
grid.breaks = .05
) + label_angle(90)
# Modell 2: Fixierung ohne Interaktion ----
mf2 <-
formula(
Fixierung_d ~ sex + alter_z + dementia_mmse + cci_z +
barthtot_a_z + Dauer_z + pas_score_z + kkh_r
)
# Modell 4: Fixierung mit Interaktion ----
mf4 <-
formula(
Fixierung_d ~ sex + alter_z + dementia_mmse + cci_z +
barthtot_a_z * kkh_r + Dauer_z * kkh_r + pas_score_z * kkh_r
)
m2 <- glm(mf2, family = binomial(), data = david)
m4 <- glm(mf4, family = binomial(), data = david)
# Modelldiagnostik Modelle 3 und 4 ----
check_collinearity(m2)
binned_residuals(m2)
performance_pcp(m2)
check_collinearity(m4)
binned_residuals(m4)
performance_pcp(m4)
# Odds Ratio und Marginal Effects ----
tab_model(m2, m4, prefix.labels = "v")
axis_title_size <- 22
axis_text_size <- 18
legend_text_size <- 18
axis_title_space <- 28
p1 <- ggemmeans(m4, c("Dauer_z", "kkh_r")) %>%
plot() +
labs(colour = NULL, y = NULL, title = NULL, x = "Aufenthaltsdauer") +
scale_x_continuous(
breaks = c(-1.3, -.25, .8, 1.85, 2.9),
labels = c("1 Tag", "7 Tage", "14 Tage", "21 Tage", "28 Tage")
) +
theme_lucid(
axis.title.size = axis_title_size,
axis.text.size = axis_text_size,
legend.text.size = legend_text_size,
legend.position = "bottom",
axis.title.space = axis_title_space
) +
theme(
legend.spacing.x = unit(.5, "cm")
)
ggsave("Figure 2a.tiff", plot = p1, width = 6, height = 4, units = "in", dpi = 300, compression = "lzw", scale = 2)
p2 <- ggemmeans(m4, c("barthtot_a_z", "kkh_r")) %>%
plot() +
labs(colour = NULL, y = NULL, title = NULL, x = "Barthel-Index") +
scale_x_continuous(
breaks = c(-1.1, -.44, .22, .88, 1.54, 2.2),
labels = c("niedrig", "20", "40", "60", "80", "hoch")
) +
theme_lucid(
axis.title.size = axis_title_size,
axis.text.size = axis_text_size,
legend.text.size = legend_text_size,
legend.position = "bottom",
axis.title.space = axis_title_space
) +
theme(
legend.spacing.x = unit(.5, "cm")
)
ggsave("Figure 2b.tiff", plot = p2, width = 6, height = 4, units = "in", dpi = 300, compression = "lzw", scale = 2)
p3 <- ggemmeans(m4, c("pas_score_z", "kkh_r")) %>%
plot() +
labs(colour = NULL, y = NULL, title = NULL) +
scale_x_continuous(breaks = c(-1, .25, 1.5, 2.75, 4), labels = c("niedrig", "4", "8", "12", "hoch")) +
theme_lucid(
axis.title.size = axis_title_size,
axis.text.size = axis_text_size,
legend.text.size = legend_text_size,
legend.position = "bottom",
axis.title.space = axis_title_space
) +
theme(
legend.spacing.x = unit(.5, "cm")
)
ggsave("Figure 2c.tiff", plot = p3, width = 6, height = 4, units = "in", dpi = 300, compression = "lzw", scale = 2)
emmeans(m4, c("pas_score_z", "kkh_r"), at = list(pas_score_z = c(-1, 0, 4))) %>%
contrast(method = "pairwise")
emmeans(m4, c("barthtot_a_z", "kkh_r"), at = list(barthtot_a_z = c(-1, 0, 2))) %>%
contrast(method = "pairwise")
emmeans(m4, c("Dauer_z", "kkh_r"), at = list(Dauer_z = c(-1, 0, 1))) %>%
contrast(method = "pairwise")