-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
174 lines (152 loc) · 7.25 KB
/
app.R
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
library(shiny)
ui <- (fluidPage(
# Header
titlePanel("Microsimulation Model of Concurrency on HIV Transmission Dynamics"),
# Sidebar
sidebarLayout(
sidebarPanel(
h3("Instructions", style = "margin-top: 0px"),
helpText("Click Run Model after changing model parameters",
"or conditions."),
actionButton(inputId = "runMod", "Run Model"),
h4("Initial Conditions", style = "margin-top: 25px"),
numericInput(inputId = "s.num.m", label = "n Male Susceptible",
value = 1000, min = 1),
numericInput(inputId = "s.num.f", label = "n Female Susceptible",
value = 1000, min = 1),
numericInput(inputId = "i.num.m", label = "n Male Infected",
value = 50, min = 1),
numericInput(inputId = "i.num.f", label = "n Female Infected",
value = 50, min = 1),
h4("Epidemic Parameters", style = "margin-top: 25px"),
sliderInput(inputId = "md", label = "Mean Degree",
min = 0.5, max = 1, value = 0.8, step = 0.05),
sliderInput(inputId = "dur", label = "Mean Partnership Duration",
min = 1, max = 50, value = 10, step = 1),
selectInput(inputId = "conc", label = "Concurrency Rule",
choices = c("No Concurrency",
"Female Only Concurrency",
"Male Only Concurrency",
"Both Sexes Concurrency")),
h4("Control Settings", style = "margin-top: 25px"),
sliderInput(inputId = "sims", label = "Simulations",
value = 10, min = 1, max = 25, step = 1),
numericInput(inputId = "nsteps", label = "Time Steps",
value = 2000, min = 100)
), # end sidebarPanel
mainPanel(
tabsetPanel(
tabPanel("Plot",
h4("Simulation Results"),
plotOutput(outputId = "concplot", height = "550px"),
br(),
wellPanel(
h4("Graphical Parameters"),
fluidRow(
column(3, checkboxInput(inputId = "sim.lines", label = "Sim Lines",
value = FALSE)),
column(3, checkboxInput(inputId = "mean.line", label = "Mean Line",
value = TRUE)),
column(3, checkboxInput(inputId = "mean.smooth", label = "Smooth Mean",
value = TRUE)),
column(3, checkboxInput(inputId = "qnts.smooth", label = "Smooth Quantile",
value = TRUE))
),
fluidRow(
column(6, sliderInput(inputId = "qnts", label = "Quantile Range",
value = 0.5, min = 0, max = 1, step = 0.05)),
column(6, sliderInput(inputId = "sim.alpha", label = "Sim Line Transparency",
value = 0.3, min = 0.05, max = 1, step = 0.05))
),
fluidRow(
column(6, sliderInput(inputId = "mean.lwd", label = "Mean Width",
value = 3, min = 1, max = 5, step = 1)),
column(6, sliderInput(inputId = "qnt.alpha", label = "Quantile Transparency",
value = 0.3, min = 0.05, max = 1, step = 0.05))
)
)),
tabPanel("About",
p("This application simulates a stochastic epidemic model of HIV-1 infection to
illustrate the impact of sexual partnership concurrency on transmission dynamics.
The theory and mathematics of this model are provided in the full ",
a("Concurrency Tutorial",
href = "https://statnet.csde.washington.edu/trac/wiki/ConcurrencyIndex"),
" associated with this web application. This model is also built into the",
a("EpiModel", href = "http://cran.r-project.org/web/packages/EpiModel/index.html"),
" software available for the R statistical computing platform.", style = "margin-top: 25px"),
p("HIV infection is simulated based on a four-stage disease progression model
in which persons transition from acute to latent to pre-AIDS to AIDS stages.
These transitions occur at deterministic intervals based on estimates of the
average time per stage. Also, the transmission probability to uninfected partners
varies by stage of the infected partner: it is highest in the acute stage and
lowest in the AIDS stage when no sexual acts are simulated to occur. This is
based on empirical estimates in ",
a("Hollingsworth (2008).", href = "http://www.ncbi.nlm.nih.gov/pubmed/18662132")),
strong("Authors"),
p("These tools were authored by ",
a("Steven M. Goodreau,", href = "http://faculty.washington.edu/goodreau/"),
" ",
a("Samuel M. Jenness,", href = "http://samueljenness.org/"),
" and ",
a("Martina Morris", href = "http://faculty.washington.edu/morrism/")))
) # end tabsetPanel
) # end mainPanel
) # end sidebarLayout
))
server <- (function(input, output, session) {
monogM <- reactive({
switch(input$conc,
"No Concurrency" = TRUE,
"Female Only Concurrency" = TRUE,
"Male Only Concurrency" = FALSE,
"Both Sexes Concurrency" = FALSE)
})
monogF <- reactive({
switch(input$conc,
"No Concurrency" = TRUE,
"Female Only Concurrency" = FALSE,
"Male Only Concurrency" = TRUE,
"Both Sexes Concurrency" = FALSE)
})
observeEvent(input$conc, {
mdConc <- ifelse(input$conc == "No Concurrency", 1, 1.5)
updateSliderInput(session, inputId = "md", label = "Mean Degree",
min = 0.5, max = mdConc, value = 0.8, step = 0.05)
})
sim <- reactive({
input$runMod
progress <- shiny::Progress$new()
progress$set(message = "Computing", value = 0)
on.exit(progress$close())
updateProgress <- function(detail = NULL) {
progress$inc(amount = 1/input$sims, detail = detail)
}
isolate(
conc_microsim(
s.num.f = input$s.num.f,
i.num.f = input$i.num.f,
s.num.m = input$s.num.m,
i.num.m = input$i.num.m,
monog.f = monogF(),
monog.m = monogM(),
meandeg = input$md,
part.duration = input$dur,
nsteps = input$nsteps,
nsims = input$sims,
verbose = FALSE,
updateProgress = updateProgress))
})
output$concplot <- renderPlot({
par(mar = c(3.5, 3.5, 1.2, 1), mgp = c(2.1, 1, 0))
plot(sim(),
sim.lines = input$sim.lines,
sim.alpha = input$sim.alpha,
mean.line = input$mean.line,
mean.smooth = input$mean.smooth,
mean.lwd = input$mean.lwd,
qnts = input$qnts,
qnt.alpha = input$qnt.alpha,
qnts.smooth = input$qnts.smooth)
})
})
shinyApp(ui = ui, server = server)