R/initialize_module.R

Defines functions initialize_module

                                                      
#' @export
initialize_module <- function(x, param, init, control, s)
{  
  #Description:
  # runs  EpiModel function EpiModel::initialize.net()
  # fills in viral load values for initial infected with initialize_infecteds_vl()
  #	fills in cd4 variable values for initial infected (initial CD4 value based on SPVL)
  # with initialize_infecteds_cd4()
  #	does a few bookkeeping steps with initialize_evonet_misc()
  #	updates vl of initial infecteds (otw, vl jumps from initial value to spvl in one
  # timestep) with viral_update_module_gamma()
  #	creates and inserts initial values for "popsumm" stats (calculated at end of
  # each timestep_ with initialize_popsumm_dynamics()
  
  #sets up basic EpiModel structure
  dat  <-  EpiModel::initialize.net(x, param, init, control,s)
  
  # need to ensure that sex attribute as been copied to dat$attr from the network.
  #  ideally for consistency we'd like to have all of the attributes 
  # included on the dat$attr list.  However, when in network mode, only the 
  # attributes included in the formula (usually 'role') will be coppied
  # so need to force copy it here until we figure a better system.  
  dat$attr$status_evo <- rep(0,length(dat$attr$status))
  dat$attr$status_evo[which(dat$attr$status=="i" )] <- 1
  
  if(!is.null(dat[['nw']])){
    dat$attr$sex <- get.vertex.attribute(dat$nw,'sex')
    dat$attr$age <- get.vertex.attribute(dat$nw,'age')
    dat$attr$id <- get.vertex.attribute(dat$nw,'id')
    if(!is.logical(dat$param$generic_nodal_att_values))
    dat$attr$att1 <- get.vertex.attribute(dat$nw,'att1')
  }
  
  # likewise, if there is going to be roles in the model, need to ensure they are copied in
  if(dat$param$model_sex=="msm" && 
     (is.null(dat$attr[['role']]) & !is.null(dat[['nw']]))){
    dat$attr$role <- get.vertex.attribute(dat$nw,'role')
  }
  
  
  #if(is.null(dat$attr[['role']]) & !is.null(dat[['nw']])){
  #  dat$attr$role <- get.vertex.attribute(dat$nw,'role')
  #}
  
  #sets up agent attributes and initial values 
  dat  <-  initialize_agents(dat, 1)
  #fills in vl variable values for initial infecteds
  dat  <-  initialize_infecteds_vl(dat,1)
  #fills in cd4 variable values for initial infecteds
  #note, this must come after initialize_infecteds_vl because initial cd4 based on spvl 
  dat  <-  initialize_infecteds_cd4(dat,1)
  #does a few random bookkeeping steps
  dat  <-   initialize_evonet_misc(dat)
  #updates vl of initial infecteds (otw, jumps from initial value to spvl)
  #but shouldn't happen for aim3 runs
  if(param$VL_Function != "aim3"){
  dat  <-  viral_update_gamma(dat,1)
  dat  <-  viral_update_cd4_intial_pop(dat)
  }
  #create list, if "save_vl_list" = TRUE to save
  #individual agent's vl/cd4 values for each timestep
  dat<- summary_vl_list(dat,1)
  #creates and fills in initial values for "popsumm" stats (stats calculated at
  #end of each timestep)
  dat <- summary_popsumm(dat,1)
  #keep track of current simulation/replicate
  dat$simulation <- s
  return(dat)
}
EvoNetHIV/Herbeck-et-al-Vaccine-201x documentation built on Sept. 5, 2020, 12:32 p.m.