def __init__(self, diagnostic): self.diagnostic = diagnostic self.probInfectedRVG = None # list of dirichlet distributions for moving out of the infected state self.probAlphaRVG = None # list of beta distributions for the alpha probability if the diagnostic test is NSB self.weeklyStateCostRVG = [ ] # list of gamma distributions for the annual cost of states self.singleStateCostRVG = [ ] # list of gamma distributions for the single cost of states # create Dirichlet distributions for transition probabilities self.probInfectedRVG = RVGs.Dirichlet(a=[ Data.P_INFECTED_CLEARED, Data.P_INFECTED_TBD, Data.P_INFECTED_TBM ]) # crate beta distribution for the alpha probability if self.diagnostic == Diagnostic.SOC: fit_output = MM.get_beta_params(mean=Data.P_DX_SOC, st_dev=Data.P_DX_SOC / 5) else: fit_output = MM.get_beta_params(mean=Data.P_DX_NSB, st_dev=Data.P_DX_NSB / 5) self.probAlphaRVG = RVGs.Beta(a=fit_output["a"], b=fit_output["b"]) # create gamma distributions for annual state cost for cost in Data.WEEKLY_STATE_COST: # if cost is zero, add a constant 0, otherwise add a gamma distribution if cost == 0: self.weeklyStateCostRVG.append(RVGs.Constant(value=0)) else: # find shape and scale of the assumed gamma distribution # no data available to estimate the standard deviation, so we assumed st_dev=cost / 5 fit_output = MM.get_gamma_params(mean=cost, st_dev=cost / 5) # append the distribution self.weeklyStateCostRVG.append( RVGs.Gamma(a=fit_output["a"], loc=0, scale=fit_output["scale"])) # create gamma distributions for single state cost if self.diagnostic == Diagnostic.SOC: single_cost = Data.SOC_ONE_TIME_COST else: single_cost = Data.NSB_ONE_TIME_COST for cost in single_cost: # if cost is zero, add a constant 0, otherwise add a gamma distribution if cost == 0: self.singleStateCostRVG.append(RVGs.Constant(value=0)) else: # find shape and scale of the assumed gamma distribution # no data available to estimate the standard deviation, so we assumed st_dev=cost / 5 fit_output = MM.get_gamma_params(mean=cost, st_dev=cost / 5) # append the distribution self.singleStateCostRVG.append( RVGs.Gamma(a=fit_output["a"], loc=0, scale=fit_output["scale"]))
def __init__(self, therapy): self.therapy = therapy self.probMatrixRVG = [ ] # list of dirichlet distributions for transition probabilities self.lnRelativeRiskRVG = None # normal distribution for the natural log of the treatment relative risk self.annualStateCostRVG = [ ] # list of gamma distributions for the annual cost of states self.annualStateUtilityRVG = [ ] # list of beta distributions for the annual utility of states # create Dirichlet distributions for transition probabilities j = 0 for prob in Data.PROB_MATRIX: self.probMatrixRVG.append(RVGs.Dirichlet(a=prob[j:])) j += 1 # treatment relative risk rr_ci = [1.2, 3] # confidence interval of the treatment relative risk # find the mean and st_dev of the normal distribution assumed for ln(RR) # sample mean ln(RR) mean_ln_rr = math.log(Data.TREATMENT_RR) # sample standard deviation of ln(RR) std_ln_rr = \ (math.log(rr_ci[1]) - math.log(rr_ci[0])) / (2 * stat.norm.ppf(1 - 0.05 / 2)) # create a normal distribution for ln(RR) self.lnRelativeRiskRVG = RVGs.Normal(loc=mean_ln_rr, scale=std_ln_rr) # create gamma distributions for annual state cost for cost in Data.ANNUAL_STATE_COST_NO: # if cost is zero, add a constant 0, otherwise add a gamma distribution if cost == 0: self.annualStateCostRVG.append(RVGs.Constant(value=0)) else: # find shape and scale of the assumed gamma distribution # no data available to estimate the standard deviation, so we assumed st_dev=cost / 5 fit_output = MM.get_gamma_params(mean=cost, st_dev=cost / 5) # append the distribution self.annualStateCostRVG.append( RVGs.Gamma(a=fit_output["a"], loc=0, scale=fit_output["scale"])) # create beta distributions for annual state utility for utility in Data.ANNUAL_STATE_UTILITY_0: # if utility is zero, add a constant 0, otherwise add a beta distribution if utility == 0: self.annualStateCostRVG.append(RVGs.Constant(value=0)) else: # find alpha and beta of the assumed beta distribution # no data available to estimate the standard deviation, so we assumed st_dev=cost / 4 fit_output = MM.get_beta_params(mean=utility, st_dev=utility / 4) # append the distribution self.annualStateUtilityRVG.append( RVGs.Beta(a=fit_output["a"], b=fit_output["b"]))
def test_beta(rnd, a, b, loc=0, scale=1): # beta random variate generator beta_dist = RVGs.Beta(a, b, loc, scale) # obtain samples samples = get_samples(beta_dist, rnd) # report mean and variance print_test_results('Beta', samples, expectation=(a * 1.0 / (a + b)) * scale + loc, variance=((a * b) / ((a + b + 1) * (a + b)**2.0)) * scale**2)
def __init__(self): self.hospdaycost = None self.fadcost = None self.sadcost = None self.icucost = None self.sequtility = None # annual state utilities self.hosputility = None self.rsvinfection = None # list of dirichlet distributions for transition probabilities self.lnRelativeRiskRVG = None self.probnhpd = None # normal distribution for the natural log of the treatment relative risk self.probhops = None self.probICU = None self.probhpd = None self.probseq = None self.weight = None self.hoptime = None self.icutime = None # hospital cost # per unit P cost # utility hua = MM.get_beta_params(mean=Data.hospital_utility, st_dev=0.07) self.hosputility = RVGs.Beta(a=hua["a"], b=hua["b"]) nhu = MM.get_beta_params(mean=Data.rsv_nh_u, st_dev=0.07) # append the distribution self.rsvinfection = RVGs.Beta(a=nhu["a"], b=nhu["b"]) seq = MM.get_beta_params(mean=Data.Asthma_utility, st_dev=0.07) # append the distribution self.sequtility = RVGs.Beta(a=seq["a"], b=seq["b"]) ##### cost hos = MM.get_gamma_params(mean=Data.cost_hos, st_dev=149) # append the distribution self.hospdaycost = RVGs.Gamma(a=hos["a"], loc=0, scale=hos["scale"]) icu = MM.get_gamma_params(mean=Data.ICU, st_dev=271) # append the distribution self.icucost = RVGs.Gamma(a=icu["a"], loc=0, scale=icu["scale"]) sad = MM.get_gamma_params(mean=Data.sadcost, st_dev=5) # append the distribution self.sadcost = RVGs.Gamma(a=sad["a"], loc=0, scale=icu["scale"]) fad = MM.get_gamma_params(mean=Data.fadcost, st_dev=6) # append the distribution self.fadcost = RVGs.Gamma(a=fad["a"], loc=0, scale=icu["scale"]) ##### prob hp = MM.get_beta_params(mean=Data.hos_rate, st_dev=0.023) # append the distribution self.probhops = RVGs.Beta(a=hp["a"], b=hp["b"]) hu = MM.get_beta_params(mean=Data.prob_ICU, st_dev=0.0967) # append the distribution self.probICU = RVGs.Beta(a=hu["a"], b=hu["b"]) dea = MM.get_beta_params(mean=Data.Hos_MORTALITY_PROB, st_dev=0.0253) # append the distribution self.probhpd = RVGs.Beta(a=dea["a"], b=dea["b"]) se = MM.get_beta_params(mean=Data.prob_seq, st_dev=0.115) # append the distribution self.probseq = RVGs.Beta(a=se["a"], b=se["b"]) de = MM.get_beta_params(mean=Data.death_rate, st_dev=0.0004836235) self.probnhpd = RVGs.Beta(a=de["a"], b=de["b"]) ### stay time hoss = MM.get_gamma_params(mean=Data.hoptime, st_dev=3.1) # append the distribution self.hoptime = RVGs.Gamma(a=hoss["a"], loc=0, scale=hoss["scale"]) ic = MM.get_gamma_params(mean=Data.icutime, st_dev=3.8) # append the distribution self.icutime = RVGs.Gamma(a=ic["a"], loc=0, scale=ic["scale"]) ## weight we = MM.get_gamma_params(mean=Data.weight, st_dev=392) # append the distribution self.weight = RVGs.Gamma(a=we["a"], loc=0, scale=we["scale"]) rr_ci = [0.181, 0.634] # confidence interval of the treatment relative risk # find the mean and st_dev of the normal distribution assumed for ln(RR) # sample mean ln(RR) mean_ln_rr = math.log(0.453) # sample standard deviation of ln(RR) std_ln_rr = \ (math.log(rr_ci[1]) - math.log(rr_ci[0])) / (2 * stat.norm.ppf(1 - 0.05 / 2)) # create a normal distribution for ln(RR) self.lnRelativeRiskRVG = RVGs.Normal(loc=mean_ln_rr, scale=std_ln_rr)
import numpy as np import SimPy.RandomVariantGenerators as RVGs from tests.ProbDistributions.RVGtests import get_samples import scipy.stats as scs # simulate some data np.random.seed(1) # 1 fitting a exponential distribution dist = RVGs.Exponential(5, 1) dat_exp = np.array(get_samples(dist, np.random)) # generate data dictResults = Fit.fit_exp(dat_exp, 'Data', fixed_location=1) # fit print("Fitting Exponential:", dictResults) # 2 fitting a beta distribution dist = RVGs.Beta(2, 3, loc=1, scale=2) dat_beta = np.array(get_samples(dist, np.random)) # generate data dictResults = Fit.fit_beta(dat_beta, 'Data', minimum=1, maximum=3) # fit print("Fitting Beta:", dictResults) # 3 fitting a beta-binomial distribution dist = RVGs.BetaBinomial(100, 2, 3, loc=1, scale=2) # n, a, b dat_betabin = np.array(get_samples(dist, np.random)) dictResults = Fit.fit_beta_binomial(dat_betabin, 'Data', fixed_location=1, fixed_scale=2) # fit print("Fitting BetaBinomial:", dictResults) # 4 Binomial dist = RVGs.Binomial(100, 0.3, 1)
def __init__(self, seed): self.rng = RVGs.RNG(seed=seed) self.beta = RVGs.Beta(a=1, b=2) self.sum = 0 self.seed = seed