-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.R
More file actions
98 lines (83 loc) · 3.1 KB
/
app.R
File metadata and controls
98 lines (83 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# to upload, run rsconnect::deployApp('MetaStudiesApp')
library(shiny)
rm(list = ls())
source("metastudiesfunctions.r")
source("metastudiesplots.r")
ui <- fluidPage(
# titlePanel(h1("Optimal treatment assignment given covariates", align = "center")),
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File of estimates and standard errors",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
hr(),
h3("Model parameters"),
fluidRow(
column(6, checkboxInput("symmetric", "Symmetric p(.)", value = FALSE),
checkboxGroupInput("cutoffs", "Cutoffs for p(.)",
choiceNames = c("1.65", "1.96","2.58"),
choiceValues = c(1.645, 1.960, 2.576),
selected = 1.960)),
column(6, radioButtons("modelmu", "Model for the distribution of effects",
choices = c("Normal" = "normal",
"Student-t" = "t" #,
#"nonparametric" = 3
),
selected = "normal"))
),
#hr(),
actionButton(inputId = "estimatebutton", label = "Estimate model")
),
mainPanel(
h2("Funnel plot, histogram of z-stats", align = "center"),
fluidRow(splitLayout(cellWidths = c("50%", "50%"),
plotOutput("funnel"),
plotOutput("hist")))
)
),
hr(),
h2("Model estimates", align = "center"),
h4("Distribution of true effects, conditional publication proabilities", align = "center"),
column(12, align="center",
tableOutput("estimatestable"),
plotOutput("estplot", width = "70%")
)
)
server <- function(input, output, session) {
#object to store data and estimation results
v = reactiveValues()
# read data, generate funnel plot
output$funnel=renderPlot({
req(input$file1)
metadata=read.table(input$file1$datapath,
sep=",")
v$X=metadata[,1]
v$sigma=metadata[,2]
metastudies_plot(v$X,v$sigma)
})
# generate histogram
output$hist=renderPlot({
req(v$X)
z_histogram(v$X, v$sigma)
})
#estimation
observeEvent(input$estimatebutton,{
v$cutoffs=as.numeric(unlist(input$cutoffs))
v$symmetric=input$symmetric
v$modelmu=input$modelmu
if (!v$symmetric) v$cutoffs= c(-rev(v$cutoffs), 0 ,v$cutoffs)
v$estimates=metastudies_estimation(v$X,v$sigma,v$cutoffs, v$symmetric, model= v$modelmu)
output$estplot = renderPlot({
estimates_plot(v$X,v$sigma,v$cutoffs, v$symmetric,v$estimates, model= v$modelmu)
})
})
#render estimates to table
output$estimatestable = renderTable(rownames=TRUE,hover=TRUE,digits=3,
{req(v$estimates)
estimatestable(v$estimates$Psihat, v$estimates$SE, v$cutoffs, v$symmetric, v$modelmu)
})
}
# Run the app ----
shinyApp(ui = ui, server = server)