diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6a065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata diff --git a/npRCT.Rproj b/npRCT.Rproj new file mode 100644 index 0000000..0228485 --- /dev/null +++ b/npRCT.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 6 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX diff --git a/server.R b/server.R new file mode 100644 index 0000000..9ba732f --- /dev/null +++ b/server.R @@ -0,0 +1,77 @@ +# -------------------------------------------------------- +# -----------------Server--------------------------------- +# -------------------------------------------------------- + + +## Load Packages +library("shiny") +library("semantic.dashboard") +library("pwr") + + +server <- function(input, output) { + + + # ---------------General npRCT function------------- + + npRCT <- reactive({ + + # Run power calculation for first t-test (traditional part of RCST) + t1 <- pwr.t.test(d = input$d1, + sig.level = input$sig.level1, + power = input$power1, + alternative = input$alternative1, + type = "two.sample") + + # Run power calculation for second t-test (stratified part of RCST) + t2 <- pwr.t.test(d = input$d2, sig.level = input$sig.level2, power = input$power2, + type = "two.sample", + alternative = input$alternative2) + + # Compute sample sizes (per group) + n1 = ceiling(t1$n) + n2 = t2$n + n2_rct = ceiling(n2 / 2) # n still traditionally randomised in stratified part + + # Compute output + n_strat = n1 - n2_rct + n_total = n_strat + n2 + n_saved = (n1 + n2) - n_total + n_ind = n1 + n2 + + # Save output + npRCT <- data.frame(n_total = round(n_total), + n_strat = n_strat, + n_saved = n_saved, + n_ind = n_ind) + + # Return output + npRCT + + }) + + + # ---------------Define output as text-------------- + + output$n_total <- renderText({ + + temp <- npRCT() + as.character(temp$n_total) + + }) + + output$n_strat <- renderText({ + + temp <- npRCT() + as.character(temp$n_strat) + + }) + + output$n_saved <- renderText({ + + temp <- npRCT() + as.character(temp$n_saved) + + }) + +} \ No newline at end of file diff --git a/ui.R b/ui.R new file mode 100644 index 0000000..bb8aa26 --- /dev/null +++ b/ui.R @@ -0,0 +1,118 @@ +# -------------------------------------------------------- +# -----------------User Interface------------------------- +# -------------------------------------------------------- + +## Load Packages +library("shiny") +library("semantic.dashboard") + + +ui <- dashboardPage( + dashboardHeader(title = "nested-precision Randomised Controlled Trial (npRCT) + Power Calculation"), + + dashboardSidebar( + side = "left", + color = "blue", + size = "thin", + helpText("This is a help text."), + + + ), + + + # ----------------dashboardBody--------------------- + dashboardBody( + fluidRow( + + + + # ----------Power Analysis Output--------- + box( + title = "Power Analysis", + color = "blue", + + h1("npRCT"), + p("Below you can find results from power analysis for the", strong("nested-precision Randomised Controlled Trial (npRCT)"),". You can set parameters for power analysis in the box to the right. Results from power analysis will change accordingly below."), + box(title = "Results", + h3("Total Sample Size"), + textOutput("n_total"), + + h3("Point of Stratification"), + textOutput("n_strat"), + + h3("Saved Sample Size"), + textOutput("n_saved") + ) + ), + + + # ----------Set RCT Parameters------------ + box( + title = "Set Parameters", + color = "blue", + + + # ----------Traditional RCT Parameters------------ + h3("Traditional RCT"), + sliderInput("d1", + "Effect Size", + step = 0.01, + min = 0, + max = 1, + value = 0.5), + br(), + sliderInput("power1", + "Power", + step = 0.01, + min = 0.5, + max = 1, + value = 0.8), + br(), + sliderInput("sig.level1", + "Significance Level", + step = 0.001, + min = 0.001, + max = 0.1, + value = 0.05), + br(), + radioButtons("alternative1", + NULL, + c("Two Sided Test"= "two.sided", + "One Sided Test"= "greater"), + selected = "two.sided"), + + + # ----------Precision RCT Parameters------------ + h3("Precision RCT"), + sliderInput("d2", + "Effect Size", + step = 0.01, + min = 0, + max = 1, + value = 0.5), + br(), + sliderInput("power2", + "Power", + step = 0.01, + min = 0.5, + max = 1, + value = 0.8), + br(), + sliderInput("sig.level2", + "Significance Level", + step = 0.001, + min = 0.001, + max = 0.1, + value = 0.05), + br(), + radioButtons("alternative2", + NULL, + c("Two Sided Test"= "two.sided", + "One Sided Test"= "greater"), + selected = "two.sided") + + ) + ) + ) +)