Exemplo n.º 1
0
def ci_cmle_boot(X, v, alpha_level):
    arr = array_from_data(X, [v])

    A = arr.as_dense()
    r = A.sum(1)
    c = A.sum(0)
    
    s_model = StationaryLogistic()
    s_model.beta['x_0'] = None
    fit_model = FixedMargins(s_model)
    arr.new_row_covariate('r', np.int)[:] = r
    arr.new_col_covariate('c', np.int)[:] = c
    fit_model.fit = fit_model.base_model.fit_conditional

    fit_model.confidence_boot(arr, alpha_level = alpha_level)

    return fit_model.conf['x_0']['pivotal']
Exemplo n.º 2
0
def ci_cmle_wald(X, v, alpha_level):
    arr = array_from_data(X, [v])

    A = arr.as_dense()
    r = A.sum(1)
    c = A.sum(0)

    s_model = StationaryLogistic()
    s_model.beta["x_0"] = None
    fit_model = FixedMargins(s_model)
    arr.new_row_covariate("r", np.int)[:] = r
    arr.new_col_covariate("c", np.int)[:] = c
    fit_model.fit = fit_model.base_model.fit_conditional

    fit_model.confidence_wald(arr, alpha_level=alpha_level)

    return safe_ci(fit_model, "x_0", "wald")
Exemplo n.º 3
0
print 'NLL: %.2f' % s_model.nll(net)
print 'kappa: %.2f' % s_model.kappa
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, s_model.beta[cov_name])
print
for rep in range(params['n_samples']):
    s_samples[rep,:,:] = s_model.generate(net)
s_model.confidence_boot(net, n_bootstrap = params['n_bootstrap'])
s_model.confidence_wald(net)
display_cis(s_model)

print 'Fitting conditional model'
c_model = FixedMargins(StationaryLogistic())
net.new_row_covariate('r', np.int)[:] = r
net.new_col_covariate('c', np.int)[:] = c
c_model.fit = c_model.base_model.fit_conditional
for cov_name in cov_names:
    c_model.base_model.beta[cov_name] = None
c_model.fit(net)
print 'NLL: %.2f' % c_model.nll(net)
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, c_model.base_model.beta[cov_name])
print
for rep in range(params['n_samples']):
    c_samples[rep,:,:] = c_model.generate(net, coverage = 0.1)
c_model.confidence_boot(net, n_bootstrap = params['n_bootstrap'])
c_model.confidence_wald(net)
for cov_name in cov_names:
    c_model.confidence_cons(net, cov_name, L = 121, test = 'score')
    c_model.confidence_cons(net, cov_name, L = 121, test = 'lr')
display_cis(c_model)
print 'NLL: %.2f' % s_model.nll(net)
print 'kappa: %.2f' % s_model.kappa
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, s_model.beta[cov_name])
print
for rep in range(params['n_samples']):
    s_samples[rep, :, :] = s_model.generate(net)
s_model.confidence_boot(net, n_bootstrap=params['n_bootstrap'])
s_model.confidence_wald(net)
display_cis(s_model)

print 'Fitting conditional model'
c_model = FixedMargins(StationaryLogistic())
net.new_row_covariate('r', np.int)[:] = r
net.new_col_covariate('c', np.int)[:] = c
c_model.fit = c_model.base_model.fit_conditional
for cov_name in cov_names:
    c_model.base_model.beta[cov_name] = None
c_model.fit(net, verbose=True)
print 'NLL: %.2f' % c_model.nll(net)
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, c_model.base_model.beta[cov_name])
print
for rep in range(params['n_samples']):
    c_samples[rep, :, :] = c_model.generate(net, coverage=0.1)
c_model.confidence_boot(net, n_bootstrap=params['n_bootstrap'])
c_model.confidence_wald(net)
for cov_name in cov_names:
    c_model.confidence_cons(net, cov_name, L=121, test='score')
    c_model.confidence_cons(net, cov_name, L=121, test='lr')
display_cis(c_model)
Exemplo n.º 5
0
print 'NLL: %.2f' % s_model.nll(net)
print 'kappa: %.2f' % s_model.kappa
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, s_model.beta[cov_name])
print
for rep in range(params['n_samples']):
    s_samples[rep, :, :] = s_model.generate(net)
s_model.confidence_boot(net, n_bootstrap=params['n_bootstrap'])
s_model.confidence_wald(net)
display_cis(s_model)

print 'Fitting conditional model'
c_model = FixedMargins(StationaryLogistic())
net.new_row_covariate('r', np.int)[:] = r
net.new_col_covariate('c', np.int)[:] = c
c_model.fit = c_model.base_model.fit_conditional
for cov_name in cov_names:
    c_model.base_model.beta[cov_name] = None
c_model.fit(net)
print 'NLL: %.2f' % c_model.nll(net)
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, c_model.base_model.beta[cov_name])
print
for rep in range(params['n_samples']):
    c_samples[rep, :, :] = c_model.generate(net, coverage=0.1)
c_model.confidence_boot(net, n_bootstrap=params['n_bootstrap'])
c_model.confidence_wald(net)
for cov_name in cov_names:
    c_model.confidence_cons(net, cov_name, L=121, test='score')
    c_model.confidence_cons(net, cov_name, L=121, test='lr')
display_cis(c_model)
Exemplo n.º 6
0
        wn_covered += 1

    ns_fit.confidence_boot(new, n_bootstrap = n_boot,
                           alpha_level = alpha_level)
    bn_ci_l, bn_ci_u = ns_fit.conf['x_0']['pivotal']
    if bn_ci_l < theta < bn_ci_u:
        bn_covered += 1

    A = new.as_dense()
    r = A.sum(1)
    c = A.sum(0)

    c_fit = FixedMargins(s_fit)
    new.new_row_covariate('r', np.int)[:] = r
    new.new_col_covariate('c', np.int)[:] = c
    c_fit.fit = c_fit.base_model.fit_conditional

    c_fit.reset_confidence()
    c_fit.confidence_wald(new)
    wc_ci_l, wc_ci_u = safe_ci(c_fit, 'x_0', 'wald')
    if wc_ci_l < theta < wc_ci_u:
        wc_covered += 1

    c_fit.confidence_boot(new, n_bootstrap = n_boot, alpha_level = alpha_level)
    bc_ci_l, bc_ci_u = c_fit.conf['x_0']['pivotal']
    if bc_ci_l < theta < bc_ci_u:
        bc_covered += 1

    c_fit.confidence_cons(new, 'x_0', alpha_level = alpha_level, L = 61,
                          test = 'score')
    cs_ci_l, cs_ci_u = c_fit.conf['x_0']['conservative-score']
print 'NLL: %.2f' % s_model.nll(net)
print 'kappa: %.2f' % s_model.kappa
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, s_model.beta[cov_name])
print
for rep in range(params['n_samples']):
    s_samples[rep,:,:] = s_model.generate(net)
s_model.confidence_boot(net, n_bootstrap = params['n_bootstrap'])
s_model.confidence_wald(net)
display_cis(s_model)

print 'Fitting conditional model'
c_model = FixedMargins(StationaryLogistic())
net.new_row_covariate('r', np.int)[:] = r
net.new_col_covariate('c', np.int)[:] = c
c_model.fit = c_model.base_model.fit_conditional
for cov_name in cov_names:
    c_model.base_model.beta[cov_name] = None
c_model.fit(net, verbose = True)
print 'NLL: %.2f' % c_model.nll(net)
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, c_model.base_model.beta[cov_name])
print
for rep in range(params['n_samples']):
    c_samples[rep,:,:] = c_model.generate(net, coverage = 0.1)
c_model.confidence_boot(net, n_bootstrap = params['n_bootstrap'])
c_model.confidence_wald(net)
for cov_name in cov_names:
    c_model.confidence_cons(net, cov_name, L = 121, test = 'score')
    c_model.confidence_cons(net, cov_name, L = 121, test = 'lr')
display_cis(c_model)