84
84
# ' )
85
85
dist_skel <- function (n , dist = FALSE , cum = TRUE , model ,
86
86
discrete = FALSE , params , max_value = 120 ) {
87
- if (model %in% " exp" ) {
87
+ if (model == " exp" ) {
88
88
# define support functions for exponential dist
89
89
rdist <- function (n ) {
90
90
rexp(n , params $ rate )
@@ -97,7 +97,7 @@ dist_skel <- function(n, dist = FALSE, cum = TRUE, model,
97
97
pexp(n , params $ rate )) /
98
98
pexp(max_value + 1 , params $ rate )
99
99
}
100
- } else if (model %in% " gamma" ) {
100
+ } else if (model == " gamma" ) {
101
101
rdist <- function (n ) {
102
102
rgamma(n , params $ shape , params $ scale )
103
103
}
@@ -110,7 +110,7 @@ dist_skel <- function(n, dist = FALSE, cum = TRUE, model,
110
110
pgamma(n , params $ shape , params $ scale )) /
111
111
pgamma(max_value + 1 , params $ shape , params $ scale )
112
112
}
113
- } else if (model %in% " lognormal" ) {
113
+ } else if (model == " lognormal" ) {
114
114
rdist <- function (n ) {
115
115
rlnorm(n , params $ mean , params $ sd )
116
116
}
@@ -141,16 +141,16 @@ dist_skel <- function(n, dist = FALSE, cum = TRUE, model,
141
141
142
142
# define internal sampling function
143
143
inner_skel <- function (n , dist = FALSE , cum = TRUE , max_value = NULL ) {
144
- if (! dist ) {
145
- rdist(n )
146
- } else {
144
+ if (dist ) {
147
145
if (cum ) {
148
146
ret <- pdist(n )
149
147
} else {
150
148
ret <- ddist(n )
151
149
}
152
150
ret [ret > 1 ] <- NA_real_
153
151
return (ret )
152
+ } else {
153
+ rdist(n )
154
154
}
155
155
}
156
156
@@ -246,14 +246,14 @@ dist_fit <- function(values = NULL, samples = 1000, cores = 1,
246
246
247
247
model <- stanmodels $ dist_fit
248
248
249
- if (dist %in% " exp" ) {
249
+ if (dist == " exp" ) {
250
250
data $ dist <- 0
251
251
data $ lam_mean <- array (mean(values ))
252
- } else if (dist %in% " lognormal" ) {
252
+ } else if (dist == " lognormal" ) {
253
253
data $ dist <- 1
254
254
data $ prior_mean <- array (log(mean(values )))
255
255
data $ prior_sd <- array (log(sd(values )))
256
- } else if (dist %in% " gamma" ) {
256
+ } else if (dist == " gamma" ) {
257
257
data $ dist <- 2
258
258
data $ prior_mean <- array (mean(values ))
259
259
data $ prior_sd <- array (sd(values ))
@@ -705,10 +705,10 @@ sample_approx_dist <- function(cases = NULL,
705
705
direction = " backwards" ,
706
706
type = " sample" ,
707
707
truncate_future = TRUE ) {
708
- if (type %in% " sample" ) {
709
- if (direction %in% " backwards" ) {
708
+ if (type == " sample" ) {
709
+ if (direction == " backwards" ) {
710
710
direction_fn <- rev
711
- } else if (direction %in% " forwards" ) {
711
+ } else if (direction == " forwards" ) {
712
712
direction_fn <- function (x ) {
713
713
x
714
714
}
@@ -735,12 +735,12 @@ sample_approx_dist <- function(cases = NULL,
735
735
736
736
737
737
# set dates order based on direction mapping
738
- if (direction %in% " backwards" ) {
738
+ if (direction == " backwards" ) {
739
739
dates <- seq(min(cases $ date ) - lubridate :: days(length(draw ) - 1 ),
740
740
max(cases $ date ),
741
741
by = " days"
742
742
)
743
- } else if (direction %in% " forwards" ) {
743
+ } else if (direction == " forwards" ) {
744
744
dates <- seq(min(cases $ date ),
745
745
max(cases $ date ) + lubridate :: days(length(draw ) - 1 ),
746
746
by = " days"
@@ -765,17 +765,17 @@ sample_approx_dist <- function(cases = NULL,
765
765
,
766
766
cum_cases : = cumsum(cases )
767
767
][cum_cases != 0 ][, cum_cases : = NULL ]
768
- } else if (type %in% " median" ) {
768
+ } else if (type == " median" ) {
769
769
shift <- as.integer(
770
770
median(as.integer(dist_fn(1000 , dist = FALSE )), na.rm = TRUE )
771
771
)
772
772
773
- if (direction %in% " backwards" ) {
773
+ if (direction == " backwards" ) {
774
774
mapped_cases <- data.table :: copy(cases )[
775
775
,
776
776
date : = date - lubridate :: days(shift )
777
777
]
778
- } else if (direction %in% " forwards" ) {
778
+ } else if (direction == " forwards" ) {
779
779
mapped_cases <- data.table :: copy(cases )[
780
780
,
781
781
date : = date + lubridate :: days(shift )
@@ -788,7 +788,7 @@ sample_approx_dist <- function(cases = NULL,
788
788
}
789
789
790
790
# filter out future cases
791
- if (direction %in% " forwards" && truncate_future ) {
791
+ if (direction == " forwards" && truncate_future ) {
792
792
max_date <- max(cases $ date )
793
793
mapped_cases <- mapped_cases [date < = max_date ]
794
794
}
@@ -1143,7 +1143,7 @@ dist_spec_plus <- function(e1, e2, tolerance = 0.001) {
1143
1143
# ' @author Sebastian Funk
1144
1144
# ' @method c dist_spec
1145
1145
# ' @importFrom purrr transpose map
1146
- ` c.dist_spec` <- function (... ) {
1146
+ c.dist_spec <- function (... ) {
1147
1147
# # process delay distributions
1148
1148
delays <- list (... )
1149
1149
if (! (all(vapply(delays , is , FALSE , " dist_spec" )))) {
0 commit comments