@@ -17,16 +17,17 @@ shinyServer(function(input, output, session) {
17
17
save_dv_observers = list (), # list of observer objects dynamically produced when displaying table
18
18
counter = 0 ,
19
19
chosen = ' ' ,
20
- control_for_gender = F ,
21
- control_for_interaction = F ,
20
+ DV_selector_sg.chosen = DV_ALL ,
21
+ control_for_gender = FALSE ,
22
+ control_for_interaction = FALSE ,
22
23
next_seed = sample(1 : 5000 ,1 ,replace = TRUE ),
23
24
current_seed = NULL ,
24
25
dv_names = c(),
25
26
dv_names_all = c(),
26
27
TEST = NULL ,
27
28
blub = 0 ,
28
- flag_auto_selected = F ,
29
- flag_point_already_excluded = F
29
+ flag_auto_selected = FALSE ,
30
+ flag_point_already_excluded = FALSE
30
31
)
31
32
32
33
@@ -138,12 +139,15 @@ shinyServer(function(input, output, session) {
138
139
})
139
140
140
141
141
- # dv chosen
142
+ # dvs chosen
142
143
observeEvent(input $ DV_selector , {
143
- # Print(paste0("DV selector chosen option: ", input$DV_selector))
144
144
dat $ chosen <- input $ DV_selector
145
145
})
146
146
147
+ observeEvent(input $ DV_selector_sg , {
148
+ dat $ DV_selector_sg.chosen <- input $ DV_selector_sg
149
+ })
150
+
147
151
# clear stack pressed
148
152
observeEvent(input $ clear_stack , {
149
153
dat $ n_studies <- 0
@@ -234,7 +238,7 @@ shinyServer(function(input, output, session) {
234
238
dat $ allData $ group <- factor (rep_len(c(input $ label_group1 , input $ label_group2 ), n ))
235
239
236
240
# add column with randomized ages
237
- dat $ allData $ age <- round(rgamma(n , 4 , 0.5 ) + 18 )
241
+ dat $ allData $ age <- round(rgamma(n , 5 , 0.5 ) + 18 )
238
242
239
243
# add column with randomized genders
240
244
dat $ allData $ gender <- factor (sample(0 : 1 , n , replace = TRUE ), labels = c(" male" , " female" ))
@@ -380,7 +384,9 @@ shinyServer(function(input, output, session) {
380
384
381
385
382
386
383
- # render plot overview
387
+ # ---------------------------------------------------------------------
388
+ # render plot overview
389
+
384
390
output $ plotoverview <- renderUI({
385
391
if (is.null(dat $ chosen ) || dat $ counter < 1 ) {
386
392
return ()
@@ -412,15 +418,17 @@ shinyServer(function(input, output, session) {
412
418
})
413
419
414
420
415
- # render main plot
421
+ # ---------------------------------------------------------------------
422
+ # render main plot
423
+
416
424
output $ mainplot <- renderPlot({
417
425
418
426
# react on changes in dat$TEST[[1]], dat$currentData, dat$chosen
419
427
420
428
if (is.null(dat $ TEST ) || is.null(dat $ selected ) || is.null(dat $ chosen ) || nrow(dat $ selected ) == 0 ) return ()
421
429
422
430
isolate({
423
- # TODO: Interaction plot when interaction with gender is chosen
431
+
424
432
p_overview <- NULL
425
433
dv <- dat $ chosen
426
434
@@ -448,7 +456,7 @@ shinyServer(function(input, output, session) {
448
456
449
457
p_overview <- ggplot(dat $ allData [1 : dat $ n ,], aes_string(x = " group" , y = dv )) +
450
458
stat_boxplot(geom = ' errorbar' , data = includedData , color = " grey" , width = 0.5 ) + # draw vertical lines at lower and upper end
451
- geom_boxplot(data = includedData , fill = " grey" , colour = " grey" , alpha = 0.25 ) + # draw boxplot
459
+ geom_boxplot(data = includedData , fill = " grey" , colour = " grey" , alpha = 0.25 , outlier.color = " red " ) + # draw boxplot
452
460
geom_point(data = includedData , shape = 16 , size = 4 , fill = NA ) + # show data points
453
461
geom_point(data = excludedData , shape = 21 , size = 4 , fill = NA , colour = " black" , alpha = 0.5 ) + # show excluded points
454
462
theme_bw()
@@ -469,7 +477,10 @@ shinyServer(function(input, output, session) {
469
477
}
470
478
})
471
479
472
- # render study stack panel
480
+
481
+ # ---------------------------------------------------------------------
482
+ # render study stack panel
483
+
473
484
output $ studystack <- renderUI({
474
485
pchecker_link <- paste0(" http://shinyapps.org/apps/p-checker/?syntax=" , URLencode(dat $ studystack , reserved = TRUE ))
475
486
@@ -522,4 +533,53 @@ shinyServer(function(input, output, session) {
522
533
div(class = " alert alert-danger" ,role = " alert" ,dat $ last_error_msg )
523
534
})
524
535
536
+
537
+ # ---------------------------------------------------------------------
538
+ # Subgroup analysis
539
+
540
+ output $ subgroupOutput <- renderUI({
541
+
542
+ if (nrow(dat $ allData ) == 0 ) return ()
543
+
544
+ # split into 6 groups
545
+ includedData <- getSelectedRows(dat $ allData , dat $ selected , dat $ DV_selector_sg.chosen )
546
+ includedData $ ageGroup <- cut(includedData $ age , breaks = c(0 , median(includedData $ age ), max(includedData $ age )), labels = c(" young" , " old" ))
547
+
548
+ print(includedData )
549
+
550
+ subgroupTests <- data.frame ()
551
+ for (ag in levels(includedData $ ageGroup )) {
552
+ for (g in levels(includedData $ gender )){
553
+ iD2 <- includedData [includedData $ ageGroup == ag & includedData $ gender == g , ]
554
+
555
+ print(iD2 )
556
+
557
+ if (sum(iD2 $ group == input $ label_group1 )> 2 & sum(iD2 $ group == input $ label_group2 )> 2 ) {
558
+
559
+ sg.aov <- aov(formula(paste0(dat $ DV_selector_sg.chosen , " ~ group" )), iD2 )
560
+
561
+ subgroupTests <- rbind(subgroupTests , data.frame (
562
+ agegroup = ag ,
563
+ gender = g ,
564
+ p.value = summary(sg.aov )[[1 ]]$ Pr [1 ]
565
+ ))
566
+ }
567
+ }
568
+ }
569
+
570
+ p1 <- ggplot(includedData , aes_string(x = " group" , y = dat $ DV_selector_sg.chosen )) + geom_point() + facet_grid(gender ~ ageGroup ) + stat_boxplot(geom = ' errorbar' , data = includedData , color = " grey" , width = 0.5 ) + # draw vertical lines at lower and upper end
571
+ geom_boxplot(data = includedData , fill = " grey" , colour = " grey" , alpha = 0.25 , outlier.color = " red" ) + # draw boxplot
572
+ geom_point(data = includedData , shape = 16 , size = 4 , fill = NA ) + # show data points
573
+ theme_bw()
574
+
575
+
576
+ return (list (
577
+ HTML(" PLOT" ),
578
+ selectInput(" DV_selector_sg" , label = " Choose DV for analysis" , c(paste0(DV_PREFIX , 1 : input $ dv_n ), isolate(dat $ DV_selector_sg.chosen ))),
579
+ renderTable(subgroupTests ),
580
+ renderPlot(p1 )
581
+ ))
582
+ })
583
+
584
+
525
585
})
0 commit comments