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)

# Offset extreme substructure only for Nonstationary model
net.offset_extremes()

print 'Fitting nonstationary model'
ns_model = NonstationaryLogistic()
for cov_name in cov_names:
    ns_model.beta[cov_name] = None
ns_model.fit(net)
print 'NLL: %.2f' % ns_model.nll(net)
print 'kappa: %.2f' % ns_model.kappa
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, ns_model.beta[cov_name])
Exemplo n.º 2
0
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)

# Offset extreme substructure only for Nonstationary model
net.offset_extremes()

print 'Fitting nonstationary model'
ns_model = NonstationaryLogistic()
for cov_name in cov_names:
    ns_model.beta[cov_name] = None
ns_model.fit(net)
print 'NLL: %.2f' % ns_model.nll(net)
print 'kappa: %.2f' % ns_model.kappa
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, ns_model.beta[cov_name])
Exemplo n.º 3
0
    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']
    if cs_ci_l < theta < cs_ci_u:
        cs_covered += 1

    c_fit.confidence_cons(new, 'x_0', alpha_level = alpha_level, L = 61,
                          test = 'lr')
    cl_ci_l, cl_ci_u = c_fit.conf['x_0']['conservative-lr']
    if cl_ci_l < theta < cl_ci_u:
        cl_covered += 1

print 'Wald (stationary): %.2f' % (1.0 * ws_covered / n_rep)
print 'Wald (nonstationary): %.2f' % (1.0 * wn_covered / n_rep)
print 'Wald (conditional): %.2f' % (1.0 * wc_covered / n_rep)
print 'Bootstrap (stationary): %.2f' % (1.0 * bs_covered / n_rep)
print 'Bootstrap (nonstationary): %.2f' % (1.0 * bn_covered / n_rep)