Skip to content

Commit 2b8d5e0

Browse files
committed
init transfer from svn repos
1 parent c5a5797 commit 2b8d5e0

34 files changed

+951
-0
lines changed

DESCRIPTION

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Package: shinysse
2+
Type: Package
3+
Title: What the Package Does (Title Case)
4+
Version: 0.1.2
5+
Author: Milica Markovic
6+
Maintainer: Milica Markovic <[email protected]>
7+
Description: Shiny package providing a sample size estimation (sse) web app
8+
License: What license is it under?
9+
Depends:
10+
shiny,
11+
shinydashboard,
12+
dplyr,
13+
sse,
14+
purrr,
15+
ggplot2
16+
Encoding: UTF-8
17+
LazyData: true
18+
RoxygenNote: 7.0.2

NAMESPACE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(app_server)
4+
export(app_ui)
5+
export(dash)
6+
export(fun_calc_prop)
7+
export(fun_calc_t)
8+
export(run_shiny)

R/app.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#' Runs the shinysse Shiny application
2+
#'
3+
#' This runs the shinysse Shiny web application. You can run the application by
4+
#' calling the run_shiny() function.
5+
#'
6+
#' @seealso \code{\link{app}},\code{\link{app_ui}}
7+
#' @export
8+
#'
9+
run_shiny <- function(){
10+
## with addResourcePath, one can make resources available in the global environment
11+
## this is needed for www since we keep it at a non-standard location for shiny term
12+
addResourcePath('www', system.file('www', package = 'shinysse'))
13+
shinyApp(ui = app_ui, server = app_server)
14+
}

R/app_server.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#' Shiny main app server function for shinysse
2+
#'
3+
#' Calls modules defined in app_ui, and passes on relevant data.
4+
#'
5+
#' @seealso \code{\link{app_ui}}, \code{\link{run_shiny}}
6+
#' @export
7+
#'
8+
app_server <- function(input, output) {
9+
# data
10+
calc_t_twosample <- readRDS(system.file("extdata", "calc_t_test_twosample.rds", package = "shinysse"))
11+
calc_t_paired <- readRDS(system.file("extdata/calc_t_test_paired.rds", package = "shinysse"))
12+
calc_prop <- readRDS(system.file("extdata/calc_prop_test.rds", package = "shinysse"))
13+
# modules
14+
mod <- fun_get_mods()
15+
callModule(dash, mod$dash)
16+
callModule(sseBasic, mod$sse_basic, calc_t_twosample, calc_t_paired)
17+
callModule(ssePlus, mod$sse_plus, calc_t_twosample)
18+
callModule(ssePlus, mod$sse_plus_paired, calc_t_paired)
19+
callModule(sseProp, mod$sse_prop, calc_prop)
20+
}

R/app_ui.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#' Shiny main app UI function for shinysse
2+
#'
3+
#' Controls the general appearance, header, sidebar, body, modules, etc.
4+
#'
5+
#' @seealso \code{\link{app}}
6+
#' @export
7+
#'
8+
app_ui <- function(){
9+
mod <- fun_get_mods()
10+
dashboardPage(
11+
header_unibas("SSE app"),
12+
dashboardSidebar(
13+
div(p(" ")),
14+
sidebarMenu(
15+
menuItem("Introduction", tabName = mod$dash, icon = icon("info")),
16+
menuItem("Two sample t-Test SSE", tabName = mod$sse_basic, icon = icon("text-size", lib = "glyphicon")),
17+
menuItem("Two sample t-Test SSE + input", tabName = mod$sse_plus, icon = icon("text-size", lib = "glyphicon")),
18+
menuItem("Paired t-Test SSE + input", tabName = mod$sse_plus_paired, icon = icon("text-size", lib = "glyphicon")),
19+
menuItem("Proportion Test SSE", tabName = mod$sse_prop, icon = icon("percentage"))
20+
)
21+
),
22+
dashboardBody(
23+
tags$head(
24+
tags$link(rel = "stylesheet", type = "text/css", href = "www/custom.css")
25+
),
26+
tabItems(
27+
dashUI(mod$dash, label = mod$dash),
28+
sseBasicUI(mod$sse_basic, label = mod$sse_basic),
29+
ssePlusUI(mod$sse_plus, label = mod$sse_plus),
30+
ssePlusUI(mod$sse_plus_paired, label = mod$sse_plus_paired),
31+
ssePropUI(mod$sse_prop, label = mod$sse_prop)
32+
)
33+
)
34+
)
35+
}

