From 2262a5126670f842c78d312ea7d8026120141e8a Mon Sep 17 00:00:00 2001 From: nemeth Date: Thu, 21 Jan 2021 18:34:43 +0100 Subject: [PATCH] added lower quartile and updated death rate info --- app.R | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 11 deletions(-) diff --git a/app.R b/app.R index 8c30842..86a41f3 100644 --- a/app.R +++ b/app.R @@ -290,7 +290,7 @@ tags$p(style="text-align:center;margin-bottom:0px;", fluidRow(align="center",selectInput(inputId="variable", - label=HTML('Measure','',as.character(icon("exclamation", class="exclamation")),' Death rates are presented as death rates per 100000 person-years. '), + label=HTML('Measure','',as.character(icon("exclamation", class="exclamation")),' Death rates are displayed on a scale of 100000 person-years. '), choices=c("Deaths, Total" = "DTotal", "Death Rate, Total" = "RTotal", @@ -333,16 +333,17 @@ tags$p(style="text-align:center;margin-bottom:0px;", Expected value of a linear trend fitted over years in the selected period.
Week-specific Lower Quartiles
The reference level for a given week equals to the lower quartile of the available data for that week in the years of the selected period. -
Yearly-average-week Trend
+
Yearly-average-week
The arithmetic mean of the week-specific averages over the period. -
Summer-average-week Trend
+
Summer-average-week
The arithmetic mean of the week-specific averages over the period excluding calendar weeks between 48 and 12. '), choices=c("Week-specific Averages", "Week-specific Trends", "Week-specific Lower Quartiles", - "Yearly-average-week Trend", - "Summer-average-week Trend" + "Yearly Average-week", + "Summer Average-week", + "Yearly Lower-quartile-week" ) ), @@ -848,9 +849,15 @@ server=function(input,output,session){ } - #### lower quartile + #### lower quartile weekly q25data=data[CountryCode %in% input$country & Year %in% c(input$period[1]:input$period[2]), lapply(.SD,quantile,prob=0.25), .SDcols= cols, by = list(CountryCode,Week,Sex)] dataset$q25data=q25data + + #### lower quartile + + q25y=data[CountryCode %in% input$country & Year %in% c(input$period[1]:input$period[2]), lapply(.SD, quantile, prob=0.25), .SDcols = cols, by = list(CountryCode,Sex)] + + #### linear trend expectation @@ -888,7 +895,9 @@ server=function(input,output,session){ q25data2=data[CountryCode %in% input$country2 & Year %in% c(input$period2[1]:input$period2[2]), lapply(.SD,quantile,prob=0.25), .SDcols= cols, by = list(CountryCode,Week,Sex)] dataset$q25data2=q25data2 - + #### lower quartile + + q25y2=data[CountryCode %in% input$country2 & Year %in% c(input$period2[1]:input$period2[2]), lapply(.SD, quantile, prob=0.25), .SDcols = cols, by = list(CountryCode,Sex)] smalldata2=data[CountryCode == input$country2 & Year %in% c(input$period2[1]:input$period2[2]),c("Year",..myvar,"Week","CountryCode","Sex")] linex2=rbindlist(by(smalldata2,smalldata2[,c("Week","Sex","CountryCode")],function(x){ @@ -945,21 +954,57 @@ server=function(input,output,session){ subdata2$ymaxvalue = subdata2[,..myvar] compareline2 = meandata2[CountryCode == input$country2, c("Sex","Week",..myvar)] } - } else if (input$area %in% c("Yearly-average-week Trend","Summer-average-week Trend")){ + } else if (input$area %in% c("Yearly Average-week","Summer Average-week","Yearly Lower-quartile-week")){ - if (input$area == "Yearly-average-week Trend"){ + if (input$area == "Yearly Average-week"){ baseline = expectedlevel[CountryCode==input$country] if (input$extracountry == TRUE){ baseline2 = expectedlevel2[CountryCode==input$country2] } - } else if (input$area == "Summer-average-week Trend") { + } else if (input$area == "Summer Average-week") { baseline = expectedlevelsummer[CountryCode==input$country] if (input$extracountry == TRUE){ baseline2 = expectedlevelsummer2[CountryCode==input$country2] } + } else if (input$area == "Yearly Lower-quartile-week") { + Qf=as.numeric(q25y[CountryCode %in% input$country & Sex == "f", ..myvar]) + Qm=as.numeric(q25y[CountryCode %in% input$country & Sex == "m", ..myvar]) + Qb=as.numeric(q25y[CountryCode %in% input$country & Sex == "b", ..myvar]) + + q25allsel=rbind( + data[CountryCode %in% input$country & Year %in% c(input$period[1]:input$period[2]) & Sex == "m",c("CountryCode", "Year","Week","Sex",..myvar)][which(data[CountryCode %in% input$country & Year %in% c(input$period[1]:input$period[2]) & Sex == "m",..myvar]