-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
1297 lines (1007 loc) · 51.3 KB
/
app.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
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
####################################### WELCOME TO THE SHINY APP AdRI_GAMLSS ######################
####################################### from Sandra K. (2023) #####################################
###################################################################################################
####################################### Scripts ###################################################
source("R/analysis.R")
source("R/gamlss.R")
####################################### Libraries #################################################
if("boot" %in% rownames(installed.packages())){
library(boot)} else{
install.packages("boot")
library(boot)}
if("dplyr" %in% rownames(installed.packages())){
library(dplyr)} else{
install.packages("dplyr")
library(dplyr)}
if("DT" %in% rownames(installed.packages())){
library(DT)} else{
install.packages("DT")
library(DT)}
if("gamlss" %in% rownames(installed.packages())){
library(gamlss)} else{
install.packages("gamlss")
library(gamlss)}
if("gamlss.add" %in% rownames(installed.packages())){
library(gamlss.add)} else{
install.packages("gamlss.add")
library(gamlss.add)}
if("plotly" %in% rownames(installed.packages())){
library(plotly)} else{
install.packages("plotly")
library(plotly)}
if("rpart" %in% rownames(installed.packages())){
library(rpart)} else{
install.packages("rpart")
library(rpart)}
if("rpart.plot" %in% rownames(installed.packages())){
library(rpart.plot)} else{
install.packages("rpart.plot")
library(rpart.plot)}
if("shinydashboard" %in% rownames(installed.packages())){
library(shinydashboard)} else{
install.packages("shinydashboard")
library(shinydashboard)}
if("zoo" %in% rownames(installed.packages())){
library(zoo)} else{
install.packages("zoo")
library(zoo)}
####################################### USER INTERFACE ############################################
ui <- dashboardPage(
dashboardHeader(title = "AdRI_GAMLSS", titleWidth = 175),
dashboardSidebar(width = 175,
sidebarMenu(
menuItem("Analysis", tabName = "analysis", icon = icon("database")),
menuItem("GAMLSS", tabName = "gamlss", icon = icon("chart-line"), startExpanded = FALSE,
menuSubItem("GAMLSS and LMS", tabName = "gamlsslms", icon = icon("chart-line")),
menuSubItem("Comparison", tabName = "comparison", icon = icon("balance-scale")),
menuSubItem("Percentiles", tabName = "percentiles", icon = icon("table")))
)),
dashboardBody(
tags$style("html, body {overflow: visible !important;"),
tabItems(
tabItem(tabName = "analysis",
fillPage(fluidRow(
### Sidebar - Analysis ###
box(
title = tagList(shiny::icon("gear"), "Settings"),
width = 3,
solidHeader = TRUE,
status = "primary",
helpText("Data Upload:"),
selectInput("dataset", "Select preinstalled dataset:", choice = list.files(pattern = c(".csv"), recursive = TRUE)),
uiOutput("dataset_file"),
actionButton('reset', 'Reset Input', icon = icon("trash")),
hr(),
helpText("Data Preprocessing:"),
radioButtons(
"days_or_years",
"Unit for the age:",
c("year" = "age", "day" = "age_days")),
conditionalPanel(
condition = "input.days_or_years == 'age'",
sliderInput(
"age_end",
"Select age-range:",
min = 0 ,
max = 100,
value = c(0, 18))),
conditionalPanel(
condition = "input.days_or_years == 'age_days'",
numericInput(
"age_input_min",
"Select age-range from:",
0,
min = 0,
max = 100 * 365)),
conditionalPanel(
condition = "input.days_or_years == 'age_days'",
numericInput("age_input", "to:", 100, min = 1, max = 100 * 365)),
selectInput("sex", "Select the sex:",
choices = list(
"Male + Female" = "t",
"Male" = "m",
"Female" = "f")),
textInput("text_unit", "Unit of the analyte:", value = "Unit"),
checkboxInput("unique", "First unique values", value = TRUE)
),
### MainPanel - Analysis ###
column(
width = 9,
tabsetPanel(
tabPanel("Overview", icon = icon("home"),
p(br(), strong("Shiny App for calculating age-dependent Reference Intervals!"), br(), br(),
"This Shiny App was developed to create age-dependent Reference Intervals using
Generalized Additive Models for Location, Scale and Shape (GAMLSS).", br(),
"For further information visit our", a("Wiki", href = "https://github.com/SandraKla/AdRI_GAMLSS/wiki"),"!"),
plotlyOutput("scatterplot_plotly", height ="700px")
),
tabPanel("Dataset", icon = icon("table"),
p(br(), strong("Shiny App for calculating age-dependent Reference Intervals!"), br(), br(),
"This Shiny App was developed to create age-dependent Reference Intervals using
Generalized Additive Models for Location, Scale and Shape (GAMLSS).", br(),
"For further information visit our", a("Wiki", href = "https://github.com/SandraKla/AdRI_GAMLSS/wiki"),"!"),
DT::dataTableOutput("datatable")),
tabPanel("Barplots", icon = icon("chart-bar"),
p(br(), strong("Shiny App for calculating age-dependent Reference Intervals!"), br(), br(),
"This Shiny App was developed to create age-dependent Reference Intervals using
Generalized Additive Models for Location, Scale and Shape (GAMLSS).", br(),
"For further information visit our", a("Wiki", href = "https://github.com/SandraKla/AdRI_GAMLSS/wiki"),"!"),
plotOutput("barplot_sex", height = "375px"),
plotOutput("barplot_value", height = "375px")),
tabPanel("Statistics", icon = icon("calculator"),
p(br(), strong("Shiny App for calculating age-dependent Reference Intervals!"), br(), br(),
"This Shiny App was developed to create age-dependent Reference Intervals using
Generalized Additive Models for Location, Scale and Shape (GAMLSS).", br(),
"For further information visit our", a("Wiki", href = "https://github.com/SandraKla/AdRI_GAMLSS/wiki"),"!"),
plotOutput("qqplot", height = "375px"),
plotOutput("lognorm", height = "375px"))
)
)
))),
tabItem(tabName = "gamlsslms",
fillPage(fluidRow(
### Sidebar - GAMLSS ###
box(
title = tagList(shiny::icon("gear"), "Settings"),
width = 3,
solidHeader = TRUE,
status = "primary",
actionButton("button_lms", "Start LMS", icon("calculator"), onclick = "$(tab).removeClass('disabled')"),
htmlOutput("buttons_lms"),
hr(),
selectInput(
"distribtion_gamlss",
"Distribution for GAMLSS:",
choices = list(
"Log-Normal Distribution" = "LOGNO",
"Normal Distribution" = "NO",
"Box-Cox" = c(
#"Box-Cole Green Distribution" = "BCCG",
"Box-Cole Green Distribution (orginal)" = "BCCGo",
#"Box-Cole Green Exp. Distribution" = "BCPE",
"Box-Cole Green Exp. Distribution (orginal)" = "BCPEo",
#"Box-Cole Green T-Distribution" = "BCT",
"Box-Cole Green T-Distribution (orginal)" = "BCTo"
)
)
),
checkboxInput("checkbox", "Distribution proposed by the LMS", value = FALSE),
actionButton("button_gamlss", "Start GAMLSS", icon("calculator"), onclick = "$(tabs).removeClass('disabled')"),
htmlOutput("buttons_gamlss")
),
### MainPanel - GAMLSS ###
column(width = 9,
tabsetPanel(
tabPanel(
"LMS",
icon = icon("chart-line"),
value = "nav_lms",
fluidRow(
box(title = tagList(shiny::icon("chart-line"), "Plot"),
width = 12,
solidHeader = TRUE,
collapsible = TRUE,
status = "primary",
plotOutput("lms", height = "475px")
),
box(title = tagList(shiny::icon("calculator"), "Statistics"),
width = 12,
solidHeader = TRUE,
collapsible = TRUE,
status = "info",
verbatimTextOutput("lms_text"),
plotOutput("lms_plot"),
plotOutput("lms_fitted"),
plotOutput("lms_wormplots"))
)),
tabPanel(
"GAMLSS (Splines)",
icon = icon("chart-line"),
value = "nav_gamlss",
fluidRow(
box(title = tagList(shiny::icon("chart-line"), "Plot"),
width = 12,
solidHeader = TRUE,
collapsible = TRUE,
status = "primary",
plotOutput("gamlss_models_splines", height = "475px")
),
box(title = tagList(shiny::icon("calculator"), "Statistics"),
width = 12,
solidHeader = TRUE,
collapsible = TRUE,
status = "info",
p("GAMLSS with P-Splines:"),
verbatimTextOutput("gamlss_text_psplines"),
plotOutput("gamlss_term_pb"),
plotOutput("gamlss_fitted_pb_"),
p("GAMLSS with Cubic-Splines:"),
verbatimTextOutput("gamlss_text_splines"),
plotOutput("gamlss_term_cs"),
plotOutput("gamlss_fitted_cs_"),
p("Wormplots for GAMLSS with the P-Splines and Cubic Splines:"),
plotOutput("wormplots_splines"))
)),
tabPanel(
"GAMLSS (Polynomials)",
icon = icon("chart-line"),
value = "nav_gamlss",
fluidRow(
box(title = tagList(shiny::icon("chart-line"), "Plot"),
width = 12,
solidHeader = TRUE,
collapsible = TRUE,
status = "primary",
plotOutput("gamlss_models_poly", height ="475px")
),
box(title = tagList(shiny::icon("calculator"), "Statistics"),
width = 12,
solidHeader = TRUE,
collapsible = TRUE,
status = "info",
p("GAMLSS with Polynomial Degree 3:"),
verbatimTextOutput("gamlss_text_poly"),
plotOutput("gamlss_term_poly"),
plotOutput("gamlss_fitted_poly_"),
p("GAMLSS with Polynomial Degree 4:"),
verbatimTextOutput("gamlss_text_poly4"),
plotOutput("gamlss_term_poly4"),
plotOutput("gamlss_fitted_poly4_"),
p("Wormplots for GAMLSS with the Polynomial Degree 3 and 4:"),
plotOutput("wormplots_poly"))
)),
tabPanel(
"GAMLSS (Neural Network)",
icon = icon("brain"),
value = "nav_gamlss",
fluidRow(
box(title = tagList(shiny::icon("chart-line"), "Plot"),
width = 12,
solidHeader = TRUE,
collapsible = TRUE,
status = "primary",
plotOutput("gamlss_net", height = "475px")),
box(title = tagList(shiny::icon("calculator"), "Statistics"),
width = 12,
solidHeader = TRUE,
collapsible = TRUE,
status = "info",
verbatimTextOutput("net_text"),
# Plot neural network with term.plot(nn_)
plotOutput("network_term"),
plotOutput("network_fitted"),
plotOutput("nn_wormplots"))
)),
tabPanel(
"GAMLSS (Decision Tree)",
icon = icon("tree"),
value = "nav_gamlss",
fluidRow(
box(title = tagList(shiny::icon("chart-line"), "Plot"),
width = 12,
solidHeader = TRUE,
collapsible = TRUE,
status = "primary",
plotOutput("gamlss_tree", height = "475px")
),
box(title = tagList(shiny::icon("calculator"), "Statistics"),
width = 12,
solidHeader = TRUE,
collapsible = TRUE,
status = "info",
verbatimTextOutput("tree_text"),
plotOutput("rpart_tree"),
plotOutput("tree_term"),
plotOutput("tree_fitted"),
plotOutput("tr_wormplots"))
)
)
)
), tags$script(src = 'tabs_enabled.js')))),
### GAMLSS - Comparison ###
### GAMLSS - Comparison ###
tabItem(tabName = "comparison",
fluidRow(
box(
title = tagList(shiny::icon("gear"), "Settings"),
width = 3,
solidHeader = TRUE,
status = "primary",
p("Models can be compared visually or with the Akaike Information Criterion (AIC),
Generalized Information Criterion (GAIC), Bayesian Information Criterion (BIC),
or Pseudo R-Squared (R^2). The model with the smallest value for AIC, BIC and GAIC is the best model for the data.
The Pseudo R-Squared (R^2) should be as large as possible for a good model. These values are colored.")
),
box(
title = tagList(shiny::icon("balance-scale"), "Comparison"),
width = 9,
solidHeader = TRUE,
status = "primary",
DT::dataTableOutput("table_compare"),
plotOutput("metrics", height = "475px")
))),
### GAMLSS - Prediction ###
tabItem(tabName = "percentiles",
fluidRow(column(
width = 3,
fluidRow(
box(
title = tagList(shiny::icon("gear"), "Settings"),
width = 12,
solidHeader = TRUE,
status = "primary",
selectInput(
"select_model",
"Select model:",
choices = list(
"Splines" = c("P-Splines" = "pb_ri",
"Cubic Splines" = "cs_ri"),
"LMS" = c(LMS = "lms_ri"),
"Polynomial" = c(
"Polynomial (Degree 3)" = "poly_ri",
"Polynomial (Degree 4)" = "poly4_ri"
),
"Machine Learning" = c("Neural Network" = "nn_ri",
"Decision Tree" = "tr_ri")
)
)
))),
column(width = 9,
box(title = tagList(shiny::icon("chart-line"), "Percentiles"),
width = 12,
solidHeader = TRUE,
collapsible = TRUE,
status = "primary",
plotOutput("gamlss_prediction", height = "475px")),
box(title = tagList(shiny::icon("table"), "Table"),
width = 12,
solidHeader = TRUE,
collapsible = TRUE,
status = "info",
DT::dataTableOutput("gamlss_tables"))
)
))
))
)
####################################### SERVER ####################################################
server <- function(input, output, session) {
options(shiny.sanitize.errors = TRUE)
##################################### Reactive Expressions ######################################
##################################### Reactive Dataset ##########################################
########### Data is subset with the function select_data() with the given age interval ##########
#################################################################################################
values <- reactiveValues(
upload_state = NULL
)
observeEvent(input$dataset_file1, {
values$upload_state <- 'uploaded'
})
observeEvent(input$reset, {
values$upload_state <- 'reset'
})
dataset_input <- reactive({
if (is.null(values$upload_state)) {
return(NULL)
} else if (values$upload_state == 'uploaded') {
return(input$dataset_file1)
} else if (values$upload_state == 'reset') {
return(NULL)
}
})
output$dataset_file <- renderUI({
input$reset ## Create a dependency with the reset button
fileInput('dataset_file1', label = NULL)
})
values_lis <- reactiveValues(
upload_state_lis = NULL
)
data_analyte <- reactive({
progress <- shiny::Progress$new()
progress$set(message = "Load data...", detail = "", value = 2)
cat(paste("*** Welcome to the Shiny App AdRI_GAMLSS! ***\n"))
req(input$dataset, input$age_end)
lms_ready <<- FALSE # To check if the lms method was used
modelsprediction <<- FALSE # To check if the models are build
residuals_ready <<- FALSE # Check if the residuals are calculated
# Read the data (from the CALIPER study or from the generator)
if(is.null(dataset_input())){
data_data <- read.csv2(input$dataset, header = TRUE,
stringsAsFactors = FALSE, sep = ";", dec = ",", na.strings = "")}
if(!is.null(dataset_input()))
{data_data <- read.csv2(dataset_input()[["datapath"]], header = TRUE,
stringsAsFactors = FALSE, sep = ";", dec = ",", na.strings = "")}
################################### Age is given by days ######################################
if(input$days_or_years == "age_days"){
# Preprocessing the data
data_analyte <- select_data_days(data_data, input$age_input_min, input$age_input, input$sex)
################################# First samples #############################################
rows_table_ <- nrow(data_analyte)
# Take only the first and unique samples from the data if ID is given
if(input$unique == TRUE){
data_analyte <-
data_analyte %>%
group_by(patient) %>%
filter(row_number()==1)
# Convert into tibble so as.data.frame()
data_analyte <- as.data.frame(data_analyte)
if(!(rows_table_ == nrow(data_analyte))){
cat(paste("*** Information!", rows_table_ - nrow(data_analyte), "values of the patients were present several times and were deleted. ***\n"))}
}
}
else{
################################# Age in years (default) ####################################
# Preprocessing the data
data_analyte <- select_data(data_data,input$age_end[1] ,input$age_end[2], input$sex)
################################# First samples #############################################
rows_table_ <- nrow(data_analyte)
if(input$unique == TRUE){
data_analyte <-
data_analyte %>%
group_by(patient) %>%
filter(row_number()==1)
# Convert into tibble so as.data.frame()
data_analyte <- as.data.frame(data_analyte)
if(!(rows_table_ == nrow(data_analyte))){
cat(paste("*** Information!", rows_table_ - nrow(data_analyte), "values of the patients were present several times and were deleted. ***\n"))}
}
}
cat("\n")
data_analyte_short <<- data_analyte
on.exit(progress$close())
data_analyte
})
##################################### Build rpart Decision Tree #################################
build_rpart <- reactive({
rpart_ready <- make_rpart(data_analyte(), as.numeric(input$tree_minsplit))
})
##################################### Reactive GAMLSS ###########################################
# make_gamlss() is used with six different smooth additive terms for the GAMLLSS models #########
# with different distributions. #################################################################
build_gamlss_model <- eventReactive(input$button_gamlss, {
req(input$dataset, input$age_end, input$distribtion_gamlss, 50, "RS")
progress <- shiny::Progress$new()
progress$set(message = "Calculate Percentiles with GAMLSS-Models...", detail = "", value = 2)
# Error message
if(input$checkbox == TRUE){
validate(need(lms_ready == TRUE,
"Please make first the LMS-Method to get the proposed distribution!"))
gamlss_model_read <- make_gamlss(data_analyte(), input$age_end[2], lms_$family[1], 100, "RS")}
else{gamlss_model_read <- make_gamlss(data_analyte(), input$age_end[2], input$distribtion_gamlss, 100, "RS")}
# Save global value to check later if the models are already calculated
modelsprediction <<- TRUE
on.exit(progress$close())
})
##################################### Reactive LMS ##############################################
lms_reactive <- eventReactive(input$button_lms, {
progress <- shiny::Progress$new()
progress$set(message = "Calculate Percentiles with LMS...", detail = "", value = 2)
lms_model <- make_lms(data_analyte())
lms_ready <<- TRUE # Value to check if lms is accomplished
on.exit(progress$close())
})
##################################### Overview ##################################################
# Scatterplot from the data_analyte() with plotly
output$scatterplot_plotly <- renderPlotly({
ylab_ <<- paste0(data_analyte()[1,7]," [", input$text_unit,"]")
#if(input$fast == FALSE){
fig <- plot_ly(data_analyte(), x = ~age_days, y = ~value,
text = ~ paste('</br>Patient: ', patient,
'</br>Station: ', code,
'</br>Age [Years]: ', age,
'</br>Age [Days]: ', age_days,
'</br>Value: ', value),
type = "scatter",
symbol = ~sex,
symbols = c('circle', 17),
color = ~sex,
colors = c("indianred", "cornflowerblue"),
mode = "markers",
marker = list(size = 10)) %>%
layout(xaxis = list(title="Age [Days]", titlefont=list(size=20), tickfont = list(size = 15)),
yaxis = list(title=ylab_, titlefont=list(size=20), tickfont = list(size = 15)))
})
# Barplot with the distribution of the sex
output$barplot_sex <- renderPlot({
ylab_ <<- paste0(data_analyte()[1,7]," [", input$text_unit,"]")
if(!(nrow(data_analyte())) == 0){
hist_data_w <- subset(data_analyte(), sex == "F", select = age)
hist_data_m <- subset(data_analyte(), sex == "M", select = age)
hist_w <- hist(hist_data_w$age, breaks=seq(min(data_analyte()[,3])-1,max(data_analyte()[,3]),by=1))$counts
hist_m <- hist(hist_data_m$age, breaks=seq(min(data_analyte()[,3])-1,max(data_analyte()[,3]),by=1))$counts
barplot(rbind(hist_m,hist_w), col = c("cornflowerblue","indianred"),
names.arg=seq(min(data_analyte()[,3]), max(data_analyte()[,3]), by=1), xlab = "AGE_YEARS", las = 1, beside = TRUE, ylab = "Number of data")
abline(h=0)
legend("topright", legend = c(paste0("Men: ", nrow(hist_data_m)), paste0("Female: ", nrow(hist_data_w))), col = c("cornflowerblue","indianred"), pch = c(17, 20))
par(new = TRUE)
boxplot(data_analyte()[,3], horizontal = TRUE, axes = FALSE, col = rgb(0, 0, 0, alpha = 0.15))
}
})
output$barplot_value <- renderPlot({
ylab_ <<- paste0(data_analyte()[1,7]," [", input$text_unit,"]")
if(!(nrow(data_analyte())) == 0){
boxplot(data_analyte()[,5]~interaction(data_analyte()[,2], data_analyte()[,3]), xlab = "Age",
ylab = ylab_, col = c("indianred", "cornflowerblue"), las = 2)
}
})
# QQ-Plot for the complete dataset
output$qqplot <- renderPlot({
if(!(nrow(data_analyte())) == 0){
qqnorm(data_analyte()[,5], pch = 20, col = "grey")
qqline(data_analyte()[,5])
}
})
# Bowley and Lognormfunction
output$lognorm <- renderPlot({
if(!(nrow(data_analyte())) == 0){
try(def.distribution(data_analyte()[,5]))
}
})
# Data-Table
output$datatable <- DT::renderDataTable({
data_table <- data_analyte()
colnames(data_table) <- c("ID", "SEX", "AGE_YEARS", "AGE_DAYS", "VALUE", "STATION", "ANALYTE")
DT::datatable(data_table, extensions = 'Buttons', rownames= FALSE,
options = list(dom = 'Blfrtip', pageLength = 15, buttons = c('copy', 'csv', 'pdf', 'print')),
caption = htmltools::tags$caption(style = 'caption-side: bottom; text-align: center;', 'Table: Overview from Dataset'))
})
################################ LMS #############################################
# LMS-Percentile Plot
output$lms <- renderPlot({
lms_reactive()
centiles(lms_, cent=c(2.5,50,97.5), xlab = "Age [Days]", ylab = ylab_, pch = 20, cex = 1,
col.cent=c("indianred","black","cornflowerblue"), lty.centiles=c(3,1,3),lwd.centiles = 2,
legend = FALSE, col = "lightgrey")
})
# Analysis LMS
output$lms_plot <- renderPlot({
lms_reactive()
plot(lms_, parameters = par(mfrow = c(2,2), mar = par("mar") + c(0,1,0,0), col.axis = "black", col = "grey", col.main = "black",
col.lab = "black", pch = 20, cex = 0.5, cex.lab = 1.5, cex.axis = 1, cex.main = 1.5))
})
# Analysis LMS
output$lms_fitted <- renderPlot({
lms_reactive()
new_lms_data <- data.frame(value_lms = data_analyte()[[5]], age_lms = data_analyte()[[4]])
fittedPlot(lms_ ,x = new_lms_data$age_lms, xlab = "Age [Days]")
})
# Analysis LMS-Text
output$lms_text <- renderPrint({
lms_reactive()
print(lms_)
cat("Power:")
print(lms_$power)
cat("\n")
centiles(lms_, cent=c(2.5,50,97.5), plot=FALSE)
})
# Wormplots LMS
output$lms_wormplots <- renderPlot({
lms_reactive()
try(wp(lms_, ylim.all = 3, col = "cornflowerblue", n.inter= 9))
})
##################################### GAMLSS ####################################################
output$all_gamlss <- renderPlot({
centiles.com(pb_, cs_, poly_, poly4_, nn_, tr_, cent=c(2.5,50,97.5), xlab = "Age [Days]", ylab = ylab_,
legend = TRUE, main = "GAMLSS")
})
output$buttons_gamlss <- renderUI({
build_gamlss_model()
print("*** Your GAMLSS are ready! ***")
})
output$buttons_lms <- renderUI({
lms_reactive()
print("*** Your LMS model is ready! ***")
})
# Centiles Plot with gamlss (P-Splines, Cubic Splines) ######
output$gamlss_models_splines <- renderPlot({
build_gamlss_model()
par(mfrow=c(1,2))
centiles(pb_, main = "GAMLSS with P-Splines", cent=c(2.5,50,97.5), xlab = "Age [Days]",
ylab = ylab_, pch = 20, cex = 1, col.cent=c("indianred","black","cornflowerblue"),
lty.centiles=c(3,1,3), lwd.centiles = 2, legend = FALSE, col = "lightgrey")
centiles(cs_, main = "GAMLSS with Cubic Splines", cent=c(2.5,50,97.5), xlab = "Age [Days]",
ylab = ylab_, pch = 20, cex = 1, col.cent=c("indianred","black","cornflowerblue"),
lty.centiles=c(3,1,3), lwd.centiles = 2, legend = FALSE, col = "lightgrey")
})
# Centiles Plot with gamlss (Polynomials Degree 3 and 4) ######
output$gamlss_models_poly <- renderPlot({
build_gamlss_model()
par(mfrow=c(1,2))
centiles(poly_, main = "GAMLSS with Polynomials (Degree 3)", cent=c(2.5,50,97.5), xlab = "Age [Days]",
ylab = ylab_, pch = 20, cex = 1, col.cent=c("indianred","black","cornflowerblue"),
lty.centiles=c(3,1,3), lwd.centiles = 2, legend = FALSE, col = "lightgrey")
centiles(poly4_, main = "GAMLSS with Polynomials (Degree 4)",cent=c(2.5,50,97.5), xlab = "Age [Days]",
ylab = ylab_, pch = 20, cex = 1, col.cent=c("indianred","black","cornflowerblue"),
lty.centiles=c(3,1,3), lwd.centiles = 2, legend = FALSE, col = "lightgrey")
})
# Plot fitted models for P-Splines
output$gamlss_fitted_pb_ <- renderPlot({
build_gamlss_model()
fittedPlot(pb_, x=data_analyte_short$age_days, xlab = "Age [Days]")
})
# Plot fitted models for Cubic Splines
output$gamlss_fitted_cs_ <- renderPlot({
build_gamlss_model()
fittedPlot(cs_, x=data_analyte_short$age_days, xlab = "Age [Days]")
})
# Plot fitted models for Polynomials Degree 3
output$gamlss_fitted_poly_ <- renderPlot({
build_gamlss_model()
fittedPlot(poly_, x=data_analyte_short$age_days, xlab = "Age [Days]")
})
# Plot fitted models for Polynomials Degree 4
output$gamlss_fitted_poly4_ <- renderPlot({
build_gamlss_model()
fittedPlot(poly4_, x=data_analyte_short$age_days, xlab = "Age [Days]")
})
# GAMLSS - Analysis Text
output$gamlss_text_psplines <- renderPrint({
build_gamlss_model()
suppressWarnings({summary(pb_)})
cat("\n")
centiles(pb_, cent=c(2.5,50,97.5), plot=FALSE)
})
# GAMLSS - Analysis Text
output$gamlss_text_splines <- renderPrint({
build_gamlss_model()
suppressWarnings({summary(cs_)})
cat("\n")
centiles(cs_, cent=c(2.5,50,97.5), plot=FALSE)
})
# GAMLSS - Analysis Text
output$gamlss_text_poly <- renderPrint({
build_gamlss_model()
suppressWarnings({summary(poly_)})
cat("\n")
centiles(poly_,cent=c(2.5,50,97.5), plot=FALSE)
})
# GAMLSS - Analysis Text
output$gamlss_text_poly4 <- renderPrint({
build_gamlss_model()
suppressWarnings({summary(poly4_)})
cat("\n")
centiles(poly4_, cent=c(2.5,50,97.5), plot=FALSE)
})
# Plot the changed terms for P-Splines
output$gamlss_term_pb <- renderPlot({
build_gamlss_model()
try(plot(pb_, parameters = par(mfrow = c(2,2), mar = par("mar")+
c(0,1,0,0), col.axis = "black", col = "grey", col.main = "black",
col.lab = "black", pch = 20, cex = 0.5, cex.lab = 1.5, cex.axis = 1, cex.main = 1.5)))
})
# Plot the changed terms for Cubic Splines
output$gamlss_term_cs <- renderPlot({
build_gamlss_model()
try(plot(cs_, parameters = par(mfrow = c(2,2), mar = par("mar")+
c(0,1,0,0), col.axis = "black", col = "grey", col.main = "black",
col.lab = "black", pch = 20, cex = 0.5, cex.lab = 1.5, cex.axis = 1, cex.main = 1.5)))
})
# Plot the changed terms for Polynomial Degree 3
output$gamlss_term_poly <- renderPlot({
build_gamlss_model()
try(plot(poly_, parameters = par(mfrow = c(2,2), mar = par("mar")+
c(0,1,0,0), col.axis = "black", col = "grey", col.main = "black",
col.lab = "black", pch = 20, cex = 0.5, cex.lab = 1.5, cex.axis = 1, cex.main = 1.5)))
})
# Plot the changed terms for Polynomial Degree 4
output$gamlss_term_poly4 <- renderPlot({
build_gamlss_model()
try(plot(poly4_, parameters = par(mfrow = c(2,2), mar = par("mar")+
c(0,1,0,0), col.axis = "black", col = "grey", col.main = "black",
col.lab = "black", pch = 20, cex = 0.5, cex.lab = 1.5, cex.axis = 1, cex.main = 1.5)))
})
# Wormplots from P-Splines and Cubic Splines
output$wormplots_splines <- renderPlot({
build_gamlss_model()
par(mfrow = c(1,2))
try(wp(pb_, ylim.all = 3, col = "cornflowerblue", n.inter= 9))
try(wp(cs_, ylim.all = 3, col = "cornflowerblue", n.inter= 9))
})
# Wormplots from Polynomials Degree 3 and 4
output$wormplots_ploy <- renderPlot({
build_gamlss_model()
par(mfrow = c(1,2))
try(wp(poly_, ylim.all = 3, col = "cornflowerblue", n.inter= 9))
try(wp(poly4_, ylim.all = 3, col = "cornflowerblue", n.inter= 9))
})
# Neural Network (machine learning) ##############################################
# Centiles Plot with the Neural Network
output$gamlss_net <- renderPlot({
build_gamlss_model()
centiles(nn_, main = "GAMLSS with Neural Network", cent=c(2.5,50,97.5), xlab = "Age [Days]", ylab = ylab_, pch = 20, cex = 1,
col.cent=c("indianred","black","cornflowerblue"), lty.centiles=c(3,1,3), lwd.centiles = 2, legend = FALSE, col = "lightgrey")
})
# Neural Network - Analysis
output$network_term <- renderPlot({
build_gamlss_model()
try(plot(nn_, parameters = par(mfrow = c(2,2), mar = par("mar")+
c(0,1,0,0), col.axis = "black", col = "grey", col.main = "black",
col.lab = "black", pch = 20, cex = 0.5, cex.lab = 1.5, cex.axis = 1, cex.main = 1.5)))
})
# Neural Network - Analysis
output$network_fitted <- renderPlot({
build_gamlss_model()
fittedPlot(nn_, x=data_analyte_short$age_days, xlab = "Age [Days]")
})
# Neural Network - Analysis
output$net_text<- renderPrint({
build_gamlss_model()
suppressWarnings({summary(nn_)})
centiles(nn_,cent=c(2.5,50,97.5), plot=FALSE)
})
#Wormplots from the Neural Network
output$nn_wormplots <- renderPlot({
build_gamlss_model()
try(wp(nn_, ylim.all = 3, col = "cornflowerblue", n.inter= 9))
})
# Decision Tree #################################################################################
# Centiles Plot with the Decision Tree
output$gamlss_tree <- renderPlot({
build_gamlss_model()
centiles(tr_, main = "GAMLSS with Decision Tree", cent=c(2.5,50,97.5), xlab = "Age [Days]", ylab = ylab_, pch = 20, cex = 1,
col.cent=c("indianred","black","cornflowerblue"), lty.centiles=c(3,1,3), lwd.centiles = 2, legend = FALSE, col = "lightgrey")
})
# Decision Tree - Analysis
output$tree_term <- renderPlot({
build_gamlss_model()
try(plot(tr_, parameters = par(mfrow = c(2,2), mar = par("mar")+
c(0,1,0,0), col.axis = "black", col = "grey", col.main = "black",
col.lab = "black", pch = 20, cex = 0.5, cex.lab = 1.5, cex.axis = 1, cex.main = 1.5)))
})
# Decision Tree - Analysis
output$tree_fitted <- renderPlot({
build_gamlss_model()
fittedPlot(nn_, x=data_analyte_short$age_days, xlab = "Age [Days]")
})
# Decision Tree - Analysis
output$tree_text <- renderPrint({
build_gamlss_model()
print(getSmo(tr_))
suppressWarnings({summary(tr_)})
centiles(tr_,cent=c(2.5,50,97.5), plot=FALSE)
})
# Plotted Decision Tree
output$rpart_tree <- renderPlot({
build_gamlss_model()
rpart.plot(getSmo(tr_), roundint=FALSE, box.palette = "RdBu")
})
# Wormplots from Decision Tree
output$tr_wormplots <- renderPlot({
build_gamlss_model()
try(wp(tr_, ylim.all = 3, col = "cornflowerblue", n.inter= 9))
})
# Comparism #####################################################################################
# Comparison Table for all GAMLSS and LMS
output$table_compare <- DT::renderDataTable({