R/fun_calc_prop.R

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#' Evaluates power -function for power.prop.test
2+
#'
3+
#' For all pre-set combinations of n, theta, xi and alpha, this function calculates a list of powPar (package: sse)
4+
#' objects and saves them at a pre-set location in inst/extdata. The function uses the stats::power.prop.test for
5+
#' this purpose. Make sure to re-build the package after running the function, in order to make it available
6+
#' with package installation.
7+
#'
8+
#' @return list of calculated powPar objects
9+
#' @export
10+
#'
11+
fun_calc_prop <- function(){
12+
## define range of significance levels
13+
alpha <- c(0.01, 0.025, 0.05)
14+
## defining the range of n and theta to be evaluated
15+
psi_prop <- powPar(n = seq(from = 3, to = 10000, by = 5), # possible range of sample sizes
16+
theta = c(seq(from = 0, to = 0.15, by = 0.0125),
17+
seq(from = 0.2, to = 0.5, by = 0.05)), # possible range of effect sizes
18+
xi = seq(from = 0.05, to = 1, by = 0.05)) # possible range of proportions
19+
20+
## defining a power-function based on a power.prop.test
21+
powFuns_prop <- list()
22+
for(i in 1:length(alpha)){
23+
eval(parse(text = paste(paste0("powFuns_prop[[", paste0("'alpha", sub(".", "p", alpha[i], fixed = TRUE)), "']]", " <- function(psi)"),
24+
"{",
25+
"p1 = xi(psi)",
26+
"power.prop.test(n = sse::n(psi)/2,",
27+
"p1 = p1,",
28+
"p2 = p1-theta(psi),",
29+
paste0("sig.level = ", alpha[i], ","),
30+
"power = NULL",
31+
")$power",
32+
"}", sep = "\n")))
33+
}
34+
35+
## evaulate power-function for all combinations of n, theta, xi and alpha
36+
calc_prop <- map(powFuns_prop, ~powCalc(psi_prop, .))
37+
38+
## readRDS
39+
calc_prop <- readRDS("calc_prop_test.rds")
40+
calc_prop <- readRDS(system.file("extdata", "calc_prop_test.rds", package = "shinyssepkg"))
41+
## save calcs to be used in the shiny app
42+
save_path <- file.path("inst", "extdata", "calc_prop_test.rds")
43+
saveRDS(calc_prop, save_path)
44+
return(calc_prop)
45+
}

R/fun_calc_t.R

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#' Evaluates power -function for power.t.test
2+
#'
3+
#' For all pre-set combinations of n, theta, xi and alpha, this function calculates a list of powPar (package: sse)
4+
#' objects and saves them at a pre-set location in inst/extdata. The function uses the stats::power.t.test for
5+
#' this purpose. Make sure to re-build the package after running the function, in order to make it available
6+
#'
7+
#' @param type character string specifying the type of t test. options: "two.sample", "one.sample", "paired"
8+
#' @return list of calculated powPar objects
9+
#' @export
10+
#'
11+
fun_calc_t <- function(type = "two.sided"){
12+
print(type)
13+
## define range of significance levels
14+
alpha <- c(0.01, 0.025, 0.05)
15+
## defining the range of n and theta to be evaluated
16+
psi_t <- powPar(n = seq(from = 5, to = 2000, by = 5), # possible range of sample sizes
17+
theta = seq(from = 1, to = 50, by = 1), # possible range of effect sizes
18+
xi = seq(from = 1, to = 80, by = 1)) # possible range of standard deviations
19+
## defining a power-function based on a power.t.test
20+
powFuns_t <- list()
21+
for(i in 1:length(alpha)){
22+
eval(parse(text = paste(paste0("powFuns_t[[", paste0("'alpha", sub(".", "p", alpha[i], fixed = TRUE)), "']]", " <- function(psi)"),
23+
"{",
24+
"power.t.test(n = sse::n(psi)/2,",
25+
"delta = theta(psi),",
26+
"sd = xi(psi),",
27+
paste0("sig.level = ", alpha[i], ","),
28+
"power = NULL,",
29+
paste0("type = '", type, "'"),
30+
")$power",
31+
"}", sep = "\n")))
32+
}
33+
## evaulate power-function for all combinations of n, theta, xi and alpha
34+
calc_t <- map(powFuns_t, ~powCalc(psi_t, .))
35+
## save calcs to be used in the shiny app
36+
save_path <- file.path("inst", "extdata", paste0("calc_t_test_", type, ".rds"))
37+
saveRDS(calc_t, save_path)
38+
return(calc_t)
39+
}

R/fun_get_mods.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fun_get_mods <- function(){
2+
mod <- list()
3+
mod$dash <- "dashboard"
4+
mod$sse_basic <- "sse_basic"
5+
mod$sse_plus <- "sse_plus"
6+
mod$sse_plus_paired <- "sse_plus_paired"
7+
mod$sse_prop <- "sse_prop"
8+
return(mod)
9+
}

R/fun_header_unibas.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# define header
2+
header_unibas <- function(header_label){
3+
header <- dashboardHeader(
4+
title = header_label,
5+
tags$li(class = "dropdown"))
6+
7+
header$children[[4]] <- header$children[[2]]
8+
header$children[[4]]$children[[1]] <- header$children[[2]]
9+
header$children[[4]]$children[[2]] <- header$children[[2]]
10+
header$children[[4]]$children[[2]]$children[[1]] <- header$children[[2]]
11+
header$children[[4]]$name <- "div"
12+
header$children[[4]]$attribs$class <- "custom-head"
13+
# uni basel header row
14+
header$children[[4]]$children[[1]]$name <- "aside"
15+
header$children[[4]]$children[[1]]$attribs$class <- "unibas"
16+
header$children[[4]]$children[[1]]$children <- NULL
17+
# dkf/faculty header row
18+
header$children[[4]]$children[[2]]$name <- "aside"
19+
header$children[[4]]$children[[2]]$attribs$class <- "dkf"
20+
header$children[[4]]$children[[2]]$children <- NULL
21+
return(header)
22+
}

R/fun_sidebar.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
getSidebar <- function(){
2+
library(shinydashboard)
3+
side <- sidebarMenu(
4+
menuItem("Dashboard", tabName = mod$dash, icon = icon("dashboard")),
5+
menuItem("SSE Basic", tabName = mod$sse_basic, icon = icon("user-alt")),
6+
menuItem("SSE Plus", tabName = mod$sse_plus, icon = icon("user-plus"))
7+
)
8+
return(side)
9+
}

0 commit comments

Comments
 (0)