-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlot.R
492 lines (411 loc) · 20 KB
/
Plot.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
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
# ------------------------------------------------------------------------------
#
# Simulation Multigroup Analysis using PLS-PM
#
# (c) Michael Klesel, Florian Schuberth, Bjoern Niehaves, Joerg Henseler
#
# Klesel, M., Schuberth, F., Henseler, J., and Niehaves, B. (forthcoming)
# “Multigroup Analysis in Information Systems Research using PLS-PM:
# A Systematic Investigation of Approaches,“ The DATA BASE for
# Advances in Information Systems
#
# ------------------------------------------------------------------------------
# Prepare workspace ------------------------------------------------------------
rm(list = ls())
options(scipen=999)
graphics.off()
# Libraries --------------------------------------------------------------------
library("tidyverse")
library("scales")
library("svglite")
library("renv")
# renv::init()
# serialize current state
# renv::snapshot()
# Restore from renv
# renv::restore()
# User functions ---------------------------------------------------------------
# Add Confidence Intervals
addCI <- function(data, runs, colum, all){
# Add Confidence Intervals
data <- data %>% mutate_at(colum,
.f = list(lowerBound = ~ .-sqrt(.*(1-.)/runs*qnorm(0.975)),
upperBound = ~ .+sqrt(.*(1-.)/runs*qnorm(0.975))))
return(data)
}
# http://jfly.iam.u-tokyo.ac.jp/color
# cbbPalette <- c("#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
myBlack <- "#000000"
myOrange <- "#E69F00"
myBlue <- "#0072B2"
myGreen <- "#009E73"
data.plot <- readRDS("data/Results.rds")
# -----------------------------------------------------------------------------
# SINGLE PATH
# -----------------------------------------------------------------------------
# Type I Error -----------------------------------------------------------------
data.plot1 <- data.plot %>%
filter(differences == "none", # homogenous groups only
normalData == F, # non-normal distributed data only
correction == "holm" | is.na(correction) | # use holm for multiple groups
(test == "NBT" & correction == "none"), # Include Henseler
type_ci == "CI_bca" | is.na(type_ci), # bca
what == "path", # path only
(is.na(distance) | distance == "dG"), # distance
ssizediff == "moderately unequal") # moderately unequal sample sizes
# Long Format
data.plot1 <- data.plot1 %>%
pivot_longer(cols = c(`1%_perCentage`,`5%_perCentage`,`10%_perCentage`),
values_to = "RR", names_to = "alpha") %>%
mutate(alpha = factor(alpha,
levels = c("10%_perCentage",
"5%_perCentage",
"1%_perCentage"))) %>%
mutate(alpha = forcats::fct_recode(alpha,
`10%` = "10%_perCentage",
`5%` = "5%_perCentage",
`1%` = "1%_perCentage")) %>%
addCI(data = ., runs = data.plot1$runs[1], colum = "RR") %>%
filter(alpha == "5%")
p1 <- ggplot(data.plot1 , aes(y = RR, x = ssize,
group = test)) +
facet_grid(cols = vars(test), rows = vars(groups))+
geom_point()+
geom_line() +
geom_hline(yintercept=c(0.05), linetype="dashed", color = "black") +
geom_line(aes(y=upperBound), linetype='dotted')+
geom_line(aes(y=lowerBound), linetype='dotted')+
geom_ribbon(aes(ymin = lowerBound, ymax = upperBound), alpha = 0.15)+
scale_y_continuous(name="Rejection rates",
limits=c(0, 1),
breaks=seq(0,1,.2),
labels = scales::percent) +
scale_x_discrete(name = "Total sample size") +
theme_bw(base_size = 14) +
theme(legend.position="bottom")
p1
# Figure 2
ggsave(p1, device = "svg", filename = "images/Figure02.svg", width = 30, height = 16)
# Power
data.plot2 <- data.plot %>%
filter(differences != "none", # homogenous groups only
normalData == F, # non-normal distributed data only
correction == "holm" | is.na(correction) | # use holm for multiple groups
(test == "NBT" & correction == "none"), # Include Henseler
type_ci == "CI_bca" | is.na(type_ci), # bca # path only
what == "path",
(is.na(distance) | distance == "dG"),
ssizediff == "moderately unequal")
data.plot2 <- data.plot2 %>%
pivot_longer(cols = c(`1%_perCentage`,`5%_perCentage`,`10%_perCentage`),
values_to = "RR", names_to = "alpha") %>%
rename("Parameter difference" = differences) %>%
filter(alpha == "5%_perCentage")
p2 <- ggplot(data.plot2 , aes(y = RR, x = ssize,
group = interaction(groups, `Parameter difference`),
color = `Parameter difference`)) +
facet_grid(cols = vars(test), rows = vars(groups))+
geom_point(aes(shape = `Parameter difference`, color = `Parameter difference`))+
# Define shapes
scale_shape_manual(values=c(0, 8, 10, 17))+
# Define colors
scale_color_manual(values=c(myOrange,myGreen,myBlue, myBlack))+
geom_line()+
# geom_line(aes(linetype = differences)) +
# Define line-types
# https://stackoverflow.com/questions/52885265/change-line-width-in-ggplot-not-size
# Define different linetypes
# The first numeral is units of dash length,
# the second units in the gap in hexadecimal.
# scale_linetype_manual(values=c("81", "82","83","84"))+
geom_hline(yintercept=c(0.8), linetype="dotted", color = "black") +
scale_y_continuous(name="Rejection rates",
limits=c(0, 1),
breaks=seq(0,1,.2),
labels = scales::percent) +
scale_x_discrete(name = "Total sample size") +
theme_bw(base_size = 14) +
theme(legend.position="bottom")
p2
# Figure 3
ggsave(p2, device = "svg", filename = "images/Figure03.svg", width = 18, height = 10)
# BW
p2 <- ggplot(data.plot2 , aes(y = RR, x = ssize,
group = interaction(groups, `Parameter difference`))) +
facet_grid(cols = vars(test), rows = vars(groups))+
geom_point(aes(shape = `Parameter difference`))+
# Define shapes
scale_shape_manual(values=c(0, 8, 10, 17))+
geom_line()+
geom_hline(yintercept=c(0.8), linetype="dotted", color = "black") +
scale_y_continuous(name="Rejection rates",
limits=c(0, 1),
breaks=seq(0,1,.2),
labels = scales::percent) +
scale_x_discrete(name = "Total sample size") +
theme_bw(base_size = 14) +
theme(legend.position="bottom")
p2
ggsave(p2, device = "svg", filename = "images/Figure03SW.svg", width = 18, height = 10)
# -----------------------------------------------------------------------------
# COMPLETE MODEL
# -----------------------------------------------------------------------------
# Type I Error -----------------------------------------------------------------
data.plot3 <- data.plot %>%
filter(differences == "none", # homogenous groups only
# test != "OTG", # exclude OTG
test != "NBT", # exclude NBT
normalData == F, # non-normal distributed data only
correction == "holm" | is.na(correction), # use holm for multiple groups
type_ci == "CI_bca" | is.na(type_ci), # bca
what == "complete", # path only
(is.na(distance) | distance == "dG"), # distance
ssizediff == "moderately unequal") # moderately unequal sample sizes
# Long Format
data.plot3 <- data.plot3 %>%
pivot_longer(cols = c(`1%_perCentage`,`5%_perCentage`,`10%_perCentage`),
values_to = "RR", names_to = "alpha") %>%
mutate(alpha = factor(alpha,
levels = c("10%_perCentage",
"5%_perCentage",
"1%_perCentage"))) %>%
mutate(alpha = forcats::fct_recode(alpha,
`10%` = "10%_perCentage",
`5%` = "5%_perCentage",
`1%` = "1%_perCentage")) %>%
addCI(data = ., runs = data.plot3$runs[1], colum = "RR") %>%
filter(alpha == "5%")
p3 <- ggplot(data.plot3 , aes(y = RR, x = ssize, group = test)) +
facet_grid(cols = vars(test), rows = vars(groups))+
geom_point()+
geom_line() +
geom_hline(yintercept=c(0.05), linetype="dashed", color = "black") +
geom_line(aes(y=upperBound), linetype='dotted')+
geom_line(aes(y=lowerBound), linetype='dotted')+
geom_ribbon(aes(ymin = lowerBound, ymax = upperBound), alpha = 0.15)+
scale_y_continuous(name="Rejection rates",
limits=c(0, 1),
breaks=seq(0,1,.2),
labels = scales::percent) +
scale_x_discrete(name = "Total sample size") +
theme_bw(base_size = 18) +
theme(legend.position="bottom")
p3
# Figure 4
ggsave(p3, device = "svg", filename = "images/Figure04.svg", width = 14, height = 10)
# Power
data.plot4 <- data.plot %>%
filter(differences != "none", # homogenous groups only
# test != "OTG", # exclude OTG
test != "NBT", # exclude NBT
normalData == F, # non-normal distributed data only
correction == "holm" | is.na(correction), # use holm for multiple groups
type_ci == "CI_bca" | is.na(type_ci), # bca
distance == "dG" | is.na(distance), # use geodesic distance only
what == "complete",
ssizediff == "moderately unequal") # severe path differenc
data.plot4 <- data.plot4 %>%
pivot_longer(cols = c(`1%_perCentage`,`5%_perCentage`,`10%_perCentage`),
values_to = "RR", names_to = "alpha") %>%
filter(alpha == "5%_perCentage")
data.plot4 <- data.plot4 %>% rename("Structural model difference" = differences)
p4 <- ggplot(data.plot4 , aes(y = RR, x = ssize,
group = interaction(groups, `Structural model difference`),
color = `Structural model difference`)) +
facet_grid(cols = vars(test), rows = vars(groups))+
geom_point(aes(shape = `Structural model difference`, color = `Structural model difference`))+
# Define shapes
scale_shape_manual(values=c(0, 8, 10, 17))+
geom_line()+
geom_hline(yintercept=c(0.8), linetype="dotted", color = "black") +
scale_y_continuous(name="Rejection rates",
limits=c(0, 1),
breaks=seq(0,1,.2),
labels = scales::percent) +
scale_x_discrete(name = "Total sample size") +
theme_bw(base_size = 18) +
theme(legend.position="bottom")
p4
# Figure 6 BW
ggsave(p4, device = "svg", filename = "images/Figure06.svg", width = 18, height = 10)
p4 <- ggplot(data.plot4 , aes(y = RR, x = ssize,
group = interaction(groups, `Structural model difference`))) +
facet_grid(cols = vars(test), rows = vars(groups))+
geom_point(aes(shape = `Structural model difference`))+
# Define shapes
scale_shape_manual(values=c(0, 8, 10, 17))+
geom_line()+
geom_hline(yintercept=c(0.8), linetype="dotted", color = "black") +
scale_y_continuous(name="Rejection rates",
limits=c(0, 1),
breaks=seq(0,1,.2),
labels = scales::percent) +
scale_x_discrete(name = "Total sample size") +
theme_bw(base_size = 18) +
theme(legend.position="bottom")
p4
# Figure 6
ggsave(p4, device = "svg", filename = "images/Figure06BW.svg", width = 18, height = 10)
# -----------------------------------------------------------------------------
# MULTIPLE COMPARISON ISSUE
# -----------------------------------------------------------------------------
data.plot5 <- data.plot %>%
filter(differences == "none" | differences == "medium-large",
test == "PTE" | test == "PTU" | test == "NPT",
normalData == F, # non-normal distributed data only
correction != "fdr" & correction != "BY",
# correction == "none" | correction == "bonferroni" |
# correction == "hochberg" | correction == "holm" correction == "BH",
comparison == "overall", # overall comparision only
ssizediff == "moderately unequal",
groups == "3 groups")
data.plot5 <- data.plot5 %>%
mutate(correction = case_when(
correction == "none" ~ "none",
correction == "bonferroni" ~ "Bonferroni",
correction == "holm" ~ "Holm",
correction == "hommel" ~ "Hommel",
correction == "hochberg" ~ "Hochberg",
correction == "BH" ~ "Benjamini & Hochberg",
TRUE ~ "ERROR"
)) %>% dplyr::rename(., c("Adjustment" = "correction"))
data.plot5$differences <- plyr::revalue(data.plot5$differences, c(none = "No group difference"))
data.plot5$differences <- plyr::revalue(data.plot5$differences, c("medium-large" = "Medium-large difference"))
data.plot5.test <- data.plot5 %>%
pivot_wider(names_from = Adjustment, values_from = `5%_perCentage`)
# fit <- aov(as.numeric(data.plot5$`5%_perCentage`) ~ as.factor(data.plot5$Adjustment))
# TukeyHSD(fit)
p5 <- ggplot(data.plot5 , aes(y = `5%_perCentage`, x = ssize,
group = interaction(differences, Adjustment),
shape = Adjustment)) +
facet_grid(cols = vars(test), rows = vars(differences))+
geom_point(aes(shape = Adjustment, color = Adjustment))+
geom_line()+
geom_hline(yintercept=c(0.05), linetype="dotted", color = "black") +
scale_y_continuous(name="Rejection rates",
limits=c(0, 1),
breaks=seq(0,1,.2),
labels = scales::percent) +
scale_x_discrete(name = "Total sample size") +
theme_bw(base_size = 18) +
theme(legend.position="bottom")
p5
# Image 7
ggsave(p5, device = "svg", filename = "images/Figure07.svg", width = 10, height = 7)
# -----------------------------------------------------------------------------
# NON-NORMAL DATA, DATA DISTRIBUTION
# -----------------------------------------------------------------------------
data.plot6 <- data.plot %>%
filter(differences == "small-medium",
test == "PTE" | test == "PTU" | test == "NPT" | test == "NDT",
# normalData == F, # non-normal distributed data only
correction == "holm" | is.na(correction),
distance == "dG" | is.na(distance),
comparison == "overall", # overall comparision only
what == "complete",
ssizediff != "moderately unequal",
groups == "3 groups")
# rename cols
data.plot6 <- data.plot6 %>% dplyr::rename(., c("Sample size distribution" = "ssizediff",
"Data distribution" = "normalData" ))
# change values
data.plot6$`Data distribution` <- recode_factor(data.plot6$`Data distribution`,
"FALSE" = "non-normal",
"TRUE" = "normal")
p6 <- ggplot(data.plot6 , aes(y = `5%_perCentage`, x = ssize,
group = interaction(`Data distribution`, `Sample size distribution`),
linetype = `Data distribution`,
color = `Sample size distribution`)) +
facet_grid(cols = vars(test), rows = vars(differences))+
geom_point(aes(shape = `Sample size distribution`))+
geom_line()+
scale_color_manual(values=c(myOrange,myBlue))+
geom_hline(yintercept=c(0.8), linetype="dotted", color = "black") +
scale_y_continuous(name="Rejection rates",
limits=c(0, 1),
breaks=seq(0,1,.1),
labels = scales::percent) +
scale_x_discrete(name = "Total sample size") +
theme_bw(base_size = 18) +
theme(legend.position="bottom")
p6
# Figure 8
ggsave(p6, device = "svg", filename = "images/Figure08.svg", width = 12, height = 8)
# BW
p6 <- ggplot(data.plot6 , aes(y = `5%_perCentage`, x = ssize,
group = interaction(`Data distribution`, `Sample size distribution`),
linetype = `Data distribution`)) +
facet_grid(cols = vars(test), rows = vars(differences))+
geom_point(aes(shape = `Sample size distribution`))+
geom_line()+
geom_hline(yintercept=c(0.8), linetype="dotted", color = "black") +
scale_y_continuous(name="Rejection rates",
limits=c(0, 1),
breaks=seq(0,1,.1),
labels = scales::percent) +
scale_x_discrete(name = "Total sample size") +
theme_bw(base_size = 18) +
theme(legend.position="bottom")
p6
# Figure 8
ggsave(p6, device = "svg", filename = "images/Figure08BW.svg", width = 12, height = 8)
# -----------------------------------------------------------------------------
# Confidence Intervals - NOT PUBLISHED
# -----------------------------------------------------------------------------
data.plot7 <- data.plot %>%
filter(
normalData == F,
!is.na(type_ci),
comparison == "Eta3 ~ Eta1",
ssizediff == "moderately unequal",
groups == "2 groups")
p7 <- ggplot(data.plot7 , aes(y = `5%_perCentage`, x = ssize,
group = type_ci, color = type_ci)) +
facet_grid(cols = vars(test), rows = vars(differences))+
geom_point()+
geom_line()+
geom_hline(yintercept=c(0.8), linetype="dotted", color = "black") +
scale_y_continuous(name="Rejection rates",
limits=c(0, 1),
breaks=seq(0,1,.1),
labels = scales::percent) +
scale_x_discrete(name = "Total sample size") +
theme_bw(base_size = 14) +
theme(legend.position="bottom")
p7
# -----------------------------------------------------------------------------
# 5000 BS runs
# -----------------------------------------------------------------------------
# 5000 Permutations ------------------------------------------------------------
data.5000 <- readRDS("data/ResultsWith5000BS.rds")
# Type I Error -----------------------------------------------------------------
data.plot8 <- data.5000 %>%
filter(differences == "none", # homogenous groups only
test == "NPT", # exclude NPT
normalData == F, # non-normal distributed data only
correction == "holm" | is.na(correction), # use holm for multiple groups
type_ci == "CI_bca" | is.na(type_ci), # bca
distance == "dG" | is.na(distance), # use geodesic distance only
comparison == "overall", # overall comparision only
ssizediff == "moderately unequal ") # severe path difference
data.plot8 <- data.plot8 %>% rename("RR" = `5%_perCentage`)
# Add CI
data.plot8 <- data.plot8 %>% addCI(data = ., runs = data.plot8$runs[1], colum = "RR")
p8 <- ggplot(data.plot8 , aes(y = RR, x = ssize, group = test)) +
facet_grid(cols = vars(perm))+
geom_point()+
geom_line() +
geom_hline(yintercept=c(0.05), linetype="dashed", color = "black") +
geom_line(aes(y=upperBound), linetype='dotted')+
geom_line(aes(y=lowerBound), linetype='dotted')+
geom_ribbon(aes(ymin = lowerBound, ymax = upperBound), alpha = 0.15)+
scale_y_continuous(name="Rejection rates",
limits=c(0, .2),
breaks=seq(0,1,.05),
labels = scales::percent) +
scale_x_discrete(name = "Total sample size") +
theme_bw(base_size = 24) +
theme(legend.position="bottom")
p8
# Figure 5
ggsave(p8, device = "svg", filename = "images/Figure05.svg", width = 14, height = 10)