samplesize-app/app.R

library(shiny)
library(poweregg)
ui <- fluidPage(

  titlePanel('Deparment of Medicine Sample Size Calculator'),

  selectInput(inputId = 'method_name',
              label = 'Regression Method',
              choices = list(
                'Linear Regression',
                'Logistic Regression',
                'Cox Regression',
                'Poisson Regression')
              ),

  numericInput(inputId = 'beta',
               label = 'Smallest Clinically Meaningful Effect',
               value = 0.8,
               min = 0.01,
               step = 0.02),

  numericInput(inputId = 'var_x',
               label = 'Variance of Covariate',
               value = 1,
               min = 0,
               step = 0.5),

  numericInput(inputId = 'mult_cor',
               label = 'Multiple Correlation',
               value = 0,
               min = 0,
               max = 0.99,
               step = 0.05),

  numericInput(inputId = 'power',
               label = 'Desired Statistical Power',
               value = 0.8,
               min = 0.01,
               max = 0.99,
               step = 0.05),
  numericInput(inputId = 'fpr',
               label = 'Desired False Positive Rate',
               value = 0.05,
               min = 0.01,
               max = 0.1,
               step = 0.01),

  conditionalPanel(
  condition = 'input.method_name=="Linear Regression"',
  numericInput(inputId = 'var_y',
               label = 'Conditional Variance of Outcome',
               value = 1,
               min = 0.01,
               step = 0.5)),

  conditionalPanel(
  condition = 'input.method_name=="Logistic Regression"',
  numericInput(inputId = 'prob',
               label = 'Marginal Variance of Outcome',
               value = 0.5,
               min = 0.01,
               max = 0.99,
               ste = 0.05
               )),

  conditionalPanel(
    condition = 'input.method_name=="Cox Regression"',
    numericInput(inputId = 'prob_uncens',
                 label = 'Probability of Uncensored Observation',
                 value = 0.5,
                 min = 0.01,
                 max = 0.99,
                 step = 0.05
                 )),

  conditionalPanel(
    condition = 'input.method_name=="Poisson Regression"',
    numericInput(inputId = 'disp',
                 label = 'Dispersion',
                 value = 1,
                 min = 1,
                 step = 0.05
    )),

  textOutput(outputId = 'sample_size')


)

server <- function(input, output, session) {

  output$sample_size<-renderText({

    if(input$method_name == 'Linear Regression'){
      N = compute_sample_size(
        method_name = stringr::str_to_lower(input$method_name),
        beta = input$beta,
        var_y = input$var_y,
        var_x = input$var_x,
        mult_cor = input$mult_cor,
        power = input$power,
        fpr = input$fpr
      )
    }
    if(input$method_name == 'Logistic Regression'){
      N = compute_sample_size(
        method_name = stringr::str_to_lower(input$method_name),
        beta = input$beta,
        prob = input$prob,
        var_x = input$var_x,
        mult_cor = input$mult_cor,
        power = input$power,
        fpr = input$fpr
      )
    }
    if(input$method_name == 'Cox Regression'){
      N = compute_sample_size(
        method_name = stringr::str_to_lower(input$method_name),
        beta = input$beta,
        prob_uncens = input$prob_uncens,
        var_x = input$var_x,
        mult_cor = input$mult_cor,
        power = input$power,
        fpr = input$fpr
      )
    }
    if(input$method_name == 'Poisson Regression'){
      N = compute_sample_size(
        method_name = stringr::str_to_lower(input$method_name),
        beta = input$beta,
        disp = input$disp,
        var_x = input$var_x,
        mult_cor = input$mult_cor,
        power = input$power,
        fpr = input$fpr
      )
    }
    stringr::str_c('Sample Size: ',N)
  })

}

shinyApp(ui, server)
Dpananos/poweregg documentation built on May 17, 2019, 5:25 a.m.