Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sirplus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BioCellGen-public
sirplus
Commits
b0e4bce9
Commit
b0e4bce9
authored
4 years ago
by
Christina Azodi
Browse files
Options
Downloads
Patches
Plain Diff
update hosp weekly to have ci bars
parent
62a3fa69
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
NAMESPACE
+1
-0
1 addition, 0 deletions
NAMESPACE
R/get_weekly_local.R
+0
-92
0 additions, 92 deletions
R/get_weekly_local.R
with
1 addition
and
92 deletions
NAMESPACE
+
1
−
0
View file @
b0e4bce9
...
...
@@ -17,6 +17,7 @@ export(departures.FUN)
export(format_sims)
export(get_ci)
export(get_prev.FUN)
export(get_weekly_local)
export(infection.FUN)
export(init_seiqhrf)
export(init_status.icm)
...
...
This diff is collapsed.
Click to expand it.
R/get_weekly_local.R
deleted
100644 → 0
+
0
−
92
View file @
62a3fa69
#' Extract information of local and weekly estimates from simulation
#'
#'
#' @param sim An \code{seiqhrf} object returned by \link{simulate_seiqhrf}.
#' @param market.share between 0 and 1, percentage of local hospital beds in
#' the simulated unit (e.g. state)
#' @param icu_percent between 0 and 1, percentage of patients that should go to
#' ICU among the ones that need hospitalization
#' @param start_date Epidemic start date. Default is 'na', if not provided will
#' plot week numbers, if provided will plot the first day (Sunday) of the
#' week.
#' @param time_limit Number of days to include. Default = 90.
#' @param total_population True population size, needed only if simulation size
#' is smaller than the true population size due to computational cost
#' etc.
#'
#' @return
#' \itemize{
#' \item \code{plot:} A \code{ggplot} object, bar charts of count of patients
#' requiring hospitalization and ICU respectively
#' \item \code{result:} A dataframe
#' \itemize{\item \code{week:} week number from input \code{sim},
#' \item \code{hosp:} the number of patients that require hospitalization locally,
#' \item \code{icu:} the number of patients that require ICU locally. }
#
#' }
#'
#' @importFrom tidyr pivot_wider
#'
get_weekly_local
<-
function
(
sim
,
market.share
=
.04
,
icu_percent
=
.1
,
start_date
=
'na'
,
time_limit
=
90
,
total_population
=
NULL
){
sim_mean
<-
as.data.frame
(
sim
,
out
=
"mean"
)
hosp
<-
sim_mean
$
h.num
if
(
!
is.null
(
total_population
)){
if
(
total_population
<
max
(
sim_mean
$
s.num
))
stop
(
"total Population should be larger than simulated size"
)
cat
(
"Scalling w.r.t total population"
)
hosp
<-
hosp
*
total_population
/
max
(
sim_mean
$
s.num
)
}
if
(
market.share
<
0
||
market.share
>
1
)
stop
(
"Market share has to be between
0 and 1"
)
if
(
icu_percent
<
0
||
icu_percent
>
1
)
stop
(
"ICU percentage has to be between
0 and 1"
)
hosp
[
is.na
(
hosp
)]
<-
0
hosp
<-
hosp
[
1
:
time_limit
]
hosp_week
<-
split
(
hosp
,
ceiling
(
seq_along
(
hosp
)
/
7
))
hosp_sum_week
<-
unlist
(
lapply
(
hosp_week
,
sum
))
t_sz
<-
length
(
hosp_sum_week
)
hosp_wk_df
<-
data.frame
(
wk
=
rep
(
seq_along
(
hosp_sum_week
),
2
),
group
=
rep
(
c
(
"general"
,
"icu"
),
each
=
t_sz
),
hosp_icu
=
c
(
hosp_sum_week
-
(
hosp_sum_week
*
icu_percent
),
hosp_sum_week
*
icu_percent
))
if
(
class
(
start_date
)
==
'Date'
){
hosp_wk_df
<-
data.frame
(
append
(
hosp_wk_df
,
list
(
Date
=
start_date
+
(
7
*
(
hosp_wk_df
$
wk
-
1
))),
after
=
match
(
"wk"
,
names
(
hosp_wk_df
))))
gg
<-
ggplot
(
data
=
hosp_wk_df
,
aes
(
x
=
Date
,
y
=
hosp_icu
,
fill
=
group
))
+
geom_bar
(
stat
=
"identity"
)
+
theme_bw
()
+
scale_x_date
(
date_breaks
=
"1 week"
,
date_labels
=
"%m-%d"
)
+
labs
(
y
=
"Weekly Hospital Load (sum over week)"
,
x
=
"Week"
)
}
else
{
gg
<-
ggplot
(
data
=
hosp_wk_df
,
aes
(
x
=
wk
,
y
=
hosp_icu
,
fill
=
group
))
+
geom_bar
(
stat
=
"identity"
)
+
theme_bw
()
+
labs
(
y
=
"Weekly Hospital Load (sum over week)"
,
x
=
"Week"
)
+
scale_x_continuous
(
breaks
=
seq
(
0
,
t_sz
,
5
),
labels
=
seq
(
0
,
t_sz
,
5
))
}
res
<-
hosp_wk_df
%>%
tidyr
::
pivot_wider
(
names_from
=
group
,
values_from
=
hosp_icu
)
return
(
list
(
"plot"
=
gg
,
"result"
=
res
))
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment