예제 #1
0
def senstivity_check():
    # 8) Check Monte Carlo Bias Analysis
    np.random.seed(101)
    mcrr = MonteCarloRR(observed_RR=0.73322, sample=10000)
    mcrr.confounder_RR_distribution(trapezoidal(mini=0.9, mode1=1.1, mode2=1.7, maxi=1.8, size=10000))
    mcrr.prop_confounder_exposed(trapezoidal(mini=0.25, mode1=0.28, mode2=0.32, maxi=0.35, size=10000))
    mcrr.prop_confounder_unexposed(trapezoidal(mini=0.55, mode1=0.58, mode2=0.62, maxi=0.65, size=10000))
    mcrr.fit()
    mcrr.plot()
    plt.show()
예제 #2
0
 def mcba(self):
     np.random.seed(101)
     mcrr = MonteCarloRR(observed_RR=0.73322, sample=10000)
     mcrr.confounder_RR_distribution(
         trapezoidal(mini=0.9, mode1=1.1, mode2=1.7, maxi=1.8, size=10000))
     mcrr.prop_confounder_exposed(
         trapezoidal(mini=0.25,
                     mode1=0.28,
                     mode2=0.32,
                     maxi=0.35,
                     size=10000))
     mcrr.prop_confounder_unexposed(
         trapezoidal(mini=0.55,
                     mode1=0.58,
                     mode2=0.62,
                     maxi=0.65,
                     size=10000))
     mcrr.fit()
     return mcrr
예제 #3
0
n = 3000  # size of each sample
sims = 2000  # number of repeated samples
np.random.seed(1015033030)

######################################
# Generating data
######################################
ids = []  # Generating simulation IDs
for i in range(sims):
    ids.extend([i + 1] * n)

df = pd.DataFrame()
df['sim_id'] = ids

# Creating confounders
df['age'] = np.round(trapezoidal(40, 40, 60, 75, size=n * sims),
                     0)  # trapezoidal distribution
df['ldl_log'] = 0.005 * df['age'] + np.random.normal(
    np.log(100), 0.18, size=n * sims)
df['diabetes'] = np.random.binomial(
    n=1,
    p=logistic.cdf(-4.23 + 0.03 * df['ldl_log'] - 0.02 * df['age'] +
                   0.0009 * df['age']**2),
    size=n * sims)
df['frailty'] = logistic.cdf(-5.5 + 0.05 * (df['age'] - 20) +
                             0.001 * df['age']**2 +
                             np.random.normal(size=n * sims))
df['age_ln'] = np.log(df['age'])
df['risk_score'] = logistic.cdf(4.299 + 3.501 * df['diabetes'] -
                                2.07 * df['age_ln'] + 0.051 * df['age_ln']**2 +
                                4.090 * df['ldl_log'] -
예제 #4
0
 def test_minimum(self):
     n = trapezoidal(mini=0.9, mode1=1.1, mode2=1.7, maxi=1.8, size=10000)
     assert np.min(n) >= 0.9
예제 #5
0
lower = np.random.RandomState(80412).uniform(-0.1, 0.1, size=100)
upper = lower + np.random.RandomState(192041).uniform(0.1, 0.2, size=100)

zipper_plot(truth=0, lcl=lower, ucl=upper, colors=('blue', 'green'))
plt.tight_layout()
plt.savefig("../images/zipper_example.png", format='png', dpi=300)
plt.close()

#####################################################################################################################
# Sensitivity
#####################################################################################################################
print("Running sensitivity...")

from zepid.sensitivity_analysis import trapezoidal

plt.hist(trapezoidal(mini=1, mode1=1.5, mode2=3, maxi=3.5, size=250000),
         bins=100)
plt.tight_layout()
plt.savefig("../images/zepid_trapezoid.png", format='png', dpi=300)
plt.close()

from zepid.sensitivity_analysis import MonteCarloRR

mcrr = MonteCarloRR(observed_RR=0.73322, sample=10000)
mcrr.confounder_RR_distribution(
    trapezoidal(mini=0.9, mode1=1.1, mode2=1.7, maxi=1.8, size=10000))
mcrr.prop_confounder_exposed(
    trapezoidal(mini=0.25, mode1=0.28, mode2=0.32, maxi=0.35, size=10000))
mcrr.prop_confounder_unexposed(
    trapezoidal(mini=0.55, mode1=0.58, mode2=0.62, maxi=0.65, size=10000))
mcrr.fit()