Skip to content

Commit

Permalink
updated npRCT app to include text output for main findings
Browse files Browse the repository at this point in the history
  • Loading branch information
kappelmann committed Nov 28, 2019
1 parent 360a53a commit 4470aec
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
13 changes: 13 additions & 0 deletions npRCT.Rproj
Original file line number Diff line number Diff line change
@@ -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
77 changes: 77 additions & 0 deletions server.R
Original file line number Diff line number Diff line change
@@ -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)

})

}
118 changes: 118 additions & 0 deletions ui.R
Original file line number Diff line number Diff line change
@@ -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")

)
)
)
)

0 comments on commit 4470aec

Please sign in to comment.