Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024-08-07 update : adding matrix normalization func. and using AR1 in spatial func. #53

19 changes: 12 additions & 7 deletions R/generate_simulated_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
#' scaling factor.
#' @param init_bool Boolean for making initial value of AUX site AR(1)
#' process stationary( 1 or 0 ).
cbernalz marked this conversation as resolved.
Show resolved Hide resolved
#' @param init_stat Boolean. Should the initial value of the AR(1) be drawn
#' from the process's stationary distribution (`TRUE`) or from the process's
#' conditional error distribution (`FALSE`)? Note that the process only has
#' a defined stationary distribution if `state_deviation_ar_coeff` < 1.
cbernalz marked this conversation as resolved.
Show resolved Hide resolved
#' Default `FALSE`.
dylanhmorris marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @return a list containing three dataframes. hosp_data is a dataframe
#' containing the number of daily hospital admissions by day for a theoretical
Expand Down Expand Up @@ -104,7 +109,7 @@
#' sigma_eps = sqrt(0.02),
#' scaling_factor = 0.01,
#' aux_site_bool = TRUE,
#' init_bool = TRUE
#' init_stat = TRUE
#' )
#' hosp_data <- sim_data$hosp_data
#' ww_data <- sim_data$ww_data
Expand Down Expand Up @@ -165,7 +170,7 @@ generate_simulated_data <- function(r_in_weeks = # nolint
sigma_eps = sqrt(0.02),
scaling_factor = 0.01,
aux_site_bool = TRUE,
init_bool = TRUE) {
init_stat = TRUE) {
# Some quick checks to make sure the inputs work as expected
stopifnot(
"weekly R(t) passed in isn't long enough" =
Expand Down Expand Up @@ -370,17 +375,17 @@ generate_simulated_data <- function(r_in_weeks = # nolint
)
# Auxiliary Site
if (aux_site_bool) {
state_deviation_noise_vec <- state_deviation_noise_vec_aux_rng(
1,
1,
n_weeks
state_deviation_noise_vec <- rnorm(
n = n_time,
mean = 0,
sd = 0
cbernalz marked this conversation as resolved.
Show resolved Hide resolved
)
log_r_site_aux <- construct_aux_rt(log_r_state_week,
state_deviation_ar_coeff = phi_rt,
scaling_factor,
sigma_eps,
dylanhmorris marked this conversation as resolved.
Show resolved Hide resolved
state_deviation_noise_vec,
init_bool
init_stat
)
log_r_site <- rbind(
log_r_site,
Expand Down
11 changes: 5 additions & 6 deletions inst/stan/functions/aux_site_process_rng.stan
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@
* of spatial epsilon.
* @param state_deviation_ar_coeff Coefficient for AR(1) temporal correlation on
* state deviations for aux site.
* @param init_bool Boolean for making initial value stationary( 1 or 0 ).
* @param init_stat Boolean. Should the initial value of the AR(1) be drawn
* from the process's.
cbernalz marked this conversation as resolved.
Show resolved Hide resolved
* @return A vector for unadjusted Rt for aux site where columns are time points.
*/
vector aux_site_process_rng(vector log_state_rt,
real scaling_factor,
real sigma_eps,
real state_deviation_ar_coeff,
int init_bool) {
int init_stat) {


//Presets
int n_time = size(log_state_rt);

// creates vector of standard normal for contruct aux rt.
vector[n_time] z = state_deviation_noise_vec_aux_rng(1,
1,
n_time);
vector[n_time] z = standard_normal_rng();
cbernalz marked this conversation as resolved.
Show resolved Hide resolved
vector[n_time] log_aux_site_rt = construct_aux_rt(log_state_rt,
state_deviation_ar_coeff,
scaling_factor,
sigma_eps,
z,
init_bool);
init_stat);

return log_aux_site_rt;
}
10 changes: 8 additions & 2 deletions man/generate_simulated_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading