chimeric_tools.Simulation¶
Simulate COVID data
- class chimeric_tools.Simulation.COVID(start_date: date | str | None = None, end_date: date | str | None = None, geo_values: ndarray | Dict[str, float] | str | list | None = None, include: list | None = None, seed: None | int | Generator = None)¶
Bases:
object
Covid simulation class
- Parameters:
start_date (date, optional) – The start date of the simulation. Defaults to None.
end_date (date, optional) – The end date of the simulation. Defaults to None.
geo_values (Union[np.ndarray, Dict[str, float], str, list, None], optional) – The geo values to use. Defaults to None.
include (Union[list, None], optional) – The list of parameters to include. Defaults to to [“cases”, “deaths”, “hosps”].
seed (Union[None, int, Generator], optional) – The seed to use. Defaults to None.
- pick_geo_values(reps: int) ndarray ¶
Randomly generate geo values with probability p and repeat for reps times
- Parameters:
reps (int) – The number of times to repeat the random generation.
- Returns:
The randomly generated geo values.
- Return type:
np.ndarray
- simulate(block_length: list | ndarray | int | str, reps: int)¶
Simulate data reps times. Simulations are made by (1) using a simple model to get in-sample predictions and their respective residuals. (2) Using a block bootstrap with block length of block_length to bootstrap the residuals. (3) Adding the new residuals back to the in-sample prediction data.
- Parameters:
block_length (Union[list, np.ndarray, int, str]) – The block length of the block bootstrap./ If block_length is an integer, this is the block length that will be used for every parameter./ If block_length is a list, the each value is the block length for each parameter, thusit must be the same length as the number of parameters./ If block_length is “auto”, then the optimal block length will be used for each parameter./
reps (int) – The number of times to repeat the simulation.
- Returns:
The simulated data in the form of a dataframe. The dataframe will contain the predictions and residuals used for each parameter along witht he simulated data. The column sim distinguishes what number simulation it is.
- Return type:
pd.DataFrame
- chimeric_tools.Simulation.optimal_block_length(x: ndarray | Series | DataFrame)¶
This is a wrapper function for arch.boostrap.optimal_block_length It returns the optimal block length for the given data.
- Parameters:
x (Union[np.ndarray, pd.Series, pd.DataFrame]) – The data to be used for the optimal block length.
- Return type:
pd.Series