inst/shiny/sample_size_dashboard/ui.R

## Header
header <- dashboardHeader(title = "Sample Size")
## Sidebar
side <- dashboardSidebar(
            sidebarMenu(
                menuItem("About",        tabName = "about",        icon = icon("dashboard")),
                menuItem("pwr",          tabName = "pwr",          icon = icon("dashboard")),
                menuItem("samplesize",   tabName = "samplesize",   icon = icon("dashboard")),
                menuItem("TrialSize",    tabName = "TrialSize",    icon = icon("dashboard")),
                menuItem("clusterPower", tabName = "clusterPower", icon = icon("dashboard")),
                menuItem("longpower",    tabName = "longpower",    icon = icon("dashboard")),
                menuItem("PowerTOST",    tabName = "PowerTOST",    icon = icon("dashboard")),
                sliderInput(inputId = "power",
                            label   = "Power (1 - Beta)",
                            value   = 0.9,
                            min     = 0,
                            max     = 1,
                            step    = 0.01,
                            round   = FALSE,
                            ticks   = TRUE),
                sliderInput(inputId = "sig.level",
                            label   = "Significance Level",
                            value   = 0.01,
                            min     = 0.00001,
                            max     = 0.1,
                            step    = 0.00001,
                            round   = FALSE,
                            ticks   = TRUE),
                sliderInput(inputId = "prop1",
                            label   = "Proportion 1",
                            value   = 0.9,
                            min     = 0,
                            max     = 1,
                            step    = 0.01,
                            round   = FALSE,
                            ticks   = TRUE),
                sliderInput(inputId = "prop2",
                            label   = "Proportion 2",
                            value   = 0.8,
                            min     = 0,
                            max     = 1,
                            step    = 0.01,
                            round   = FALSE,
                            ticks   = TRUE),
                sliderInput(inputId = "mean1",
                            label   = "Mean 1",
                            value   = 1,
                            min     = 0,
                            max     = 100,
                            step    = 0.1,
                            round   = FALSE,
                            ticks   = TRUE),
                sliderInput(inputId = "sd1",
                            label   = "SD 1",
                            value   = 1,
                            min     = 0,
                            max     = 100,
                            step    = 0.1,
                            round   = FALSE,
                            ticks   = TRUE),
                sliderInput(inputId = "mean2",
                            label   = "Mean 2",
                            value   = 1,
                            min     = 0,
                            max     = 100,
                            step    = 0.1,
                            round   = FALSE,
                            ticks   = TRUE),
                sliderInput(inputId = "sd2",
                            label   = "SD 2",
                            value   = 1,
                            min     = 0,
                            max     = 100,
                            step    = 0.1,
                            round   = FALSE,
                            ticks   = TRUE)
            )
)
## Body
body <- dashboardBody(
            tabItems(
                tabItem(tabName = "about",
                        h2("About"),
                        fluidRow(width = 12,
                                 column(width = 12,
                                        p("This site allows you to compute sample sizes for lots of study designs.  It uses a number of packages that are listed on the",
                                          a(href = "https://cran.r-project.org/web/views/ClinicalTrials.html",
                                            "CRAN Clinical Trials TaskView"),
                                          " and is in essence simply a graphical wrapper for the various packages listed there saving the user to be familiar with ",
                                          a(href = "https://www.r-project.org/",
                                            "R"),
                                          " and its syntax in order to perform sample size calculations.  For now only point estimates of the estimated power based on the supplied parameters are provided but in due course the site will be extended and will perform calculations around the parameters estimated and plot these graphically since there is very often uncertainty around the estimates of effect sizes and the obtained sample size will often differ from that desired due to missing data (whether thats failure to recruit sufficient participants or loss to follow-up).  Currently the packages that are supported are listed on the left."),
                                        HTML("<ul>
                                              <li> <a href='https://cran.r-project.org/web/packages/pwr/' target='_blank'>pwr</a>
                                              <li> <a href='https://cran.r-project.org/web/packages/samplesize/' target='_blank'>samplesize</a>
                                              <li> <a href='https://cran.r-project.org/web/packages/TrialSize/' target='_blank'>TrialSize</a>
                                              <li> <a href='https://cran.r-project.org/web/packages/clusterPower/' target='_blank'>clusterPower</a>
                                              <li> <a href='https://cran.r-project.org/web/packages/longpower/' target='_blank'>longpower</a>
                                              <li> <a href='https://cran.r-project.org/web/packages/powerTOST/' target='_blank'>powerTOST</a>
                                              </ul>"),
                                        p("Many of these calculations over-simplify the analysis, assuming a direct test of proportions, or comparison of means is made (some of the provided calculators account for study designs such as clustering and/or longitudinal analyses).  Very often analyses are far more sophisticated and include adjustments for covariates and in doing so the power of the test performed is altered.  Such factors affecting the sample size calculation are not accounted for in the calculations that derive sample sizes for direct comparison of means or proportions and are therefore often inappropriate methods of basing study designs on.  Users interested in a more complete and rounded approach to sample size calculations that accounts for this may be interested in simulation and are pointed towards the excellent package ",
                                          a(href = "https://cran.r-project.org/web/packages/simglm/index.html",
                                            "simglm"),
                                          " (",
                                          a(href = "https://github.com/lebebr01/simglm",
                                            "GitHub"),
                                          ") which allows a more complete specification of many study designs and performs simulations to determine the power of a given sample size.  It includes a Shiny WebUI application to ease the process of specifying models.  It includes several vignettes, the most relevant of which is",
                                          a(href = "https://cran.r-project.org/web/packages/simglm/vignettes/Power.html",
                                            "Power Analysis with simglm"),
                                          "."))),
                        h2("ToDo"),
                        fluidRow(width = 12,
                                 column(width = 12,
                                        p("This is a work in progress, completed so far in the authors personal time for gratis.  There are a number of ways in which it can be improved, some of which are listed below."),
                                        HTML("<ul>
                                              <li> Abstract common components to the sidebar (e.g. desired significance level and desired power, proportions/means), some progress need to reactively standardise these for use in subsequent functions.
                                              <li> Allow users to input real values and calculate standardised effects sizes (in terms of Cohen's D) internally for passing to the various functions, some progress on this is in place.
                                              <li> Ultimately a cleaner interface will be to allow specification of parameters in the sidebar along with the package that is to be used to determine the required sample size, this requires reactivity in the ui.R and various components and is documented in <a href='https://shiny.rstudio.com/articles/dynamic-ui.html' target='_blank'>Dynamic UI</a>.
                                              <li> Take the parameters provided and perform calculations for a range of values around these, plotting results and displaying these since the point estimates are likely to be off and its useful for researchers to know how this will impact the sample size they should be looking to obtain.
                                              <li> Include 'modules' for calculating sample sizes for the various group-sequential study design packages that are available.
                                              <li> Make elements below reactive to the selected test type so that for example input for k (number of groups) under pwr is only shown if Test == ANOVA (One-way balanced) is selected.
                                              </ul>"))),
                        h2("Contributing"),
                        fluidRow(width = 12,
                                 column(width = 12,
                                        p("This ",
                                          a(href = "",
                                            "Shiny Application"),
                                          " is part of the R package ",
                                          a(href = "https://github.com/ns-ctru/ctru/",
                                            "ctru"),
                                          " developed by ",
                                          a(href = "mailto:n.shephard@sheffield.ac.uk",
                                            "Neil Shephard"),
                                          " with a view to sharing code between staff within the ",
                                          a(href = "https://www.sheffield.ac.uk/scharr/sections/dts/ctru",
                                            "Sheffield Clinical Trials Unit (CTRU)"),
                                          " and ",
                                          a(href = "https://www.sheffield.ac.uk/scharr/sections/dts/statistics",
                                            "Medical Statistics Group (MSG)"),
                                          ".  The package development is version controlled using ",
                                          a(href = "",
                                            "Git"),
                                          " and is hosted on ",
                                          a(href = "https://github.com/ns-ctru/ctru/",
                                            "GitHub"),
                                          " meaning anyone who wishes to correct or extend the functionality/design (e.g. by addressing items on the ToDo list above) can do so by forking the repository, making changes locally and then submitting a pull request.  If you are not familiar with these steps refer to an overview ",
                                          a(href = "https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github",
                                            "here"),
                                          " (there are plenty of additional resources on using Git/GitHub on the web, some are referenced in the slides",
                                          a(href = "https://www.overleaf.com/read/czjppxskyxpj",
                                            "RepRoducibility"),
                                          " written by the author of this package).")
                                 ))),
                tabItem(tabName = "pwr",
                        h2("pwr"),
                        fluidRow(
                            column(width = 6,
                                   p("Perform sample size calculations using the ",
                                     a(href = "https://cran.r-project.org/web/packages/pwr/",
                                       "pwr",
                                       target = "_blank"),
                                     " package.  Users would likely benefit from reading the ",
                                     a(href = "https://cran.r-project.org/web/packages/pwr/vignettes/pwr-vignette.html",
                                       "package vignette",
                                       target = "_blank"),
                                     "."),
                                   p("The package documentation can be viewed ",
                                     a(href = "https://www.rdocumentation.org/packages/pwr/",
                                       "online",
                                       target = "_blank"),
                                     "."),
                                   selectInput(inputId = "test",
                                               label   = "Test",
                                               choices = c("One-sample Proportion"                            = "pwr.p.test",
                                                           "Two-sample Proportion (equal size)"               = "pwr.2p.test",
                                                           "Two-sample Proportion (unequal size)"             = "pwr.2p2n.test",
                                                           "T-test (One, Two and Paired sample, equal size)"  = "pwr.t.test",
                                                           "T-test (Two sample, unequal size)"                = "pwr.t2n.test",
                                                           "ANOVA (One-way balanched)"                        = "pwr.anova.test",
                                                           "Correlation Test"                                 = "pwr.r.test",
                                                           "Chi-squared Test"                                 = "pwr.chisq.test",
                                                           "General Linear Model"                             = "pwr.f2.test"
                                                           )
                                               ),
                                   selectInput(inputId = "alternative",
                                               label   = "Alternative Hypothesis",
                                               choices = c("Two-Sided"   = "two.sided",
                                                           "Less"        = "less",
                                                           "Greater"     = "greater")),
                                   selectInput(inputId = "type",
                                               label   = "Type",
                                               choices = c("Two Sample"   = "two.sample",
                                                           "One Sample"   = "one.sample",
                                                           "Paired"       = "paired")),
                                   sliderInput(inputId = "k",
                                               label   = "Number of Groups (for ANOVA)",
                                               value   = 0,
                                               min     = 0,
                                               max     = 10,
                                               step    = 1,
                                               round   = FALSE,
                                               ticks   = TRUE),
                                   sliderInput(inputId = "r",
                                               label   = "Correlation Coefficient",
                                               value   = 0.8,
                                               min     = 0,
                                               max     = 1,
                                               step    = 0.001,
                                               round   = FALSE,
                                               ticks   = TRUE),
                                   sliderInput(inputId = "h",
                                               label   = "Effect Size (Cohen's D)",
                                               value   = 0.1,
                                               min     = 0,
                                               max     = 1,
                                               step    = 0.01,
                                               round   = FALSE,
                                               ticks   = TRUE),
                                   sliderInput(inputId = "ratio",
                                               label   = "Ratio of Sample Sizes for 2-arm trials with different size arms",
                                               value   = 0.5,
                                               min     = 0,
                                               max     = 1,
                                               step    = 0.01,
                                               round   = FALSE,
                                               ticks   = TRUE)
                                   ),
                            column(width = 6,
                                   valueBoxOutput("pwr_n"),
                                   valueBoxOutput("alpha"),
                                   valueBoxOutput("power")
                                   )
                        )
                        ),
                tabItem(tabName = "samplesize",
                        h2("samplesize"),
                        fluidRow(width = 12,
                            column(width = 6,
                                   p("Perform sample size calculations using the ",
                                     a(href = "https://cran.r-project.org/web/packages/samplesize/",
                                       "samplesize",
                                       target = "_blank"),
                                     " package."),
                                   p("The package documentation can be viewed ",
                                     a(href = "https://www.rdocumentation.org/packages/samplesize/",
                                       "online",
                                       target = "_blank"),
                                     "."),
                                   selectInput(inputId = "test",
                                               label   = "Test",
                                               choices = c("T-Test"        = "n.ttest",
                                                           "Wilcox"      = "n.wilcox.ord")
                                               ),
                                   selectInput(inputId = "design",
                                               label   = "Design",
                                               choices = c("Unpaired"    = "unpaired",
                                                           "Paired"      = "paired")
                                               ),
                                   selectInput(inputId = "fraction",
                                               label   = "Fraction",
                                               choices = c("Balanced"    = "balanced",
                                                           "Unbalanced"  = "unbalanced")
                                               ),
                                   selectInput(inputId = "variance",
                                               label   = "Variance",
                                               choices = c("Equal"       = "equal",
                                                           "Unequal"     = "unequal")
                                               )
                                   )## ,
                            ## column(width = 6,
                            ##        valueBoxOutput("samplesize_n"),
                            ##        valueBoxOutput("alpha"),
                            ##        valueBoxOutput("power")
                            ##        )
                            )
                        ),
                tabItem(tabName = "TrialSize",
                        h2("TrialSize"),
                        fluidRow(width = 12,
                                 column(width = 6,
                                        p("Perform sample size calculations using the ",
                                          a(href = "https://cran.r-project.org/web/packages/TrialSize/",
                                            "TrialSize",
                                            target = "_blank"),
                                          " package.  There is no package vignette."),
                                        p("The package documentation can be viewed ",
                                          a(href = "https://www.rdocumentation.org/packages/TrialSize/",
                                            "online",
                                            target = "_blank"),
                                          ".")
                                        )
                                )
                        ),
                tabItem(tabName = "clusterPower",
                        h2("clusterPower"),
                        fluidRow(width = 12,
                            column(width = 6,
                                   p("Perform sample size calculations using the ",
                                     a(href = "https://cran.r-project.org/web/packages/clusterPower/",
                                       "clusterPower",
                                       target = "_blank"),
                                     " package.  There is no package vignette."),
                                   p("The package documentation can be viewed ",
                                     a(href = "https://www.rdocumentation.org/packages/clusterPower/",
                                       "online",
                                       target = "_blank"),
                                     ".")
                                   )
                              )
                        ),
                tabItem(tabName = "longpower",
                        h2("longpower"),
                        fluidRow(width = 12,
                            column(width = 6,
                                   p("Perform sample size calculations using the ",
                                     a(href = "https://cran.r-project.org/web/packages/longpower/",
                                       "longpower",
                                       target = "_blank"),
                                     " package.  A useful reference is the package vignette",
                                     a(href = "https://cran.r-project.org/web/packages/longpower/vignettes/longpower.pdf",
                                       "Power calculations for longitudinal data",
                                       target = "_blank"),
                                     "."),
                                   p("The package documentation can be viewed ",
                                     a(href = "https://www.rdocumentation.org/packages/longpower/",
                                       "online",
                                       target = "_blank"),
                                     ".")
                                   )
                               )
                        ),
                tabItem(tabName = "PowerTOST",
                        h2("PowerTOST"),
                        fluidRow(width = 12,
                            column(width = 6,
                                   p("Perform sample size calculations using the ",
                                     a(href = "https://cran.r-project.org/web/packages/PowerTOST/",
                                       "PowerTOST",
                                       target = "_blank"),
                                     " package for (Bio)Equivalence studies.  There is no package vignette."),
                                   p("The package documentation can be viewed ",
                                     a(href = "https://www.rdocumentation.org/packages/powerTOST/",
                                       "online",
                                       target = "_blank"),
                                     ".")
                                   )
                              )
                        )
            )
)

ui <- dashboardPage(header,
                    side,
                    body,
                    skin = "purple")


## Generic sample code to copy and paste into sections above
## sliderInput(inputId = "",
##             label   = "",
##             value   = ,
##             min     = ,
##             max     = ,
##             step    = ,
##             round   = FALSE,
##             ticks   = TRUE)
## selectInput(inputId  = "",
##             label    = "",
##             selected = NULL,
##             choices  = c("" = "",
##                          "" = "",
##                          "" = ""))
ns-ctru/ctru documentation built on May 23, 2019, 9:34 p.m.