Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__init__.py +3 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/_diagnostics_count.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/conditional_models.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/count_model.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/diagnostic.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/discrete_margins.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/truncated_model.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/_diagnostics_count.py +605 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/conditional_models.py +634 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/count_model.py +1140 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/diagnostic.py +250 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/discrete_margins.py +732 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/discrete_model.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__init__.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_conditional.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_constrained.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_count_model.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_diagnostic.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_discrete.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_margins.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_predict.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_sandwich_cov.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_truncated_model.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__init__.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_count_margins.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_count_robust_cluster.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_discrete.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_glm_logit_constrained.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_poisson_constrained.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_predict.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_truncated.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_truncated_st.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/mn_logit_summary.txt +49 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/mnlogit_resid.csv +1 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/nbinom_resids.csv +20 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/phat_mnlogit.csv +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/poisson_resid.csv +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/predict_prob_poisson.csv +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_count_margins.py +394 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_count_robust_cluster.py +689 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_discrete.py +1257 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_glm_logit_constrained.py +697 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_poisson_constrained.py +665 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_predict.py +253 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_truncated.py +60 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_truncated_st.py +746 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/ships.csv +41 -0
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__init__.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from statsmodels.tools._test_runner import PytestTester
|
| 2 |
+
|
| 3 |
+
test = PytestTester()
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (275 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/_diagnostics_count.cpython-310.pyc
ADDED
|
Binary file (16.6 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/conditional_models.cpython-310.pyc
ADDED
|
Binary file (16.4 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/count_model.cpython-310.pyc
ADDED
|
Binary file (32.9 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/diagnostic.cpython-310.pyc
ADDED
|
Binary file (8.52 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/discrete_margins.cpython-310.pyc
ADDED
|
Binary file (21 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/__pycache__/truncated_model.cpython-310.pyc
ADDED
|
Binary file (36.2 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/_diagnostics_count.py
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Created on Fri Sep 15 12:53:45 2017
|
| 3 |
+
|
| 4 |
+
Author: Josef Perktold
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
from scipy import stats
|
| 9 |
+
|
| 10 |
+
import pandas as pd
|
| 11 |
+
|
| 12 |
+
from statsmodels.stats.base import HolderTuple
|
| 13 |
+
from statsmodels.discrete.discrete_model import Poisson
|
| 14 |
+
from statsmodels.regression.linear_model import OLS
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def _combine_bins(edge_index, x):
|
| 18 |
+
"""group columns into bins using sum
|
| 19 |
+
|
| 20 |
+
This is mainly a helper function for combining probabilities into cells.
|
| 21 |
+
It similar to `np.add.reduceat(x, edge_index, axis=-1)` except for the
|
| 22 |
+
treatment of the last index and last cell.
|
| 23 |
+
|
| 24 |
+
Parameters
|
| 25 |
+
----------
|
| 26 |
+
edge_index : array_like
|
| 27 |
+
This defines the (zero-based) indices for the columns that are be
|
| 28 |
+
combined. Each index in `edge_index` except the last is the starting
|
| 29 |
+
index for a bin. The largest index in a bin is the next edge_index-1.
|
| 30 |
+
x : 1d or 2d array
|
| 31 |
+
array for which columns are combined. If x is 1-dimensional that it
|
| 32 |
+
will be treated as a 2-d row vector.
|
| 33 |
+
|
| 34 |
+
Returns
|
| 35 |
+
-------
|
| 36 |
+
x_new : ndarray
|
| 37 |
+
k_li : ndarray
|
| 38 |
+
Count of columns combined in bin.
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
Examples
|
| 42 |
+
--------
|
| 43 |
+
>>> dia.combine_bins([0,1,5], np.arange(4))
|
| 44 |
+
(array([0, 6]), array([1, 4]))
|
| 45 |
+
|
| 46 |
+
this aggregates to two bins with the sum of 1 and 4 elements
|
| 47 |
+
>>> np.arange(4)[0].sum()
|
| 48 |
+
0
|
| 49 |
+
>>> np.arange(4)[1:5].sum()
|
| 50 |
+
6
|
| 51 |
+
|
| 52 |
+
If the rightmost index is smaller than len(x)+1, then the remaining
|
| 53 |
+
columns will not be included.
|
| 54 |
+
|
| 55 |
+
>>> dia.combine_bins([0,1,3], np.arange(4))
|
| 56 |
+
(array([0, 3]), array([1, 2]))
|
| 57 |
+
"""
|
| 58 |
+
x = np.asarray(x)
|
| 59 |
+
if x.ndim == 1:
|
| 60 |
+
is_1d = True
|
| 61 |
+
x = x[None, :]
|
| 62 |
+
else:
|
| 63 |
+
is_1d = False
|
| 64 |
+
xli = []
|
| 65 |
+
kli = []
|
| 66 |
+
for bin_idx in range(len(edge_index) - 1):
|
| 67 |
+
i, j = edge_index[bin_idx : bin_idx + 2]
|
| 68 |
+
xli.append(x[:, i:j].sum(1))
|
| 69 |
+
kli.append(j - i)
|
| 70 |
+
|
| 71 |
+
x_new = np.column_stack(xli)
|
| 72 |
+
if is_1d:
|
| 73 |
+
x_new = x_new.squeeze()
|
| 74 |
+
return x_new, np.asarray(kli)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def plot_probs(freq, probs_predicted, label='predicted', upp_xlim=None,
|
| 78 |
+
fig=None):
|
| 79 |
+
"""diagnostic plots for comparing two lists of discrete probabilities
|
| 80 |
+
|
| 81 |
+
Parameters
|
| 82 |
+
----------
|
| 83 |
+
freq, probs_predicted : nd_arrays
|
| 84 |
+
two arrays of probabilities, this can be any probabilities for
|
| 85 |
+
the same events, default is designed for comparing predicted
|
| 86 |
+
and observed probabilities
|
| 87 |
+
label : str or tuple
|
| 88 |
+
If string, then it will be used as the label for probs_predicted and
|
| 89 |
+
"freq" is used for the other probabilities.
|
| 90 |
+
If label is a tuple of strings, then the first is they are used as
|
| 91 |
+
label for both probabilities
|
| 92 |
+
|
| 93 |
+
upp_xlim : None or int
|
| 94 |
+
If it is not None, then the xlim of the first two plots are set to
|
| 95 |
+
(0, upp_xlim), otherwise the matplotlib default is used
|
| 96 |
+
fig : None or matplotlib figure instance
|
| 97 |
+
If fig is provided, then the axes will be added to it in a (3,1)
|
| 98 |
+
subplots, otherwise a matplotlib figure instance is created
|
| 99 |
+
|
| 100 |
+
Returns
|
| 101 |
+
-------
|
| 102 |
+
Figure
|
| 103 |
+
The figure contains 3 subplot with probabilities, cumulative
|
| 104 |
+
probabilities and a PP-plot
|
| 105 |
+
"""
|
| 106 |
+
|
| 107 |
+
if isinstance(label, list):
|
| 108 |
+
label0, label1 = label
|
| 109 |
+
else:
|
| 110 |
+
label0, label1 = 'freq', label
|
| 111 |
+
|
| 112 |
+
if fig is None:
|
| 113 |
+
import matplotlib.pyplot as plt
|
| 114 |
+
fig = plt.figure(figsize=(8,12))
|
| 115 |
+
ax1 = fig.add_subplot(311)
|
| 116 |
+
ax1.plot(freq, '-o', label=label0)
|
| 117 |
+
ax1.plot(probs_predicted, '-d', label=label1)
|
| 118 |
+
if upp_xlim is not None:
|
| 119 |
+
ax1.set_xlim(0, upp_xlim)
|
| 120 |
+
ax1.legend()
|
| 121 |
+
ax1.set_title('probabilities')
|
| 122 |
+
|
| 123 |
+
ax2 = fig.add_subplot(312)
|
| 124 |
+
ax2.plot(np.cumsum(freq), '-o', label=label0)
|
| 125 |
+
ax2.plot(np.cumsum(probs_predicted), '-d', label=label1)
|
| 126 |
+
if upp_xlim is not None:
|
| 127 |
+
ax2.set_xlim(0, upp_xlim)
|
| 128 |
+
ax2.legend()
|
| 129 |
+
ax2.set_title('cumulative probabilities')
|
| 130 |
+
|
| 131 |
+
ax3 = fig.add_subplot(313)
|
| 132 |
+
ax3.plot(np.cumsum(probs_predicted), np.cumsum(freq), 'o')
|
| 133 |
+
ax3.plot(np.arange(len(freq)) / len(freq), np.arange(len(freq)) / len(freq))
|
| 134 |
+
ax3.set_title('PP-plot')
|
| 135 |
+
ax3.set_xlabel(label1)
|
| 136 |
+
ax3.set_ylabel(label0)
|
| 137 |
+
return fig
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def test_chisquare_prob(results, probs, bin_edges=None, method=None):
|
| 141 |
+
"""
|
| 142 |
+
chisquare test for predicted probabilities using cmt-opg
|
| 143 |
+
|
| 144 |
+
Parameters
|
| 145 |
+
----------
|
| 146 |
+
results : results instance
|
| 147 |
+
Instance of a count regression results
|
| 148 |
+
probs : ndarray
|
| 149 |
+
Array of predicted probabilities with observations
|
| 150 |
+
in rows and event counts in columns
|
| 151 |
+
bin_edges : None or array
|
| 152 |
+
intervals to combine several counts into cells
|
| 153 |
+
see combine_bins
|
| 154 |
+
|
| 155 |
+
Returns
|
| 156 |
+
-------
|
| 157 |
+
(api not stable, replace by test-results class)
|
| 158 |
+
statistic : float
|
| 159 |
+
chisquare statistic for tes
|
| 160 |
+
p-value : float
|
| 161 |
+
p-value of test
|
| 162 |
+
df : int
|
| 163 |
+
degrees of freedom for chisquare distribution
|
| 164 |
+
extras : ???
|
| 165 |
+
currently returns a tuple with some intermediate results
|
| 166 |
+
(diff, res_aux)
|
| 167 |
+
|
| 168 |
+
Notes
|
| 169 |
+
-----
|
| 170 |
+
|
| 171 |
+
Status : experimental, no verified unit tests, needs to be generalized
|
| 172 |
+
currently only OPG version with auxiliary regression is implemented
|
| 173 |
+
|
| 174 |
+
Assumes counts are np.arange(probs.shape[1]), i.e. consecutive
|
| 175 |
+
integers starting at zero.
|
| 176 |
+
|
| 177 |
+
Auxiliary regression drops the last column of binned probs to avoid
|
| 178 |
+
that probabilities sum to 1.
|
| 179 |
+
|
| 180 |
+
References
|
| 181 |
+
----------
|
| 182 |
+
.. [1] Andrews, Donald W. K. 1988a. “Chi-Square Diagnostic Tests for
|
| 183 |
+
Econometric Models: Theory.” Econometrica 56 (6): 1419–53.
|
| 184 |
+
https://doi.org/10.2307/1913105.
|
| 185 |
+
|
| 186 |
+
.. [2] Andrews, Donald W. K. 1988b. “Chi-Square Diagnostic Tests for
|
| 187 |
+
Econometric Models.” Journal of Econometrics 37 (1): 135–56.
|
| 188 |
+
https://doi.org/10.1016/0304-4076(88)90079-6.
|
| 189 |
+
|
| 190 |
+
.. [3] Manjón, M., and O. Martínez. 2014. “The Chi-Squared Goodness-of-Fit
|
| 191 |
+
Test for Count-Data Models.” Stata Journal 14 (4): 798–816.
|
| 192 |
+
"""
|
| 193 |
+
res = results
|
| 194 |
+
score_obs = results.model.score_obs(results.params)
|
| 195 |
+
d_ind = (res.model.endog[:, None] == np.arange(probs.shape[1])).astype(int)
|
| 196 |
+
if bin_edges is not None:
|
| 197 |
+
d_ind_bins, k_bins = _combine_bins(bin_edges, d_ind)
|
| 198 |
+
probs_bins, k_bins = _combine_bins(bin_edges, probs)
|
| 199 |
+
k_bins = probs_bins.shape[-1]
|
| 200 |
+
else:
|
| 201 |
+
d_ind_bins, k_bins = d_ind, d_ind.shape[1]
|
| 202 |
+
probs_bins = probs
|
| 203 |
+
diff1 = d_ind_bins - probs_bins
|
| 204 |
+
# diff2 = (1 - d_ind.sum(1)) - (1 - probs_bins.sum(1))
|
| 205 |
+
x_aux = np.column_stack((score_obs, diff1[:, :-1])) # diff2))
|
| 206 |
+
nobs = x_aux.shape[0]
|
| 207 |
+
res_aux = OLS(np.ones(nobs), x_aux).fit()
|
| 208 |
+
|
| 209 |
+
chi2_stat = nobs * (1 - res_aux.ssr / res_aux.uncentered_tss)
|
| 210 |
+
df = res_aux.model.rank - score_obs.shape[1]
|
| 211 |
+
if df < k_bins - 1:
|
| 212 |
+
# not a problem in general, but it can be for OPG version
|
| 213 |
+
import warnings
|
| 214 |
+
# TODO: Warning shows up in Monte Carlo loop, skip for now
|
| 215 |
+
warnings.warn('auxiliary model is rank deficient')
|
| 216 |
+
|
| 217 |
+
statistic = chi2_stat
|
| 218 |
+
pvalue = stats.chi2.sf(chi2_stat, df)
|
| 219 |
+
|
| 220 |
+
res = HolderTuple(
|
| 221 |
+
statistic=statistic,
|
| 222 |
+
pvalue=pvalue,
|
| 223 |
+
df=df,
|
| 224 |
+
diff1=diff1,
|
| 225 |
+
res_aux=res_aux,
|
| 226 |
+
distribution="chi2",
|
| 227 |
+
)
|
| 228 |
+
return res
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
class DispersionResults(HolderTuple):
|
| 232 |
+
|
| 233 |
+
def summary_frame(self):
|
| 234 |
+
frame = pd.DataFrame({
|
| 235 |
+
"statistic": self.statistic,
|
| 236 |
+
"pvalue": self.pvalue,
|
| 237 |
+
"method": self.method,
|
| 238 |
+
"alternative": self.alternative
|
| 239 |
+
})
|
| 240 |
+
|
| 241 |
+
return frame
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def test_poisson_dispersion(results, method="all", _old=False):
|
| 245 |
+
"""Score/LM type tests for Poisson variance assumptions
|
| 246 |
+
|
| 247 |
+
Null Hypothesis is
|
| 248 |
+
|
| 249 |
+
H0: var(y) = E(y) and assuming E(y) is correctly specified
|
| 250 |
+
H1: var(y) ~= E(y)
|
| 251 |
+
|
| 252 |
+
The tests are based on the constrained model, i.e. the Poisson model.
|
| 253 |
+
The tests differ in their assumed alternatives, and in their maintained
|
| 254 |
+
assumptions.
|
| 255 |
+
|
| 256 |
+
Parameters
|
| 257 |
+
----------
|
| 258 |
+
results : Poisson results instance
|
| 259 |
+
This can be a results instance for either a discrete Poisson or a GLM
|
| 260 |
+
with family Poisson.
|
| 261 |
+
method : str
|
| 262 |
+
Not used yet. Currently results for all methods are returned.
|
| 263 |
+
_old : bool
|
| 264 |
+
Temporary keyword for backwards compatibility, will be removed
|
| 265 |
+
in future version of statsmodels.
|
| 266 |
+
|
| 267 |
+
Returns
|
| 268 |
+
-------
|
| 269 |
+
res : instance
|
| 270 |
+
The instance of DispersionResults has the hypothesis test results,
|
| 271 |
+
statistic, pvalue, method, alternative, as main attributes and a
|
| 272 |
+
summary_frame method that returns the results as pandas DataFrame.
|
| 273 |
+
|
| 274 |
+
"""
|
| 275 |
+
|
| 276 |
+
if method not in ["all"]:
|
| 277 |
+
raise ValueError(f'unknown method "{method}"')
|
| 278 |
+
|
| 279 |
+
if hasattr(results, '_results'):
|
| 280 |
+
results = results._results
|
| 281 |
+
|
| 282 |
+
endog = results.model.endog
|
| 283 |
+
nobs = endog.shape[0] # TODO: use attribute, may need to be added
|
| 284 |
+
fitted = results.predict()
|
| 285 |
+
# fitted = results.fittedvalues # discrete has linear prediction
|
| 286 |
+
# this assumes Poisson
|
| 287 |
+
resid2 = results.resid_response**2
|
| 288 |
+
var_resid_endog = (resid2 - endog)
|
| 289 |
+
var_resid_fitted = (resid2 - fitted)
|
| 290 |
+
std1 = np.sqrt(2 * (fitted**2).sum())
|
| 291 |
+
|
| 292 |
+
var_resid_endog_sum = var_resid_endog.sum()
|
| 293 |
+
dean_a = var_resid_fitted.sum() / std1
|
| 294 |
+
dean_b = var_resid_endog_sum / std1
|
| 295 |
+
dean_c = (var_resid_endog / fitted).sum() / np.sqrt(2 * nobs)
|
| 296 |
+
|
| 297 |
+
pval_dean_a = 2 * stats.norm.sf(np.abs(dean_a))
|
| 298 |
+
pval_dean_b = 2 * stats.norm.sf(np.abs(dean_b))
|
| 299 |
+
pval_dean_c = 2 * stats.norm.sf(np.abs(dean_c))
|
| 300 |
+
|
| 301 |
+
results_all = [[dean_a, pval_dean_a],
|
| 302 |
+
[dean_b, pval_dean_b],
|
| 303 |
+
[dean_c, pval_dean_c]]
|
| 304 |
+
description = [['Dean A', 'mu (1 + a mu)'],
|
| 305 |
+
['Dean B', 'mu (1 + a mu)'],
|
| 306 |
+
['Dean C', 'mu (1 + a)']]
|
| 307 |
+
|
| 308 |
+
# Cameron Trived auxiliary regression page 78 count book 1989
|
| 309 |
+
endog_v = var_resid_endog / fitted
|
| 310 |
+
res_ols_nb2 = OLS(endog_v, fitted).fit(use_t=False)
|
| 311 |
+
stat_ols_nb2 = res_ols_nb2.tvalues[0]
|
| 312 |
+
pval_ols_nb2 = res_ols_nb2.pvalues[0]
|
| 313 |
+
results_all.append([stat_ols_nb2, pval_ols_nb2])
|
| 314 |
+
description.append(['CT nb2', 'mu (1 + a mu)'])
|
| 315 |
+
|
| 316 |
+
res_ols_nb1 = OLS(endog_v, fitted).fit(use_t=False)
|
| 317 |
+
stat_ols_nb1 = res_ols_nb1.tvalues[0]
|
| 318 |
+
pval_ols_nb1 = res_ols_nb1.pvalues[0]
|
| 319 |
+
results_all.append([stat_ols_nb1, pval_ols_nb1])
|
| 320 |
+
description.append(['CT nb1', 'mu (1 + a)'])
|
| 321 |
+
|
| 322 |
+
endog_v = var_resid_endog / fitted
|
| 323 |
+
res_ols_nb2 = OLS(endog_v, fitted).fit(cov_type='HC3', use_t=False)
|
| 324 |
+
stat_ols_hc1_nb2 = res_ols_nb2.tvalues[0]
|
| 325 |
+
pval_ols_hc1_nb2 = res_ols_nb2.pvalues[0]
|
| 326 |
+
results_all.append([stat_ols_hc1_nb2, pval_ols_hc1_nb2])
|
| 327 |
+
description.append(['CT nb2 HC3', 'mu (1 + a mu)'])
|
| 328 |
+
|
| 329 |
+
res_ols_nb1 = OLS(endog_v, np.ones(len(endog_v))).fit(cov_type='HC3',
|
| 330 |
+
use_t=False)
|
| 331 |
+
stat_ols_hc1_nb1 = res_ols_nb1.tvalues[0]
|
| 332 |
+
pval_ols_hc1_nb1 = res_ols_nb1.pvalues[0]
|
| 333 |
+
results_all.append([stat_ols_hc1_nb1, pval_ols_hc1_nb1])
|
| 334 |
+
description.append(['CT nb1 HC3', 'mu (1 + a)'])
|
| 335 |
+
|
| 336 |
+
results_all = np.array(results_all)
|
| 337 |
+
if _old:
|
| 338 |
+
# for backwards compatibility in 0.14, remove in later versions
|
| 339 |
+
return results_all, description
|
| 340 |
+
else:
|
| 341 |
+
res = DispersionResults(
|
| 342 |
+
statistic=results_all[:, 0],
|
| 343 |
+
pvalue=results_all[:, 1],
|
| 344 |
+
method=[i[0] for i in description],
|
| 345 |
+
alternative=[i[1] for i in description],
|
| 346 |
+
name="Poisson Dispersion Test"
|
| 347 |
+
)
|
| 348 |
+
return res
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
def _test_poisson_dispersion_generic(
|
| 352 |
+
results,
|
| 353 |
+
exog_new_test,
|
| 354 |
+
exog_new_control=None,
|
| 355 |
+
include_score=False,
|
| 356 |
+
use_endog=True,
|
| 357 |
+
cov_type='HC3',
|
| 358 |
+
cov_kwds=None,
|
| 359 |
+
use_t=False
|
| 360 |
+
):
|
| 361 |
+
"""A variable addition test for the variance function
|
| 362 |
+
|
| 363 |
+
This uses an artificial regression to calculate a variant of an LM or
|
| 364 |
+
generalized score test for the specification of the variance assumption
|
| 365 |
+
in a Poisson model. The performed test is a Wald test on the coefficients
|
| 366 |
+
of the `exog_new_test`.
|
| 367 |
+
|
| 368 |
+
Warning: insufficiently tested, especially for options
|
| 369 |
+
"""
|
| 370 |
+
|
| 371 |
+
if hasattr(results, '_results'):
|
| 372 |
+
results = results._results
|
| 373 |
+
|
| 374 |
+
endog = results.model.endog
|
| 375 |
+
nobs = endog.shape[0] # TODO: use attribute, may need to be added
|
| 376 |
+
# fitted = results.fittedvalues # generic has linpred as fittedvalues
|
| 377 |
+
fitted = results.predict()
|
| 378 |
+
resid2 = results.resid_response**2
|
| 379 |
+
# the following assumes Poisson
|
| 380 |
+
if use_endog:
|
| 381 |
+
var_resid = (resid2 - endog)
|
| 382 |
+
else:
|
| 383 |
+
var_resid = (resid2 - fitted)
|
| 384 |
+
|
| 385 |
+
endog_v = var_resid / fitted
|
| 386 |
+
|
| 387 |
+
k_constraints = exog_new_test.shape[1]
|
| 388 |
+
ex_list = [exog_new_test]
|
| 389 |
+
if include_score:
|
| 390 |
+
score_obs = results.model.score_obs(results.params)
|
| 391 |
+
ex_list.append(score_obs)
|
| 392 |
+
|
| 393 |
+
if exog_new_control is not None:
|
| 394 |
+
ex_list.append(score_obs)
|
| 395 |
+
|
| 396 |
+
if len(ex_list) > 1:
|
| 397 |
+
ex = np.column_stack(ex_list)
|
| 398 |
+
use_wald = True
|
| 399 |
+
else:
|
| 400 |
+
ex = ex_list[0] # no control variables in exog
|
| 401 |
+
use_wald = False
|
| 402 |
+
|
| 403 |
+
res_ols = OLS(endog_v, ex).fit(cov_type=cov_type, cov_kwds=cov_kwds,
|
| 404 |
+
use_t=use_t)
|
| 405 |
+
|
| 406 |
+
if use_wald:
|
| 407 |
+
# we have controls and need to test coefficients
|
| 408 |
+
k_vars = ex.shape[1]
|
| 409 |
+
constraints = np.eye(k_constraints, k_vars)
|
| 410 |
+
ht = res_ols.wald_test(constraints)
|
| 411 |
+
stat_ols = ht.statistic
|
| 412 |
+
pval_ols = ht.pvalue
|
| 413 |
+
else:
|
| 414 |
+
# we do not have controls and can use overall fit
|
| 415 |
+
nobs = endog_v.shape[0]
|
| 416 |
+
rsquared_noncentered = 1 - res_ols.ssr/res_ols.uncentered_tss
|
| 417 |
+
stat_ols = nobs * rsquared_noncentered
|
| 418 |
+
pval_ols = stats.chi2.sf(stat_ols, k_constraints)
|
| 419 |
+
|
| 420 |
+
return stat_ols, pval_ols
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
def test_poisson_zeroinflation_jh(results_poisson, exog_infl=None):
|
| 424 |
+
"""score test for zero inflation or deflation in Poisson
|
| 425 |
+
|
| 426 |
+
This implements Jansakul and Hinde 2009 score test
|
| 427 |
+
for excess zeros against a zero modified Poisson
|
| 428 |
+
alternative. They use a linear link function for the
|
| 429 |
+
inflation model to allow for zero deflation.
|
| 430 |
+
|
| 431 |
+
Parameters
|
| 432 |
+
----------
|
| 433 |
+
results_poisson: results instance
|
| 434 |
+
The test is only valid if the results instance is a Poisson
|
| 435 |
+
model.
|
| 436 |
+
exog_infl : ndarray
|
| 437 |
+
Explanatory variables for the zero inflated or zero modified
|
| 438 |
+
alternative. I exog_infl is None, then the inflation
|
| 439 |
+
probability is assumed to be constant.
|
| 440 |
+
|
| 441 |
+
Returns
|
| 442 |
+
-------
|
| 443 |
+
score test results based on chisquare distribution
|
| 444 |
+
|
| 445 |
+
Notes
|
| 446 |
+
-----
|
| 447 |
+
This is a score test based on the null hypothesis that
|
| 448 |
+
the true model is Poisson. It will also reject for
|
| 449 |
+
other deviations from a Poisson model if those affect
|
| 450 |
+
the zero probabilities, e.g. in the direction of
|
| 451 |
+
excess dispersion as in the Negative Binomial
|
| 452 |
+
or Generalized Poisson model.
|
| 453 |
+
Therefore, rejection in this test does not imply that
|
| 454 |
+
zero-inflated Poisson is the appropriate model.
|
| 455 |
+
|
| 456 |
+
Status: experimental, no verified unit tests,
|
| 457 |
+
|
| 458 |
+
TODO: If the zero modification probability is assumed
|
| 459 |
+
to be constant under the alternative, then we only have
|
| 460 |
+
a scalar test score and we can use one-sided tests to
|
| 461 |
+
distinguish zero inflation and deflation from the
|
| 462 |
+
two-sided deviations. (The general one-sided case is
|
| 463 |
+
difficult.)
|
| 464 |
+
In this case the test specializes to the test by Broek
|
| 465 |
+
|
| 466 |
+
References
|
| 467 |
+
----------
|
| 468 |
+
.. [1] Jansakul, N., and J. P. Hinde. 2002. “Score Tests for Zero-Inflated
|
| 469 |
+
Poisson Models.” Computational Statistics & Data Analysis 40 (1):
|
| 470 |
+
75–96. https://doi.org/10.1016/S0167-9473(01)00104-9.
|
| 471 |
+
"""
|
| 472 |
+
if not isinstance(results_poisson.model, Poisson):
|
| 473 |
+
# GLM Poisson would be also valid, not tried
|
| 474 |
+
import warnings
|
| 475 |
+
warnings.warn('Test is only valid if model is Poisson')
|
| 476 |
+
|
| 477 |
+
nobs = results_poisson.model.endog.shape[0]
|
| 478 |
+
|
| 479 |
+
if exog_infl is None:
|
| 480 |
+
exog_infl = np.ones((nobs, 1))
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
endog = results_poisson.model.endog
|
| 484 |
+
exog = results_poisson.model.exog
|
| 485 |
+
|
| 486 |
+
mu = results_poisson.predict()
|
| 487 |
+
prob_zero = np.exp(-mu)
|
| 488 |
+
|
| 489 |
+
cov_poi = results_poisson.cov_params()
|
| 490 |
+
cross_derivative = (exog_infl.T * (-mu)).dot(exog).T
|
| 491 |
+
cov_infl = (exog_infl.T * ((1 - prob_zero) / prob_zero)).dot(exog_infl)
|
| 492 |
+
score_obs_infl = exog_infl * (((endog == 0) - prob_zero) / prob_zero)[:,None]
|
| 493 |
+
#score_obs_infl = exog_infl * ((endog == 0) * (1 - prob_zero) / prob_zero - (endog>0))[:,None] #same
|
| 494 |
+
score_infl = score_obs_infl.sum(0)
|
| 495 |
+
cov_score_infl = cov_infl - cross_derivative.T.dot(cov_poi).dot(cross_derivative)
|
| 496 |
+
cov_score_infl_inv = np.linalg.pinv(cov_score_infl)
|
| 497 |
+
|
| 498 |
+
statistic = score_infl.dot(cov_score_infl_inv).dot(score_infl)
|
| 499 |
+
df2 = np.linalg.matrix_rank(cov_score_infl) # more general, maybe not needed
|
| 500 |
+
df = exog_infl.shape[1]
|
| 501 |
+
pvalue = stats.chi2.sf(statistic, df)
|
| 502 |
+
|
| 503 |
+
res = HolderTuple(
|
| 504 |
+
statistic=statistic,
|
| 505 |
+
pvalue=pvalue,
|
| 506 |
+
df=df,
|
| 507 |
+
rank_score=df2,
|
| 508 |
+
distribution="chi2",
|
| 509 |
+
)
|
| 510 |
+
return res
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def test_poisson_zeroinflation_broek(results_poisson):
|
| 514 |
+
"""score test for zero modification in Poisson, special case
|
| 515 |
+
|
| 516 |
+
This assumes that the Poisson model has a constant and that
|
| 517 |
+
the zero modification probability is constant.
|
| 518 |
+
|
| 519 |
+
This is a special case of test_poisson_zeroinflation derived by
|
| 520 |
+
van den Broek 1995.
|
| 521 |
+
|
| 522 |
+
The test reports two sided and one sided alternatives based on
|
| 523 |
+
the normal distribution of the test statistic.
|
| 524 |
+
|
| 525 |
+
References
|
| 526 |
+
----------
|
| 527 |
+
.. [1] Broek, Jan van den. 1995. “A Score Test for Zero Inflation in a
|
| 528 |
+
Poisson Distribution.” Biometrics 51 (2): 738–43.
|
| 529 |
+
https://doi.org/10.2307/2532959.
|
| 530 |
+
|
| 531 |
+
"""
|
| 532 |
+
|
| 533 |
+
mu = results_poisson.predict()
|
| 534 |
+
prob_zero = np.exp(-mu)
|
| 535 |
+
endog = results_poisson.model.endog
|
| 536 |
+
# nobs = len(endog)
|
| 537 |
+
# score = ((endog == 0) / prob_zero).sum() - nobs
|
| 538 |
+
# var_score = (1 / prob_zero).sum() - nobs - endog.sum()
|
| 539 |
+
score = (((endog == 0) - prob_zero) / prob_zero).sum()
|
| 540 |
+
var_score = ((1 - prob_zero) / prob_zero).sum() - endog.sum()
|
| 541 |
+
statistic = score / np.sqrt(var_score)
|
| 542 |
+
pvalue_two = 2 * stats.norm.sf(np.abs(statistic))
|
| 543 |
+
pvalue_upp = stats.norm.sf(statistic)
|
| 544 |
+
pvalue_low = stats.norm.cdf(statistic)
|
| 545 |
+
|
| 546 |
+
res = HolderTuple(
|
| 547 |
+
statistic=statistic,
|
| 548 |
+
pvalue=pvalue_two,
|
| 549 |
+
pvalue_smaller=pvalue_upp,
|
| 550 |
+
pvalue_larger=pvalue_low,
|
| 551 |
+
chi2=statistic**2,
|
| 552 |
+
pvalue_chi2=stats.chi2.sf(statistic**2, 1),
|
| 553 |
+
df_chi2=1,
|
| 554 |
+
distribution="normal",
|
| 555 |
+
)
|
| 556 |
+
return res
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
def test_poisson_zeros(results):
|
| 560 |
+
"""Test for excess zeros in Poisson regression model.
|
| 561 |
+
|
| 562 |
+
The test is implemented following Tang and Tang [1]_ equ. (12) which is
|
| 563 |
+
based on the test derived in He et al 2019 [2]_.
|
| 564 |
+
|
| 565 |
+
References
|
| 566 |
+
----------
|
| 567 |
+
|
| 568 |
+
.. [1] Tang, Yi, and Wan Tang. 2018. “Testing Modified Zeros for Poisson
|
| 569 |
+
Regression Models:” Statistical Methods in Medical Research,
|
| 570 |
+
September. https://doi.org/10.1177/0962280218796253.
|
| 571 |
+
|
| 572 |
+
.. [2] He, Hua, Hui Zhang, Peng Ye, and Wan Tang. 2019. “A Test of Inflated
|
| 573 |
+
Zeros for Poisson Regression Models.” Statistical Methods in
|
| 574 |
+
Medical Research 28 (4): 1157–69.
|
| 575 |
+
https://doi.org/10.1177/0962280217749991.
|
| 576 |
+
|
| 577 |
+
"""
|
| 578 |
+
x = results.model.exog
|
| 579 |
+
mean = results.predict()
|
| 580 |
+
prob0 = np.exp(-mean)
|
| 581 |
+
counts = (results.model.endog == 0).astype(int)
|
| 582 |
+
diff = counts.sum() - prob0.sum()
|
| 583 |
+
var1 = prob0 @ (1 - prob0)
|
| 584 |
+
pm = prob0 * mean
|
| 585 |
+
c = np.linalg.inv(x.T * mean @ x)
|
| 586 |
+
pmx = pm @ x
|
| 587 |
+
var2 = pmx @ c @ pmx
|
| 588 |
+
var = var1 - var2
|
| 589 |
+
statistic = diff / np.sqrt(var)
|
| 590 |
+
|
| 591 |
+
pvalue_two = 2 * stats.norm.sf(np.abs(statistic))
|
| 592 |
+
pvalue_upp = stats.norm.sf(statistic)
|
| 593 |
+
pvalue_low = stats.norm.cdf(statistic)
|
| 594 |
+
|
| 595 |
+
res = HolderTuple(
|
| 596 |
+
statistic=statistic,
|
| 597 |
+
pvalue=pvalue_two,
|
| 598 |
+
pvalue_smaller=pvalue_upp,
|
| 599 |
+
pvalue_larger=pvalue_low,
|
| 600 |
+
chi2=statistic**2,
|
| 601 |
+
pvalue_chi2=stats.chi2.sf(statistic**2, 1),
|
| 602 |
+
df_chi2=1,
|
| 603 |
+
distribution="normal",
|
| 604 |
+
)
|
| 605 |
+
return res
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/conditional_models.py
ADDED
|
@@ -0,0 +1,634 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"""
|
| 2 |
+
Conditional logistic, Poisson, and multinomial logit regression
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
import statsmodels.base.model as base
|
| 7 |
+
import statsmodels.regression.linear_model as lm
|
| 8 |
+
import statsmodels.base.wrapper as wrap
|
| 9 |
+
from statsmodels.discrete.discrete_model import (MultinomialResults,
|
| 10 |
+
MultinomialResultsWrapper)
|
| 11 |
+
import collections
|
| 12 |
+
import warnings
|
| 13 |
+
import itertools
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class _ConditionalModel(base.LikelihoodModel):
|
| 17 |
+
|
| 18 |
+
def __init__(self, endog, exog, missing='none', **kwargs):
|
| 19 |
+
|
| 20 |
+
if "groups" not in kwargs:
|
| 21 |
+
raise ValueError("'groups' is a required argument")
|
| 22 |
+
groups = kwargs["groups"]
|
| 23 |
+
|
| 24 |
+
if groups.size != endog.size:
|
| 25 |
+
msg = "'endog' and 'groups' should have the same dimensions"
|
| 26 |
+
raise ValueError(msg)
|
| 27 |
+
|
| 28 |
+
if exog.shape[0] != endog.size:
|
| 29 |
+
msg = "The leading dimension of 'exog' should equal the length of 'endog'"
|
| 30 |
+
raise ValueError(msg)
|
| 31 |
+
|
| 32 |
+
super().__init__(
|
| 33 |
+
endog, exog, missing=missing, **kwargs)
|
| 34 |
+
|
| 35 |
+
if self.data.const_idx is not None:
|
| 36 |
+
msg = ("Conditional models should not have an intercept in the " +
|
| 37 |
+
"design matrix")
|
| 38 |
+
raise ValueError(msg)
|
| 39 |
+
|
| 40 |
+
exog = self.exog
|
| 41 |
+
self.k_params = exog.shape[1]
|
| 42 |
+
|
| 43 |
+
# Get the row indices for each group
|
| 44 |
+
row_ix = {}
|
| 45 |
+
for i, g in enumerate(groups):
|
| 46 |
+
if g not in row_ix:
|
| 47 |
+
row_ix[g] = []
|
| 48 |
+
row_ix[g].append(i)
|
| 49 |
+
|
| 50 |
+
# Split the data into groups and remove groups with no variation
|
| 51 |
+
endog, exog = np.asarray(endog), np.asarray(exog)
|
| 52 |
+
offset = kwargs.get("offset")
|
| 53 |
+
self._endog_grp = []
|
| 54 |
+
self._exog_grp = []
|
| 55 |
+
self._groupsize = []
|
| 56 |
+
if offset is not None:
|
| 57 |
+
offset = np.asarray(offset)
|
| 58 |
+
self._offset_grp = []
|
| 59 |
+
self._offset = []
|
| 60 |
+
self._sumy = []
|
| 61 |
+
self.nobs = 0
|
| 62 |
+
drops = [0, 0]
|
| 63 |
+
for g, ix in row_ix.items():
|
| 64 |
+
y = endog[ix].flat
|
| 65 |
+
if np.std(y) == 0:
|
| 66 |
+
drops[0] += 1
|
| 67 |
+
drops[1] += len(y)
|
| 68 |
+
continue
|
| 69 |
+
self.nobs += len(y)
|
| 70 |
+
self._endog_grp.append(y)
|
| 71 |
+
if offset is not None:
|
| 72 |
+
self._offset_grp.append(offset[ix])
|
| 73 |
+
self._groupsize.append(len(y))
|
| 74 |
+
self._exog_grp.append(exog[ix, :])
|
| 75 |
+
self._sumy.append(np.sum(y))
|
| 76 |
+
|
| 77 |
+
if drops[0] > 0:
|
| 78 |
+
msg = ("Dropped %d groups and %d observations for having " +
|
| 79 |
+
"no within-group variance") % tuple(drops)
|
| 80 |
+
warnings.warn(msg)
|
| 81 |
+
|
| 82 |
+
# This can be pre-computed
|
| 83 |
+
if offset is not None:
|
| 84 |
+
self._endofs = []
|
| 85 |
+
for k, ofs in enumerate(self._offset_grp):
|
| 86 |
+
self._endofs.append(np.dot(self._endog_grp[k], ofs))
|
| 87 |
+
|
| 88 |
+
# Number of groups
|
| 89 |
+
self._n_groups = len(self._endog_grp)
|
| 90 |
+
|
| 91 |
+
# These are the sufficient statistics
|
| 92 |
+
self._xy = []
|
| 93 |
+
self._n1 = []
|
| 94 |
+
for g in range(self._n_groups):
|
| 95 |
+
self._xy.append(np.dot(self._endog_grp[g], self._exog_grp[g]))
|
| 96 |
+
self._n1.append(np.sum(self._endog_grp[g]))
|
| 97 |
+
|
| 98 |
+
def hessian(self, params):
|
| 99 |
+
|
| 100 |
+
from statsmodels.tools.numdiff import approx_fprime
|
| 101 |
+
hess = approx_fprime(params, self.score)
|
| 102 |
+
hess = np.atleast_2d(hess)
|
| 103 |
+
return hess
|
| 104 |
+
|
| 105 |
+
def fit(self,
|
| 106 |
+
start_params=None,
|
| 107 |
+
method='BFGS',
|
| 108 |
+
maxiter=100,
|
| 109 |
+
full_output=True,
|
| 110 |
+
disp=False,
|
| 111 |
+
fargs=(),
|
| 112 |
+
callback=None,
|
| 113 |
+
retall=False,
|
| 114 |
+
skip_hessian=False,
|
| 115 |
+
**kwargs):
|
| 116 |
+
|
| 117 |
+
rslt = super().fit(
|
| 118 |
+
start_params=start_params,
|
| 119 |
+
method=method,
|
| 120 |
+
maxiter=maxiter,
|
| 121 |
+
full_output=full_output,
|
| 122 |
+
disp=disp,
|
| 123 |
+
skip_hessian=skip_hessian)
|
| 124 |
+
|
| 125 |
+
crslt = ConditionalResults(self, rslt.params, rslt.cov_params(), 1)
|
| 126 |
+
crslt.method = method
|
| 127 |
+
crslt.nobs = self.nobs
|
| 128 |
+
crslt.n_groups = self._n_groups
|
| 129 |
+
crslt._group_stats = [
|
| 130 |
+
"%d" % min(self._groupsize),
|
| 131 |
+
"%d" % max(self._groupsize),
|
| 132 |
+
"%.1f" % np.mean(self._groupsize)
|
| 133 |
+
]
|
| 134 |
+
rslt = ConditionalResultsWrapper(crslt)
|
| 135 |
+
return rslt
|
| 136 |
+
|
| 137 |
+
def fit_regularized(self,
|
| 138 |
+
method="elastic_net",
|
| 139 |
+
alpha=0.,
|
| 140 |
+
start_params=None,
|
| 141 |
+
refit=False,
|
| 142 |
+
**kwargs):
|
| 143 |
+
"""
|
| 144 |
+
Return a regularized fit to a linear regression model.
|
| 145 |
+
|
| 146 |
+
Parameters
|
| 147 |
+
----------
|
| 148 |
+
method : {'elastic_net'}
|
| 149 |
+
Only the `elastic_net` approach is currently implemented.
|
| 150 |
+
alpha : scalar or array_like
|
| 151 |
+
The penalty weight. If a scalar, the same penalty weight
|
| 152 |
+
applies to all variables in the model. If a vector, it
|
| 153 |
+
must have the same length as `params`, and contains a
|
| 154 |
+
penalty weight for each coefficient.
|
| 155 |
+
start_params : array_like
|
| 156 |
+
Starting values for `params`.
|
| 157 |
+
refit : bool
|
| 158 |
+
If True, the model is refit using only the variables that
|
| 159 |
+
have non-zero coefficients in the regularized fit. The
|
| 160 |
+
refitted model is not regularized.
|
| 161 |
+
**kwargs
|
| 162 |
+
Additional keyword argument that are used when fitting the model.
|
| 163 |
+
|
| 164 |
+
Returns
|
| 165 |
+
-------
|
| 166 |
+
Results
|
| 167 |
+
A results instance.
|
| 168 |
+
"""
|
| 169 |
+
|
| 170 |
+
from statsmodels.base.elastic_net import fit_elasticnet
|
| 171 |
+
|
| 172 |
+
if method != "elastic_net":
|
| 173 |
+
raise ValueError("method for fit_regularized must be elastic_net")
|
| 174 |
+
|
| 175 |
+
defaults = {"maxiter": 50, "L1_wt": 1, "cnvrg_tol": 1e-10,
|
| 176 |
+
"zero_tol": 1e-10}
|
| 177 |
+
defaults.update(kwargs)
|
| 178 |
+
|
| 179 |
+
return fit_elasticnet(self, method=method,
|
| 180 |
+
alpha=alpha,
|
| 181 |
+
start_params=start_params,
|
| 182 |
+
refit=refit,
|
| 183 |
+
**defaults)
|
| 184 |
+
|
| 185 |
+
# Override to allow groups to be passed as a variable name.
|
| 186 |
+
@classmethod
|
| 187 |
+
def from_formula(cls,
|
| 188 |
+
formula,
|
| 189 |
+
data,
|
| 190 |
+
subset=None,
|
| 191 |
+
drop_cols=None,
|
| 192 |
+
*args,
|
| 193 |
+
**kwargs):
|
| 194 |
+
|
| 195 |
+
try:
|
| 196 |
+
groups = kwargs["groups"]
|
| 197 |
+
del kwargs["groups"]
|
| 198 |
+
except KeyError:
|
| 199 |
+
raise ValueError("'groups' is a required argument")
|
| 200 |
+
|
| 201 |
+
if isinstance(groups, str):
|
| 202 |
+
groups = data[groups]
|
| 203 |
+
|
| 204 |
+
if "0+" not in formula.replace(" ", ""):
|
| 205 |
+
warnings.warn("Conditional models should not include an intercept")
|
| 206 |
+
|
| 207 |
+
model = super().from_formula(
|
| 208 |
+
formula, data=data, groups=groups, *args, **kwargs)
|
| 209 |
+
|
| 210 |
+
return model
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
class ConditionalLogit(_ConditionalModel):
|
| 214 |
+
"""
|
| 215 |
+
Fit a conditional logistic regression model to grouped data.
|
| 216 |
+
|
| 217 |
+
Every group is implicitly given an intercept, but the model is fit using
|
| 218 |
+
a conditional likelihood in which the intercepts are not present. Thus,
|
| 219 |
+
intercept estimates are not given, but the other parameter estimates can
|
| 220 |
+
be interpreted as being adjusted for any group-level confounders.
|
| 221 |
+
|
| 222 |
+
Parameters
|
| 223 |
+
----------
|
| 224 |
+
endog : array_like
|
| 225 |
+
The response variable, must contain only 0 and 1.
|
| 226 |
+
exog : array_like
|
| 227 |
+
The array of covariates. Do not include an intercept
|
| 228 |
+
in this array.
|
| 229 |
+
groups : array_like
|
| 230 |
+
Codes defining the groups. This is a required keyword parameter.
|
| 231 |
+
"""
|
| 232 |
+
|
| 233 |
+
def __init__(self, endog, exog, missing='none', **kwargs):
|
| 234 |
+
|
| 235 |
+
super().__init__(
|
| 236 |
+
endog, exog, missing=missing, **kwargs)
|
| 237 |
+
|
| 238 |
+
if np.any(np.unique(self.endog) != np.r_[0, 1]):
|
| 239 |
+
msg = "endog must be coded as 0, 1"
|
| 240 |
+
raise ValueError(msg)
|
| 241 |
+
|
| 242 |
+
self.K = self.exog.shape[1]
|
| 243 |
+
# i.e. self.k_params, for compatibility with MNLogit
|
| 244 |
+
|
| 245 |
+
def loglike(self, params):
|
| 246 |
+
|
| 247 |
+
ll = 0
|
| 248 |
+
for g in range(len(self._endog_grp)):
|
| 249 |
+
ll += self.loglike_grp(g, params)
|
| 250 |
+
|
| 251 |
+
return ll
|
| 252 |
+
|
| 253 |
+
def score(self, params):
|
| 254 |
+
|
| 255 |
+
score = 0
|
| 256 |
+
for g in range(self._n_groups):
|
| 257 |
+
score += self.score_grp(g, params)
|
| 258 |
+
|
| 259 |
+
return score
|
| 260 |
+
|
| 261 |
+
def _denom(self, grp, params, ofs=None):
|
| 262 |
+
|
| 263 |
+
if ofs is None:
|
| 264 |
+
ofs = 0
|
| 265 |
+
|
| 266 |
+
exb = np.exp(np.dot(self._exog_grp[grp], params) + ofs)
|
| 267 |
+
|
| 268 |
+
# In the recursions, f may be called multiple times with the
|
| 269 |
+
# same arguments, so we memoize the results.
|
| 270 |
+
memo = {}
|
| 271 |
+
|
| 272 |
+
def f(t, k):
|
| 273 |
+
if t < k:
|
| 274 |
+
return 0
|
| 275 |
+
if k == 0:
|
| 276 |
+
return 1
|
| 277 |
+
|
| 278 |
+
try:
|
| 279 |
+
return memo[(t, k)]
|
| 280 |
+
except KeyError:
|
| 281 |
+
pass
|
| 282 |
+
|
| 283 |
+
v = f(t - 1, k) + f(t - 1, k - 1) * exb[t - 1]
|
| 284 |
+
memo[(t, k)] = v
|
| 285 |
+
|
| 286 |
+
return v
|
| 287 |
+
|
| 288 |
+
return f(self._groupsize[grp], self._n1[grp])
|
| 289 |
+
|
| 290 |
+
def _denom_grad(self, grp, params, ofs=None):
|
| 291 |
+
|
| 292 |
+
if ofs is None:
|
| 293 |
+
ofs = 0
|
| 294 |
+
|
| 295 |
+
ex = self._exog_grp[grp]
|
| 296 |
+
exb = np.exp(np.dot(ex, params) + ofs)
|
| 297 |
+
|
| 298 |
+
# s may be called multiple times in the recursions with the
|
| 299 |
+
# same arguments, so memoize the results.
|
| 300 |
+
memo = {}
|
| 301 |
+
|
| 302 |
+
def s(t, k):
|
| 303 |
+
|
| 304 |
+
if t < k:
|
| 305 |
+
return 0, np.zeros(self.k_params)
|
| 306 |
+
if k == 0:
|
| 307 |
+
return 1, 0
|
| 308 |
+
|
| 309 |
+
try:
|
| 310 |
+
return memo[(t, k)]
|
| 311 |
+
except KeyError:
|
| 312 |
+
pass
|
| 313 |
+
|
| 314 |
+
h = exb[t - 1]
|
| 315 |
+
a, b = s(t - 1, k)
|
| 316 |
+
c, e = s(t - 1, k - 1)
|
| 317 |
+
d = c * h * ex[t - 1, :]
|
| 318 |
+
|
| 319 |
+
u, v = a + c * h, b + d + e * h
|
| 320 |
+
memo[(t, k)] = (u, v)
|
| 321 |
+
|
| 322 |
+
return u, v
|
| 323 |
+
|
| 324 |
+
return s(self._groupsize[grp], self._n1[grp])
|
| 325 |
+
|
| 326 |
+
def loglike_grp(self, grp, params):
|
| 327 |
+
|
| 328 |
+
ofs = None
|
| 329 |
+
if hasattr(self, 'offset'):
|
| 330 |
+
ofs = self._offset_grp[grp]
|
| 331 |
+
|
| 332 |
+
llg = np.dot(self._xy[grp], params)
|
| 333 |
+
|
| 334 |
+
if ofs is not None:
|
| 335 |
+
llg += self._endofs[grp]
|
| 336 |
+
|
| 337 |
+
llg -= np.log(self._denom(grp, params, ofs))
|
| 338 |
+
|
| 339 |
+
return llg
|
| 340 |
+
|
| 341 |
+
def score_grp(self, grp, params):
|
| 342 |
+
|
| 343 |
+
ofs = 0
|
| 344 |
+
if hasattr(self, 'offset'):
|
| 345 |
+
ofs = self._offset_grp[grp]
|
| 346 |
+
|
| 347 |
+
d, h = self._denom_grad(grp, params, ofs)
|
| 348 |
+
return self._xy[grp] - h / d
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
class ConditionalPoisson(_ConditionalModel):
|
| 352 |
+
"""
|
| 353 |
+
Fit a conditional Poisson regression model to grouped data.
|
| 354 |
+
|
| 355 |
+
Every group is implicitly given an intercept, but the model is fit using
|
| 356 |
+
a conditional likelihood in which the intercepts are not present. Thus,
|
| 357 |
+
intercept estimates are not given, but the other parameter estimates can
|
| 358 |
+
be interpreted as being adjusted for any group-level confounders.
|
| 359 |
+
|
| 360 |
+
Parameters
|
| 361 |
+
----------
|
| 362 |
+
endog : array_like
|
| 363 |
+
The response variable
|
| 364 |
+
exog : array_like
|
| 365 |
+
The covariates
|
| 366 |
+
groups : array_like
|
| 367 |
+
Codes defining the groups. This is a required keyword parameter.
|
| 368 |
+
"""
|
| 369 |
+
|
| 370 |
+
def loglike(self, params):
|
| 371 |
+
|
| 372 |
+
ofs = None
|
| 373 |
+
if hasattr(self, 'offset'):
|
| 374 |
+
ofs = self._offset_grp
|
| 375 |
+
|
| 376 |
+
ll = 0.0
|
| 377 |
+
|
| 378 |
+
for i in range(len(self._endog_grp)):
|
| 379 |
+
|
| 380 |
+
xb = np.dot(self._exog_grp[i], params)
|
| 381 |
+
if ofs is not None:
|
| 382 |
+
xb += ofs[i]
|
| 383 |
+
exb = np.exp(xb)
|
| 384 |
+
y = self._endog_grp[i]
|
| 385 |
+
ll += np.dot(y, xb)
|
| 386 |
+
s = exb.sum()
|
| 387 |
+
ll -= self._sumy[i] * np.log(s)
|
| 388 |
+
|
| 389 |
+
return ll
|
| 390 |
+
|
| 391 |
+
def score(self, params):
|
| 392 |
+
|
| 393 |
+
ofs = None
|
| 394 |
+
if hasattr(self, 'offset'):
|
| 395 |
+
ofs = self._offset_grp
|
| 396 |
+
|
| 397 |
+
score = 0.0
|
| 398 |
+
|
| 399 |
+
for i in range(len(self._endog_grp)):
|
| 400 |
+
|
| 401 |
+
x = self._exog_grp[i]
|
| 402 |
+
xb = np.dot(x, params)
|
| 403 |
+
if ofs is not None:
|
| 404 |
+
xb += ofs[i]
|
| 405 |
+
exb = np.exp(xb)
|
| 406 |
+
s = exb.sum()
|
| 407 |
+
y = self._endog_grp[i]
|
| 408 |
+
score += np.dot(y, x)
|
| 409 |
+
score -= self._sumy[i] * np.dot(exb, x) / s
|
| 410 |
+
|
| 411 |
+
return score
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
class ConditionalResults(base.LikelihoodModelResults):
|
| 415 |
+
def __init__(self, model, params, normalized_cov_params, scale):
|
| 416 |
+
|
| 417 |
+
super().__init__(
|
| 418 |
+
model,
|
| 419 |
+
params,
|
| 420 |
+
normalized_cov_params=normalized_cov_params,
|
| 421 |
+
scale=scale)
|
| 422 |
+
|
| 423 |
+
def summary(self, yname=None, xname=None, title=None, alpha=.05):
|
| 424 |
+
"""
|
| 425 |
+
Summarize the fitted model.
|
| 426 |
+
|
| 427 |
+
Parameters
|
| 428 |
+
----------
|
| 429 |
+
yname : str, optional
|
| 430 |
+
Default is `y`
|
| 431 |
+
xname : list[str], optional
|
| 432 |
+
Names for the exogenous variables, default is "var_xx".
|
| 433 |
+
Must match the number of parameters in the model
|
| 434 |
+
title : str, optional
|
| 435 |
+
Title for the top table. If not None, then this replaces the
|
| 436 |
+
default title
|
| 437 |
+
alpha : float
|
| 438 |
+
Significance level for the confidence intervals
|
| 439 |
+
|
| 440 |
+
Returns
|
| 441 |
+
-------
|
| 442 |
+
smry : Summary instance
|
| 443 |
+
This holds the summary tables and text, which can be printed or
|
| 444 |
+
converted to various output formats.
|
| 445 |
+
|
| 446 |
+
See Also
|
| 447 |
+
--------
|
| 448 |
+
statsmodels.iolib.summary.Summary : class to hold summary
|
| 449 |
+
results
|
| 450 |
+
"""
|
| 451 |
+
|
| 452 |
+
top_left = [
|
| 453 |
+
('Dep. Variable:', None),
|
| 454 |
+
('Model:', None),
|
| 455 |
+
('Log-Likelihood:', None),
|
| 456 |
+
('Method:', [self.method]),
|
| 457 |
+
('Date:', None),
|
| 458 |
+
('Time:', None),
|
| 459 |
+
]
|
| 460 |
+
|
| 461 |
+
top_right = [
|
| 462 |
+
('No. Observations:', None),
|
| 463 |
+
('No. groups:', [self.n_groups]),
|
| 464 |
+
('Min group size:', [self._group_stats[0]]),
|
| 465 |
+
('Max group size:', [self._group_stats[1]]),
|
| 466 |
+
('Mean group size:', [self._group_stats[2]]),
|
| 467 |
+
]
|
| 468 |
+
|
| 469 |
+
if title is None:
|
| 470 |
+
title = "Conditional Logit Model Regression Results"
|
| 471 |
+
|
| 472 |
+
# create summary tables
|
| 473 |
+
from statsmodels.iolib.summary import Summary
|
| 474 |
+
smry = Summary()
|
| 475 |
+
smry.add_table_2cols(
|
| 476 |
+
self,
|
| 477 |
+
gleft=top_left,
|
| 478 |
+
gright=top_right, # [],
|
| 479 |
+
yname=yname,
|
| 480 |
+
xname=xname,
|
| 481 |
+
title=title)
|
| 482 |
+
smry.add_table_params(
|
| 483 |
+
self, yname=yname, xname=xname, alpha=alpha, use_t=self.use_t)
|
| 484 |
+
|
| 485 |
+
return smry
|
| 486 |
+
|
| 487 |
+
class ConditionalMNLogit(_ConditionalModel):
|
| 488 |
+
"""
|
| 489 |
+
Fit a conditional multinomial logit model to grouped data.
|
| 490 |
+
|
| 491 |
+
Parameters
|
| 492 |
+
----------
|
| 493 |
+
endog : array_like
|
| 494 |
+
The dependent variable, must be integer-valued, coded
|
| 495 |
+
0, 1, ..., c-1, where c is the number of response
|
| 496 |
+
categories.
|
| 497 |
+
exog : array_like
|
| 498 |
+
The independent variables.
|
| 499 |
+
groups : array_like
|
| 500 |
+
Codes defining the groups. This is a required keyword parameter.
|
| 501 |
+
|
| 502 |
+
Notes
|
| 503 |
+
-----
|
| 504 |
+
Equivalent to femlogit in Stata.
|
| 505 |
+
|
| 506 |
+
References
|
| 507 |
+
----------
|
| 508 |
+
Gary Chamberlain (1980). Analysis of covariance with qualitative
|
| 509 |
+
data. The Review of Economic Studies. Vol. 47, No. 1, pp. 225-238.
|
| 510 |
+
"""
|
| 511 |
+
|
| 512 |
+
def __init__(self, endog, exog, missing='none', **kwargs):
|
| 513 |
+
|
| 514 |
+
super().__init__(
|
| 515 |
+
endog, exog, missing=missing, **kwargs)
|
| 516 |
+
|
| 517 |
+
# endog must be integers
|
| 518 |
+
self.endog = self.endog.astype(int)
|
| 519 |
+
|
| 520 |
+
self.k_cat = self.endog.max() + 1
|
| 521 |
+
self.df_model = (self.k_cat - 1) * self.exog.shape[1]
|
| 522 |
+
self.df_resid = self.nobs - self.df_model
|
| 523 |
+
self._ynames_map = {j: str(j) for j in range(self.k_cat)}
|
| 524 |
+
self.J = self.k_cat # Unfortunate name, needed for results
|
| 525 |
+
self.K = self.exog.shape[1] # for compatibility with MNLogit
|
| 526 |
+
|
| 527 |
+
if self.endog.min() < 0:
|
| 528 |
+
msg = "endog may not contain negative values"
|
| 529 |
+
raise ValueError(msg)
|
| 530 |
+
|
| 531 |
+
grx = collections.defaultdict(list)
|
| 532 |
+
for k, v in enumerate(self.groups):
|
| 533 |
+
grx[v].append(k)
|
| 534 |
+
self._group_labels = list(grx.keys())
|
| 535 |
+
self._group_labels.sort()
|
| 536 |
+
self._grp_ix = [grx[k] for k in self._group_labels]
|
| 537 |
+
|
| 538 |
+
def fit(self,
|
| 539 |
+
start_params=None,
|
| 540 |
+
method='BFGS',
|
| 541 |
+
maxiter=100,
|
| 542 |
+
full_output=True,
|
| 543 |
+
disp=False,
|
| 544 |
+
fargs=(),
|
| 545 |
+
callback=None,
|
| 546 |
+
retall=False,
|
| 547 |
+
skip_hessian=False,
|
| 548 |
+
**kwargs):
|
| 549 |
+
|
| 550 |
+
if start_params is None:
|
| 551 |
+
q = self.exog.shape[1]
|
| 552 |
+
c = self.k_cat - 1
|
| 553 |
+
start_params = np.random.normal(size=q * c)
|
| 554 |
+
|
| 555 |
+
# Do not call super(...).fit because it cannot handle the 2d-params.
|
| 556 |
+
rslt = base.LikelihoodModel.fit(
|
| 557 |
+
self,
|
| 558 |
+
start_params=start_params,
|
| 559 |
+
method=method,
|
| 560 |
+
maxiter=maxiter,
|
| 561 |
+
full_output=full_output,
|
| 562 |
+
disp=disp,
|
| 563 |
+
skip_hessian=skip_hessian)
|
| 564 |
+
|
| 565 |
+
rslt.params = rslt.params.reshape((self.exog.shape[1], -1))
|
| 566 |
+
rslt = MultinomialResults(self, rslt)
|
| 567 |
+
|
| 568 |
+
# Not clear what the null likelihood should be, there is no intercept
|
| 569 |
+
# so the null model is not clearly defined. This is needed for summary
|
| 570 |
+
# to work.
|
| 571 |
+
rslt.set_null_options(llnull=np.nan)
|
| 572 |
+
|
| 573 |
+
return MultinomialResultsWrapper(rslt)
|
| 574 |
+
|
| 575 |
+
def loglike(self, params):
|
| 576 |
+
|
| 577 |
+
q = self.exog.shape[1]
|
| 578 |
+
c = self.k_cat - 1
|
| 579 |
+
|
| 580 |
+
pmat = params.reshape((q, c))
|
| 581 |
+
pmat = np.concatenate((np.zeros((q, 1)), pmat), axis=1)
|
| 582 |
+
lpr = np.dot(self.exog, pmat)
|
| 583 |
+
|
| 584 |
+
ll = 0.0
|
| 585 |
+
for ii in self._grp_ix:
|
| 586 |
+
x = lpr[ii, :]
|
| 587 |
+
jj = np.arange(x.shape[0], dtype=int)
|
| 588 |
+
y = self.endog[ii]
|
| 589 |
+
denom = 0.0
|
| 590 |
+
for p in itertools.permutations(y):
|
| 591 |
+
denom += np.exp(x[(jj, p)].sum())
|
| 592 |
+
ll += x[(jj, y)].sum() - np.log(denom)
|
| 593 |
+
|
| 594 |
+
return ll
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
def score(self, params):
|
| 598 |
+
|
| 599 |
+
q = self.exog.shape[1]
|
| 600 |
+
c = self.k_cat - 1
|
| 601 |
+
|
| 602 |
+
pmat = params.reshape((q, c))
|
| 603 |
+
pmat = np.concatenate((np.zeros((q, 1)), pmat), axis=1)
|
| 604 |
+
lpr = np.dot(self.exog, pmat)
|
| 605 |
+
|
| 606 |
+
grad = np.zeros((q, c))
|
| 607 |
+
for ii in self._grp_ix:
|
| 608 |
+
x = lpr[ii, :]
|
| 609 |
+
jj = np.arange(x.shape[0], dtype=int)
|
| 610 |
+
y = self.endog[ii]
|
| 611 |
+
denom = 0.0
|
| 612 |
+
denomg = np.zeros((q, c))
|
| 613 |
+
for p in itertools.permutations(y):
|
| 614 |
+
v = np.exp(x[(jj, p)].sum())
|
| 615 |
+
denom += v
|
| 616 |
+
for i, r in enumerate(p):
|
| 617 |
+
if r != 0:
|
| 618 |
+
denomg[:, r - 1] += v * self.exog[ii[i], :]
|
| 619 |
+
|
| 620 |
+
for i, r in enumerate(y):
|
| 621 |
+
if r != 0:
|
| 622 |
+
grad[:, r - 1] += self.exog[ii[i], :]
|
| 623 |
+
|
| 624 |
+
grad -= denomg / denom
|
| 625 |
+
|
| 626 |
+
return grad.flatten()
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
|
| 630 |
+
class ConditionalResultsWrapper(lm.RegressionResultsWrapper):
|
| 631 |
+
pass
|
| 632 |
+
|
| 633 |
+
|
| 634 |
+
wrap.populate_wrapper(ConditionalResultsWrapper, ConditionalResults)
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/count_model.py
ADDED
|
@@ -0,0 +1,1140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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son",
|
| 2 |
+
"ZeroInflatedNegativeBinomialP"]
|
| 3 |
+
|
| 4 |
+
import warnings
|
| 5 |
+
import numpy as np
|
| 6 |
+
import statsmodels.base.model as base
|
| 7 |
+
import statsmodels.base.wrapper as wrap
|
| 8 |
+
import statsmodels.regression.linear_model as lm
|
| 9 |
+
from statsmodels.discrete.discrete_model import (DiscreteModel, CountModel,
|
| 10 |
+
Poisson, Logit, CountResults,
|
| 11 |
+
L1CountResults, Probit,
|
| 12 |
+
_discrete_results_docs,
|
| 13 |
+
_validate_l1_method,
|
| 14 |
+
GeneralizedPoisson,
|
| 15 |
+
NegativeBinomialP)
|
| 16 |
+
from statsmodels.distributions import zipoisson, zigenpoisson, zinegbin
|
| 17 |
+
from statsmodels.tools.numdiff import approx_fprime, approx_hess
|
| 18 |
+
from statsmodels.tools.decorators import cache_readonly
|
| 19 |
+
from statsmodels.tools.sm_exceptions import ConvergenceWarning
|
| 20 |
+
from statsmodels.compat.pandas import Appender
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_doc_zi_params = """
|
| 24 |
+
exog_infl : array_like or None
|
| 25 |
+
Explanatory variables for the binary inflation model, i.e. for
|
| 26 |
+
mixing probability model. If None, then a constant is used.
|
| 27 |
+
offset : array_like
|
| 28 |
+
Offset is added to the linear prediction with coefficient equal to 1.
|
| 29 |
+
exposure : array_like
|
| 30 |
+
Log(exposure) is added to the linear prediction with coefficient
|
| 31 |
+
equal to 1.
|
| 32 |
+
inflation : {'logit', 'probit'}
|
| 33 |
+
The model for the zero inflation, either Logit (default) or Probit
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class GenericZeroInflated(CountModel):
|
| 38 |
+
__doc__ = """
|
| 39 |
+
Generic Zero Inflated Model
|
| 40 |
+
|
| 41 |
+
%(params)s
|
| 42 |
+
%(extra_params)s
|
| 43 |
+
|
| 44 |
+
Attributes
|
| 45 |
+
----------
|
| 46 |
+
endog : ndarray
|
| 47 |
+
A reference to the endogenous response variable
|
| 48 |
+
exog : ndarray
|
| 49 |
+
A reference to the exogenous design.
|
| 50 |
+
exog_infl : ndarray
|
| 51 |
+
A reference to the zero-inflated exogenous design.
|
| 52 |
+
""" % {'params' : base._model_params_doc,
|
| 53 |
+
'extra_params' : _doc_zi_params + base._missing_param_doc}
|
| 54 |
+
|
| 55 |
+
def __init__(self, endog, exog, exog_infl=None, offset=None,
|
| 56 |
+
inflation='logit', exposure=None, missing='none', **kwargs):
|
| 57 |
+
super().__init__(endog, exog, offset=offset,
|
| 58 |
+
exposure=exposure,
|
| 59 |
+
missing=missing, **kwargs)
|
| 60 |
+
|
| 61 |
+
if exog_infl is None:
|
| 62 |
+
self.k_inflate = 1
|
| 63 |
+
self._no_exog_infl = True
|
| 64 |
+
self.exog_infl = np.ones((endog.size, self.k_inflate),
|
| 65 |
+
dtype=np.float64)
|
| 66 |
+
else:
|
| 67 |
+
self.exog_infl = exog_infl
|
| 68 |
+
self.k_inflate = exog_infl.shape[1]
|
| 69 |
+
self._no_exog_infl = False
|
| 70 |
+
|
| 71 |
+
if len(exog.shape) == 1:
|
| 72 |
+
self.k_exog = 1
|
| 73 |
+
else:
|
| 74 |
+
self.k_exog = exog.shape[1]
|
| 75 |
+
|
| 76 |
+
self.infl = inflation
|
| 77 |
+
if inflation == 'logit':
|
| 78 |
+
self.model_infl = Logit(np.zeros(self.exog_infl.shape[0]),
|
| 79 |
+
self.exog_infl)
|
| 80 |
+
self._hessian_inflate = self._hessian_logit
|
| 81 |
+
elif inflation == 'probit':
|
| 82 |
+
self.model_infl = Probit(np.zeros(self.exog_infl.shape[0]),
|
| 83 |
+
self.exog_infl)
|
| 84 |
+
self._hessian_inflate = self._hessian_probit
|
| 85 |
+
|
| 86 |
+
else:
|
| 87 |
+
raise ValueError("inflation == %s, which is not handled"
|
| 88 |
+
% inflation)
|
| 89 |
+
|
| 90 |
+
self.inflation = inflation
|
| 91 |
+
self.k_extra = self.k_inflate
|
| 92 |
+
|
| 93 |
+
if len(self.exog) != len(self.exog_infl):
|
| 94 |
+
raise ValueError('exog and exog_infl have different number of'
|
| 95 |
+
'observation. `missing` handling is not supported')
|
| 96 |
+
|
| 97 |
+
infl_names = ['inflate_%s' % i for i in self.model_infl.data.param_names]
|
| 98 |
+
self.exog_names[:] = infl_names + list(self.exog_names)
|
| 99 |
+
self.exog_infl = np.asarray(self.exog_infl, dtype=np.float64)
|
| 100 |
+
|
| 101 |
+
self._init_keys.extend(['exog_infl', 'inflation'])
|
| 102 |
+
self._null_drop_keys = ['exog_infl']
|
| 103 |
+
|
| 104 |
+
def _get_exogs(self):
|
| 105 |
+
"""list of exogs, for internal use in post-estimation
|
| 106 |
+
"""
|
| 107 |
+
return (self.exog, self.exog_infl)
|
| 108 |
+
|
| 109 |
+
def loglike(self, params):
|
| 110 |
+
"""
|
| 111 |
+
Loglikelihood of Generic Zero Inflated model.
|
| 112 |
+
|
| 113 |
+
Parameters
|
| 114 |
+
----------
|
| 115 |
+
params : array_like
|
| 116 |
+
The parameters of the model.
|
| 117 |
+
|
| 118 |
+
Returns
|
| 119 |
+
-------
|
| 120 |
+
loglike : float
|
| 121 |
+
The log-likelihood function of the model evaluated at `params`.
|
| 122 |
+
See notes.
|
| 123 |
+
|
| 124 |
+
Notes
|
| 125 |
+
-----
|
| 126 |
+
.. math:: \\ln L=\\sum_{y_{i}=0}\\ln(w_{i}+(1-w_{i})*P_{main\\_model})+
|
| 127 |
+
\\sum_{y_{i}>0}(\\ln(1-w_{i})+L_{main\\_model})
|
| 128 |
+
where P - pdf of main model, L - loglike function of main model.
|
| 129 |
+
"""
|
| 130 |
+
return np.sum(self.loglikeobs(params))
|
| 131 |
+
|
| 132 |
+
def loglikeobs(self, params):
|
| 133 |
+
"""
|
| 134 |
+
Loglikelihood for observations of Generic Zero Inflated model.
|
| 135 |
+
|
| 136 |
+
Parameters
|
| 137 |
+
----------
|
| 138 |
+
params : array_like
|
| 139 |
+
The parameters of the model.
|
| 140 |
+
|
| 141 |
+
Returns
|
| 142 |
+
-------
|
| 143 |
+
loglike : ndarray
|
| 144 |
+
The log likelihood for each observation of the model evaluated
|
| 145 |
+
at `params`. See Notes for definition.
|
| 146 |
+
|
| 147 |
+
Notes
|
| 148 |
+
-----
|
| 149 |
+
.. math:: \\ln L=\\ln(w_{i}+(1-w_{i})*P_{main\\_model})+
|
| 150 |
+
\\ln(1-w_{i})+L_{main\\_model}
|
| 151 |
+
where P - pdf of main model, L - loglike function of main model.
|
| 152 |
+
|
| 153 |
+
for observations :math:`i=1,...,n`
|
| 154 |
+
"""
|
| 155 |
+
params_infl = params[:self.k_inflate]
|
| 156 |
+
params_main = params[self.k_inflate:]
|
| 157 |
+
|
| 158 |
+
y = self.endog
|
| 159 |
+
w = self.model_infl.predict(params_infl)
|
| 160 |
+
|
| 161 |
+
w = np.clip(w, np.finfo(float).eps, 1 - np.finfo(float).eps)
|
| 162 |
+
llf_main = self.model_main.loglikeobs(params_main)
|
| 163 |
+
zero_idx = np.nonzero(y == 0)[0]
|
| 164 |
+
nonzero_idx = np.nonzero(y)[0]
|
| 165 |
+
|
| 166 |
+
llf = np.zeros_like(y, dtype=np.float64)
|
| 167 |
+
llf[zero_idx] = (np.log(w[zero_idx] +
|
| 168 |
+
(1 - w[zero_idx]) * np.exp(llf_main[zero_idx])))
|
| 169 |
+
llf[nonzero_idx] = np.log(1 - w[nonzero_idx]) + llf_main[nonzero_idx]
|
| 170 |
+
|
| 171 |
+
return llf
|
| 172 |
+
|
| 173 |
+
@Appender(DiscreteModel.fit.__doc__)
|
| 174 |
+
def fit(self, start_params=None, method='bfgs', maxiter=35,
|
| 175 |
+
full_output=1, disp=1, callback=None,
|
| 176 |
+
cov_type='nonrobust', cov_kwds=None, use_t=None, **kwargs):
|
| 177 |
+
if start_params is None:
|
| 178 |
+
offset = getattr(self, "offset", 0) + getattr(self, "exposure", 0)
|
| 179 |
+
if np.size(offset) == 1 and offset == 0:
|
| 180 |
+
offset = None
|
| 181 |
+
start_params = self._get_start_params()
|
| 182 |
+
|
| 183 |
+
if callback is None:
|
| 184 |
+
# work around perfect separation callback #3895
|
| 185 |
+
callback = lambda *x: x
|
| 186 |
+
|
| 187 |
+
mlefit = super().fit(start_params=start_params,
|
| 188 |
+
maxiter=maxiter, disp=disp, method=method,
|
| 189 |
+
full_output=full_output, callback=callback,
|
| 190 |
+
**kwargs)
|
| 191 |
+
|
| 192 |
+
zipfit = self.result_class(self, mlefit._results)
|
| 193 |
+
result = self.result_class_wrapper(zipfit)
|
| 194 |
+
|
| 195 |
+
if cov_kwds is None:
|
| 196 |
+
cov_kwds = {}
|
| 197 |
+
|
| 198 |
+
result._get_robustcov_results(cov_type=cov_type,
|
| 199 |
+
use_self=True, use_t=use_t, **cov_kwds)
|
| 200 |
+
return result
|
| 201 |
+
|
| 202 |
+
@Appender(DiscreteModel.fit_regularized.__doc__)
|
| 203 |
+
def fit_regularized(self, start_params=None, method='l1',
|
| 204 |
+
maxiter='defined_by_method', full_output=1, disp=1, callback=None,
|
| 205 |
+
alpha=0, trim_mode='auto', auto_trim_tol=0.01, size_trim_tol=1e-4,
|
| 206 |
+
qc_tol=0.03, **kwargs):
|
| 207 |
+
|
| 208 |
+
_validate_l1_method(method)
|
| 209 |
+
|
| 210 |
+
if np.size(alpha) == 1 and alpha != 0:
|
| 211 |
+
k_params = self.k_exog + self.k_inflate
|
| 212 |
+
alpha = alpha * np.ones(k_params)
|
| 213 |
+
|
| 214 |
+
extra = self.k_extra - self.k_inflate
|
| 215 |
+
alpha_p = alpha[:-(self.k_extra - extra)] if (self.k_extra
|
| 216 |
+
and np.size(alpha) > 1) else alpha
|
| 217 |
+
if start_params is None:
|
| 218 |
+
offset = getattr(self, "offset", 0) + getattr(self, "exposure", 0)
|
| 219 |
+
if np.size(offset) == 1 and offset == 0:
|
| 220 |
+
offset = None
|
| 221 |
+
start_params = self.model_main.fit_regularized(
|
| 222 |
+
start_params=start_params, method=method, maxiter=maxiter,
|
| 223 |
+
full_output=full_output, disp=0, callback=callback,
|
| 224 |
+
alpha=alpha_p, trim_mode=trim_mode, auto_trim_tol=auto_trim_tol,
|
| 225 |
+
size_trim_tol=size_trim_tol, qc_tol=qc_tol, **kwargs).params
|
| 226 |
+
start_params = np.append(np.ones(self.k_inflate), start_params)
|
| 227 |
+
cntfit = super(CountModel, self).fit_regularized(
|
| 228 |
+
start_params=start_params, method=method, maxiter=maxiter,
|
| 229 |
+
full_output=full_output, disp=disp, callback=callback,
|
| 230 |
+
alpha=alpha, trim_mode=trim_mode, auto_trim_tol=auto_trim_tol,
|
| 231 |
+
size_trim_tol=size_trim_tol, qc_tol=qc_tol, **kwargs)
|
| 232 |
+
|
| 233 |
+
discretefit = self.result_class_reg(self, cntfit)
|
| 234 |
+
return self.result_class_reg_wrapper(discretefit)
|
| 235 |
+
|
| 236 |
+
def score_obs(self, params):
|
| 237 |
+
"""
|
| 238 |
+
Generic Zero Inflated model score (gradient) vector of the log-likelihood
|
| 239 |
+
|
| 240 |
+
Parameters
|
| 241 |
+
----------
|
| 242 |
+
params : array_like
|
| 243 |
+
The parameters of the model
|
| 244 |
+
|
| 245 |
+
Returns
|
| 246 |
+
-------
|
| 247 |
+
score : ndarray, 1-D
|
| 248 |
+
The score vector of the model, i.e. the first derivative of the
|
| 249 |
+
loglikelihood function, evaluated at `params`
|
| 250 |
+
"""
|
| 251 |
+
params_infl = params[:self.k_inflate]
|
| 252 |
+
params_main = params[self.k_inflate:]
|
| 253 |
+
|
| 254 |
+
y = self.endog
|
| 255 |
+
w = self.model_infl.predict(params_infl)
|
| 256 |
+
w = np.clip(w, np.finfo(float).eps, 1 - np.finfo(float).eps)
|
| 257 |
+
score_main = self.model_main.score_obs(params_main)
|
| 258 |
+
llf_main = self.model_main.loglikeobs(params_main)
|
| 259 |
+
llf = self.loglikeobs(params)
|
| 260 |
+
zero_idx = np.nonzero(y == 0)[0]
|
| 261 |
+
nonzero_idx = np.nonzero(y)[0]
|
| 262 |
+
|
| 263 |
+
mu = self.model_main.predict(params_main)
|
| 264 |
+
|
| 265 |
+
# TODO: need to allow for complex to use CS numerical derivatives
|
| 266 |
+
dldp = np.zeros((self.exog.shape[0], self.k_exog), dtype=np.float64)
|
| 267 |
+
dldw = np.zeros_like(self.exog_infl, dtype=np.float64)
|
| 268 |
+
|
| 269 |
+
dldp[zero_idx,:] = (score_main[zero_idx].T *
|
| 270 |
+
(1 - (w[zero_idx]) / np.exp(llf[zero_idx]))).T
|
| 271 |
+
dldp[nonzero_idx,:] = score_main[nonzero_idx]
|
| 272 |
+
|
| 273 |
+
if self.inflation == 'logit':
|
| 274 |
+
dldw[zero_idx,:] = (self.exog_infl[zero_idx].T * w[zero_idx] *
|
| 275 |
+
(1 - w[zero_idx]) *
|
| 276 |
+
(1 - np.exp(llf_main[zero_idx])) /
|
| 277 |
+
np.exp(llf[zero_idx])).T
|
| 278 |
+
dldw[nonzero_idx,:] = -(self.exog_infl[nonzero_idx].T *
|
| 279 |
+
w[nonzero_idx]).T
|
| 280 |
+
elif self.inflation == 'probit':
|
| 281 |
+
return approx_fprime(params, self.loglikeobs)
|
| 282 |
+
|
| 283 |
+
return np.hstack((dldw, dldp))
|
| 284 |
+
|
| 285 |
+
def score(self, params):
|
| 286 |
+
return self.score_obs(params).sum(0)
|
| 287 |
+
|
| 288 |
+
def _hessian_main(self, params):
|
| 289 |
+
pass
|
| 290 |
+
|
| 291 |
+
def _hessian_logit(self, params):
|
| 292 |
+
params_infl = params[:self.k_inflate]
|
| 293 |
+
params_main = params[self.k_inflate:]
|
| 294 |
+
|
| 295 |
+
y = self.endog
|
| 296 |
+
w = self.model_infl.predict(params_infl)
|
| 297 |
+
w = np.clip(w, np.finfo(float).eps, 1 - np.finfo(float).eps)
|
| 298 |
+
score_main = self.model_main.score_obs(params_main)
|
| 299 |
+
llf_main = self.model_main.loglikeobs(params_main)
|
| 300 |
+
llf = self.loglikeobs(params)
|
| 301 |
+
zero_idx = np.nonzero(y == 0)[0]
|
| 302 |
+
nonzero_idx = np.nonzero(y)[0]
|
| 303 |
+
|
| 304 |
+
hess_arr = np.zeros((self.k_inflate, self.k_exog + self.k_inflate))
|
| 305 |
+
|
| 306 |
+
pmf = np.exp(llf)
|
| 307 |
+
|
| 308 |
+
#d2l/dw2
|
| 309 |
+
for i in range(self.k_inflate):
|
| 310 |
+
for j in range(i, -1, -1):
|
| 311 |
+
hess_arr[i, j] = ((
|
| 312 |
+
self.exog_infl[zero_idx, i] * self.exog_infl[zero_idx, j] *
|
| 313 |
+
(w[zero_idx] * (1 - w[zero_idx]) * ((1 -
|
| 314 |
+
np.exp(llf_main[zero_idx])) * (1 - 2 * w[zero_idx]) *
|
| 315 |
+
np.exp(llf[zero_idx]) - (w[zero_idx] - w[zero_idx]**2) *
|
| 316 |
+
(1 - np.exp(llf_main[zero_idx]))**2) /
|
| 317 |
+
pmf[zero_idx]**2)).sum() -
|
| 318 |
+
(self.exog_infl[nonzero_idx, i] * self.exog_infl[nonzero_idx, j] *
|
| 319 |
+
w[nonzero_idx] * (1 - w[nonzero_idx])).sum())
|
| 320 |
+
|
| 321 |
+
#d2l/dpdw
|
| 322 |
+
for i in range(self.k_inflate):
|
| 323 |
+
for j in range(self.k_exog):
|
| 324 |
+
hess_arr[i, j + self.k_inflate] = -(score_main[zero_idx, j] *
|
| 325 |
+
w[zero_idx] * (1 - w[zero_idx]) *
|
| 326 |
+
self.exog_infl[zero_idx, i] / pmf[zero_idx]).sum()
|
| 327 |
+
|
| 328 |
+
return hess_arr
|
| 329 |
+
|
| 330 |
+
def _hessian_probit(self, params):
|
| 331 |
+
pass
|
| 332 |
+
|
| 333 |
+
def hessian(self, params):
|
| 334 |
+
"""
|
| 335 |
+
Generic Zero Inflated model Hessian matrix of the loglikelihood
|
| 336 |
+
|
| 337 |
+
Parameters
|
| 338 |
+
----------
|
| 339 |
+
params : array_like
|
| 340 |
+
The parameters of the model
|
| 341 |
+
|
| 342 |
+
Returns
|
| 343 |
+
-------
|
| 344 |
+
hess : ndarray, (k_vars, k_vars)
|
| 345 |
+
The Hessian, second derivative of loglikelihood function,
|
| 346 |
+
evaluated at `params`
|
| 347 |
+
|
| 348 |
+
Notes
|
| 349 |
+
-----
|
| 350 |
+
"""
|
| 351 |
+
hess_arr_main = self._hessian_main(params)
|
| 352 |
+
hess_arr_infl = self._hessian_inflate(params)
|
| 353 |
+
|
| 354 |
+
if hess_arr_main is None or hess_arr_infl is None:
|
| 355 |
+
return approx_hess(params, self.loglike)
|
| 356 |
+
|
| 357 |
+
dim = self.k_exog + self.k_inflate
|
| 358 |
+
|
| 359 |
+
hess_arr = np.zeros((dim, dim))
|
| 360 |
+
|
| 361 |
+
hess_arr[:self.k_inflate,:] = hess_arr_infl
|
| 362 |
+
hess_arr[self.k_inflate:,self.k_inflate:] = hess_arr_main
|
| 363 |
+
|
| 364 |
+
tri_idx = np.triu_indices(self.k_exog + self.k_inflate, k=1)
|
| 365 |
+
hess_arr[tri_idx] = hess_arr.T[tri_idx]
|
| 366 |
+
|
| 367 |
+
return hess_arr
|
| 368 |
+
|
| 369 |
+
def predict(self, params, exog=None, exog_infl=None, exposure=None,
|
| 370 |
+
offset=None, which='mean', y_values=None):
|
| 371 |
+
"""
|
| 372 |
+
Predict expected response or other statistic given exogenous variables.
|
| 373 |
+
|
| 374 |
+
Parameters
|
| 375 |
+
----------
|
| 376 |
+
params : array_like
|
| 377 |
+
The parameters of the model.
|
| 378 |
+
exog : ndarray, optional
|
| 379 |
+
Explanatory variables for the main count model.
|
| 380 |
+
If ``exog`` is None, then the data from the model will be used.
|
| 381 |
+
exog_infl : ndarray, optional
|
| 382 |
+
Explanatory variables for the zero-inflation model.
|
| 383 |
+
``exog_infl`` has to be provided if ``exog`` was provided unless
|
| 384 |
+
``exog_infl`` in the model is only a constant.
|
| 385 |
+
offset : ndarray, optional
|
| 386 |
+
Offset is added to the linear predictor of the mean function with
|
| 387 |
+
coefficient equal to 1.
|
| 388 |
+
Default is zero if exog is not None, and the model offset if exog
|
| 389 |
+
is None.
|
| 390 |
+
exposure : ndarray, optional
|
| 391 |
+
Log(exposure) is added to the linear predictor with coefficient
|
| 392 |
+
equal to 1. If exposure is specified, then it will be logged by
|
| 393 |
+
the method. The user does not need to log it first.
|
| 394 |
+
Default is one if exog is is not None, and it is the model exposure
|
| 395 |
+
if exog is None.
|
| 396 |
+
which : str (optional)
|
| 397 |
+
Statitistic to predict. Default is 'mean'.
|
| 398 |
+
|
| 399 |
+
- 'mean' : the conditional expectation of endog E(y | x). This
|
| 400 |
+
takes inflated zeros into account.
|
| 401 |
+
- 'linear' : the linear predictor of the mean function.
|
| 402 |
+
- 'var' : returns the estimated variance of endog implied by the
|
| 403 |
+
model.
|
| 404 |
+
- 'mean-main' : mean of the main count model
|
| 405 |
+
- 'prob-main' : probability of selecting the main model.
|
| 406 |
+
The probability of zero inflation is ``1 - prob-main``.
|
| 407 |
+
- 'mean-nonzero' : expected value conditional on having observation
|
| 408 |
+
larger than zero, E(y | X, y>0)
|
| 409 |
+
- 'prob-zero' : probability of observing a zero count. P(y=0 | x)
|
| 410 |
+
- 'prob' : probabilities of each count from 0 to max(endog), or
|
| 411 |
+
for y_values if those are provided. This is a multivariate
|
| 412 |
+
return (2-dim when predicting for several observations).
|
| 413 |
+
|
| 414 |
+
y_values : array_like
|
| 415 |
+
Values of the random variable endog at which pmf is evaluated.
|
| 416 |
+
Only used if ``which="prob"``
|
| 417 |
+
"""
|
| 418 |
+
no_exog = False
|
| 419 |
+
if exog is None:
|
| 420 |
+
no_exog = True
|
| 421 |
+
exog = self.exog
|
| 422 |
+
|
| 423 |
+
if exog_infl is None:
|
| 424 |
+
if no_exog:
|
| 425 |
+
exog_infl = self.exog_infl
|
| 426 |
+
else:
|
| 427 |
+
if self._no_exog_infl:
|
| 428 |
+
exog_infl = np.ones((len(exog), 1))
|
| 429 |
+
else:
|
| 430 |
+
exog_infl = np.asarray(exog_infl)
|
| 431 |
+
if exog_infl.ndim == 1 and self.k_inflate == 1:
|
| 432 |
+
exog_infl = exog_infl[:, None]
|
| 433 |
+
|
| 434 |
+
if exposure is None:
|
| 435 |
+
if no_exog:
|
| 436 |
+
exposure = getattr(self, 'exposure', 0)
|
| 437 |
+
else:
|
| 438 |
+
exposure = 0
|
| 439 |
+
else:
|
| 440 |
+
exposure = np.log(exposure)
|
| 441 |
+
|
| 442 |
+
if offset is None:
|
| 443 |
+
if no_exog:
|
| 444 |
+
offset = getattr(self, 'offset', 0)
|
| 445 |
+
else:
|
| 446 |
+
offset = 0
|
| 447 |
+
|
| 448 |
+
params_infl = params[:self.k_inflate]
|
| 449 |
+
params_main = params[self.k_inflate:]
|
| 450 |
+
|
| 451 |
+
prob_main = 1 - self.model_infl.predict(params_infl, exog_infl)
|
| 452 |
+
|
| 453 |
+
lin_pred = np.dot(exog, params_main[:self.exog.shape[1]]) + exposure + offset
|
| 454 |
+
|
| 455 |
+
# Refactor: This is pretty hacky,
|
| 456 |
+
# there should be an appropriate predict method in model_main
|
| 457 |
+
# this is just prob(y=0 | model_main)
|
| 458 |
+
tmp_exog = self.model_main.exog
|
| 459 |
+
tmp_endog = self.model_main.endog
|
| 460 |
+
tmp_offset = getattr(self.model_main, 'offset', False)
|
| 461 |
+
tmp_exposure = getattr(self.model_main, 'exposure', False)
|
| 462 |
+
self.model_main.exog = exog
|
| 463 |
+
self.model_main.endog = np.zeros(exog.shape[0])
|
| 464 |
+
self.model_main.offset = offset
|
| 465 |
+
self.model_main.exposure = exposure
|
| 466 |
+
llf = self.model_main.loglikeobs(params_main)
|
| 467 |
+
self.model_main.exog = tmp_exog
|
| 468 |
+
self.model_main.endog = tmp_endog
|
| 469 |
+
# tmp_offset might be an array with elementwise equality testing
|
| 470 |
+
#if np.size(tmp_offset) == 1 and tmp_offset[0] == 'no':
|
| 471 |
+
if tmp_offset is False:
|
| 472 |
+
del self.model_main.offset
|
| 473 |
+
else:
|
| 474 |
+
self.model_main.offset = tmp_offset
|
| 475 |
+
#if np.size(tmp_exposure) == 1 and tmp_exposure[0] == 'no':
|
| 476 |
+
if tmp_exposure is False:
|
| 477 |
+
del self.model_main.exposure
|
| 478 |
+
else:
|
| 479 |
+
self.model_main.exposure = tmp_exposure
|
| 480 |
+
# end hack
|
| 481 |
+
|
| 482 |
+
prob_zero = (1 - prob_main) + prob_main * np.exp(llf)
|
| 483 |
+
|
| 484 |
+
if which == 'mean':
|
| 485 |
+
return prob_main * np.exp(lin_pred)
|
| 486 |
+
elif which == 'mean-main':
|
| 487 |
+
return np.exp(lin_pred)
|
| 488 |
+
elif which == 'linear':
|
| 489 |
+
return lin_pred
|
| 490 |
+
elif which == 'mean-nonzero':
|
| 491 |
+
return prob_main * np.exp(lin_pred) / (1 - prob_zero)
|
| 492 |
+
elif which == 'prob-zero':
|
| 493 |
+
return prob_zero
|
| 494 |
+
elif which == 'prob-main':
|
| 495 |
+
return prob_main
|
| 496 |
+
elif which == 'var':
|
| 497 |
+
mu = np.exp(lin_pred)
|
| 498 |
+
return self._predict_var(params, mu, 1 - prob_main)
|
| 499 |
+
elif which == 'prob':
|
| 500 |
+
return self._predict_prob(params, exog, exog_infl, exposure,
|
| 501 |
+
offset, y_values=y_values)
|
| 502 |
+
else:
|
| 503 |
+
raise ValueError('which = %s is not available' % which)
|
| 504 |
+
|
| 505 |
+
def _derivative_predict(self, params, exog=None, transform='dydx'):
|
| 506 |
+
"""NotImplemented
|
| 507 |
+
"""
|
| 508 |
+
raise NotImplementedError
|
| 509 |
+
|
| 510 |
+
def _derivative_exog(self, params, exog=None, transform="dydx",
|
| 511 |
+
dummy_idx=None, count_idx=None):
|
| 512 |
+
"""NotImplemented
|
| 513 |
+
"""
|
| 514 |
+
raise NotImplementedError
|
| 515 |
+
|
| 516 |
+
def _deriv_mean_dparams(self, params):
|
| 517 |
+
"""
|
| 518 |
+
Derivative of the expected endog with respect to the parameters.
|
| 519 |
+
|
| 520 |
+
Parameters
|
| 521 |
+
----------
|
| 522 |
+
params : ndarray
|
| 523 |
+
parameter at which score is evaluated
|
| 524 |
+
|
| 525 |
+
Returns
|
| 526 |
+
-------
|
| 527 |
+
The value of the derivative of the expected endog with respect
|
| 528 |
+
to the parameter vector.
|
| 529 |
+
"""
|
| 530 |
+
params_infl = params[:self.k_inflate]
|
| 531 |
+
params_main = params[self.k_inflate:]
|
| 532 |
+
|
| 533 |
+
w = self.model_infl.predict(params_infl)
|
| 534 |
+
w = np.clip(w, np.finfo(float).eps, 1 - np.finfo(float).eps)
|
| 535 |
+
mu = self.model_main.predict(params_main)
|
| 536 |
+
|
| 537 |
+
score_infl = self.model_infl._deriv_mean_dparams(params_infl)
|
| 538 |
+
score_main = self.model_main._deriv_mean_dparams(params_main)
|
| 539 |
+
|
| 540 |
+
dmat_infl = - mu[:, None] * score_infl
|
| 541 |
+
dmat_main = (1 - w[:, None]) * score_main
|
| 542 |
+
|
| 543 |
+
dmat = np.column_stack((dmat_infl, dmat_main))
|
| 544 |
+
return dmat
|
| 545 |
+
|
| 546 |
+
def _deriv_score_obs_dendog(self, params):
|
| 547 |
+
"""derivative of score_obs w.r.t. endog
|
| 548 |
+
|
| 549 |
+
Parameters
|
| 550 |
+
----------
|
| 551 |
+
params : ndarray
|
| 552 |
+
parameter at which score is evaluated
|
| 553 |
+
|
| 554 |
+
Returns
|
| 555 |
+
-------
|
| 556 |
+
derivative : ndarray_2d
|
| 557 |
+
The derivative of the score_obs with respect to endog.
|
| 558 |
+
"""
|
| 559 |
+
raise NotImplementedError
|
| 560 |
+
|
| 561 |
+
# The below currently does not work, discontinuity at zero
|
| 562 |
+
# see https://github.com/statsmodels/statsmodels/pull/7951#issuecomment-996355875 # noqa
|
| 563 |
+
from statsmodels.tools.numdiff import _approx_fprime_scalar
|
| 564 |
+
endog_original = self.endog
|
| 565 |
+
|
| 566 |
+
def f(y):
|
| 567 |
+
if y.ndim == 2 and y.shape[1] == 1:
|
| 568 |
+
y = y[:, 0]
|
| 569 |
+
self.endog = y
|
| 570 |
+
self.model_main.endog = y
|
| 571 |
+
sf = self.score_obs(params)
|
| 572 |
+
self.endog = endog_original
|
| 573 |
+
self.model_main.endog = endog_original
|
| 574 |
+
return sf
|
| 575 |
+
|
| 576 |
+
ds = _approx_fprime_scalar(self.endog[:, None], f, epsilon=1e-2)
|
| 577 |
+
|
| 578 |
+
return ds
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
class ZeroInflatedPoisson(GenericZeroInflated):
|
| 582 |
+
__doc__ = """
|
| 583 |
+
Poisson Zero Inflated Model
|
| 584 |
+
|
| 585 |
+
%(params)s
|
| 586 |
+
%(extra_params)s
|
| 587 |
+
|
| 588 |
+
Attributes
|
| 589 |
+
----------
|
| 590 |
+
endog : ndarray
|
| 591 |
+
A reference to the endogenous response variable
|
| 592 |
+
exog : ndarray
|
| 593 |
+
A reference to the exogenous design.
|
| 594 |
+
exog_infl : ndarray
|
| 595 |
+
A reference to the zero-inflated exogenous design.
|
| 596 |
+
""" % {'params' : base._model_params_doc,
|
| 597 |
+
'extra_params' : _doc_zi_params + base._missing_param_doc}
|
| 598 |
+
|
| 599 |
+
def __init__(self, endog, exog, exog_infl=None, offset=None, exposure=None,
|
| 600 |
+
inflation='logit', missing='none', **kwargs):
|
| 601 |
+
super().__init__(endog, exog, offset=offset,
|
| 602 |
+
inflation=inflation,
|
| 603 |
+
exog_infl=exog_infl,
|
| 604 |
+
exposure=exposure,
|
| 605 |
+
missing=missing, **kwargs)
|
| 606 |
+
self.model_main = Poisson(self.endog, self.exog, offset=offset,
|
| 607 |
+
exposure=exposure)
|
| 608 |
+
self.distribution = zipoisson
|
| 609 |
+
self.result_class = ZeroInflatedPoissonResults
|
| 610 |
+
self.result_class_wrapper = ZeroInflatedPoissonResultsWrapper
|
| 611 |
+
self.result_class_reg = L1ZeroInflatedPoissonResults
|
| 612 |
+
self.result_class_reg_wrapper = L1ZeroInflatedPoissonResultsWrapper
|
| 613 |
+
|
| 614 |
+
def _hessian_main(self, params):
|
| 615 |
+
params_infl = params[:self.k_inflate]
|
| 616 |
+
params_main = params[self.k_inflate:]
|
| 617 |
+
|
| 618 |
+
y = self.endog
|
| 619 |
+
w = self.model_infl.predict(params_infl)
|
| 620 |
+
w = np.clip(w, np.finfo(float).eps, 1 - np.finfo(float).eps)
|
| 621 |
+
score = self.score(params)
|
| 622 |
+
zero_idx = np.nonzero(y == 0)[0]
|
| 623 |
+
nonzero_idx = np.nonzero(y)[0]
|
| 624 |
+
|
| 625 |
+
mu = self.model_main.predict(params_main)
|
| 626 |
+
|
| 627 |
+
hess_arr = np.zeros((self.k_exog, self.k_exog))
|
| 628 |
+
|
| 629 |
+
coeff = (1 + w[zero_idx] * (np.exp(mu[zero_idx]) - 1))
|
| 630 |
+
|
| 631 |
+
#d2l/dp2
|
| 632 |
+
for i in range(self.k_exog):
|
| 633 |
+
for j in range(i, -1, -1):
|
| 634 |
+
hess_arr[i, j] = ((
|
| 635 |
+
self.exog[zero_idx, i] * self.exog[zero_idx, j] *
|
| 636 |
+
mu[zero_idx] * (w[zero_idx] - 1) * (1 / coeff -
|
| 637 |
+
w[zero_idx] * mu[zero_idx] * np.exp(mu[zero_idx]) /
|
| 638 |
+
coeff**2)).sum() - (mu[nonzero_idx] * self.exog[nonzero_idx, i] *
|
| 639 |
+
self.exog[nonzero_idx, j]).sum())
|
| 640 |
+
|
| 641 |
+
return hess_arr
|
| 642 |
+
|
| 643 |
+
def _predict_prob(self, params, exog, exog_infl, exposure, offset,
|
| 644 |
+
y_values=None):
|
| 645 |
+
params_infl = params[:self.k_inflate]
|
| 646 |
+
params_main = params[self.k_inflate:]
|
| 647 |
+
|
| 648 |
+
if y_values is None:
|
| 649 |
+
y_values = np.atleast_2d(np.arange(0, np.max(self.endog)+1))
|
| 650 |
+
|
| 651 |
+
if len(exog_infl.shape) < 2:
|
| 652 |
+
transform = True
|
| 653 |
+
w = np.atleast_2d(
|
| 654 |
+
self.model_infl.predict(params_infl, exog_infl))[:, None]
|
| 655 |
+
else:
|
| 656 |
+
transform = False
|
| 657 |
+
w = self.model_infl.predict(params_infl, exog_infl)[:, None]
|
| 658 |
+
|
| 659 |
+
w = np.clip(w, np.finfo(float).eps, 1 - np.finfo(float).eps)
|
| 660 |
+
mu = self.model_main.predict(params_main, exog,
|
| 661 |
+
offset=offset)[:, None]
|
| 662 |
+
result = self.distribution.pmf(y_values, mu, w)
|
| 663 |
+
return result[0] if transform else result
|
| 664 |
+
|
| 665 |
+
def _predict_var(self, params, mu, prob_infl):
|
| 666 |
+
"""predict values for conditional variance V(endog | exog)
|
| 667 |
+
|
| 668 |
+
Parameters
|
| 669 |
+
----------
|
| 670 |
+
params : array_like
|
| 671 |
+
The model parameters. This is only used to extract extra params
|
| 672 |
+
like dispersion parameter.
|
| 673 |
+
mu : array_like
|
| 674 |
+
Array of mean predictions for main model.
|
| 675 |
+
prob_inlf : array_like
|
| 676 |
+
Array of predicted probabilities of zero-inflation `w`.
|
| 677 |
+
|
| 678 |
+
Returns
|
| 679 |
+
-------
|
| 680 |
+
Predicted conditional variance.
|
| 681 |
+
"""
|
| 682 |
+
w = prob_infl
|
| 683 |
+
var_ = (1 - w) * mu * (1 + w * mu)
|
| 684 |
+
return var_
|
| 685 |
+
|
| 686 |
+
def _get_start_params(self):
|
| 687 |
+
with warnings.catch_warnings():
|
| 688 |
+
warnings.simplefilter("ignore", category=ConvergenceWarning)
|
| 689 |
+
start_params = self.model_main.fit(disp=0, method="nm").params
|
| 690 |
+
start_params = np.append(np.ones(self.k_inflate) * 0.1, start_params)
|
| 691 |
+
return start_params
|
| 692 |
+
|
| 693 |
+
def get_distribution(self, params, exog=None, exog_infl=None,
|
| 694 |
+
exposure=None, offset=None):
|
| 695 |
+
"""Get frozen instance of distribution based on predicted parameters.
|
| 696 |
+
|
| 697 |
+
Parameters
|
| 698 |
+
----------
|
| 699 |
+
params : array_like
|
| 700 |
+
The parameters of the model.
|
| 701 |
+
exog : ndarray, optional
|
| 702 |
+
Explanatory variables for the main count model.
|
| 703 |
+
If ``exog`` is None, then the data from the model will be used.
|
| 704 |
+
exog_infl : ndarray, optional
|
| 705 |
+
Explanatory variables for the zero-inflation model.
|
| 706 |
+
``exog_infl`` has to be provided if ``exog`` was provided unless
|
| 707 |
+
``exog_infl`` in the model is only a constant.
|
| 708 |
+
offset : ndarray, optional
|
| 709 |
+
Offset is added to the linear predictor of the mean function with
|
| 710 |
+
coefficient equal to 1.
|
| 711 |
+
Default is zero if exog is not None, and the model offset if exog
|
| 712 |
+
is None.
|
| 713 |
+
exposure : ndarray, optional
|
| 714 |
+
Log(exposure) is added to the linear predictor of the mean
|
| 715 |
+
function with coefficient equal to 1. If exposure is specified,
|
| 716 |
+
then it will be logged by the method. The user does not need to
|
| 717 |
+
log it first.
|
| 718 |
+
Default is one if exog is is not None, and it is the model exposure
|
| 719 |
+
if exog is None.
|
| 720 |
+
|
| 721 |
+
Returns
|
| 722 |
+
-------
|
| 723 |
+
Instance of frozen scipy distribution subclass.
|
| 724 |
+
"""
|
| 725 |
+
mu = self.predict(params, exog=exog, exog_infl=exog_infl,
|
| 726 |
+
exposure=exposure, offset=offset, which="mean-main")
|
| 727 |
+
w = self.predict(params, exog=exog, exog_infl=exog_infl,
|
| 728 |
+
exposure=exposure, offset=offset, which="prob-main")
|
| 729 |
+
|
| 730 |
+
# distr = self.distribution(mu[:, None], 1 - w[:, None])
|
| 731 |
+
distr = self.distribution(mu, 1 - w)
|
| 732 |
+
return distr
|
| 733 |
+
|
| 734 |
+
|
| 735 |
+
class ZeroInflatedGeneralizedPoisson(GenericZeroInflated):
|
| 736 |
+
__doc__ = """
|
| 737 |
+
Zero Inflated Generalized Poisson Model
|
| 738 |
+
|
| 739 |
+
%(params)s
|
| 740 |
+
%(extra_params)s
|
| 741 |
+
|
| 742 |
+
Attributes
|
| 743 |
+
----------
|
| 744 |
+
endog : ndarray
|
| 745 |
+
A reference to the endogenous response variable
|
| 746 |
+
exog : ndarray
|
| 747 |
+
A reference to the exogenous design.
|
| 748 |
+
exog_infl : ndarray
|
| 749 |
+
A reference to the zero-inflated exogenous design.
|
| 750 |
+
p : scalar
|
| 751 |
+
P denotes parametrizations for ZIGP regression.
|
| 752 |
+
""" % {'params' : base._model_params_doc,
|
| 753 |
+
'extra_params' : _doc_zi_params +
|
| 754 |
+
"""p : float
|
| 755 |
+
dispersion power parameter for the GeneralizedPoisson model. p=1 for
|
| 756 |
+
ZIGP-1 and p=2 for ZIGP-2. Default is p=2
|
| 757 |
+
""" + base._missing_param_doc}
|
| 758 |
+
|
| 759 |
+
def __init__(self, endog, exog, exog_infl=None, offset=None, exposure=None,
|
| 760 |
+
inflation='logit', p=2, missing='none', **kwargs):
|
| 761 |
+
super().__init__(endog, exog,
|
| 762 |
+
offset=offset,
|
| 763 |
+
inflation=inflation,
|
| 764 |
+
exog_infl=exog_infl,
|
| 765 |
+
exposure=exposure,
|
| 766 |
+
missing=missing, **kwargs)
|
| 767 |
+
self.model_main = GeneralizedPoisson(self.endog, self.exog,
|
| 768 |
+
offset=offset, exposure=exposure, p=p)
|
| 769 |
+
self.distribution = zigenpoisson
|
| 770 |
+
self.k_exog += 1
|
| 771 |
+
self.k_extra += 1
|
| 772 |
+
self.exog_names.append("alpha")
|
| 773 |
+
self.result_class = ZeroInflatedGeneralizedPoissonResults
|
| 774 |
+
self.result_class_wrapper = ZeroInflatedGeneralizedPoissonResultsWrapper
|
| 775 |
+
self.result_class_reg = L1ZeroInflatedGeneralizedPoissonResults
|
| 776 |
+
self.result_class_reg_wrapper = L1ZeroInflatedGeneralizedPoissonResultsWrapper
|
| 777 |
+
|
| 778 |
+
def _get_init_kwds(self):
|
| 779 |
+
kwds = super()._get_init_kwds()
|
| 780 |
+
kwds['p'] = self.model_main.parameterization + 1
|
| 781 |
+
return kwds
|
| 782 |
+
|
| 783 |
+
def _predict_prob(self, params, exog, exog_infl, exposure, offset,
|
| 784 |
+
y_values=None):
|
| 785 |
+
params_infl = params[:self.k_inflate]
|
| 786 |
+
params_main = params[self.k_inflate:]
|
| 787 |
+
|
| 788 |
+
p = self.model_main.parameterization + 1
|
| 789 |
+
if y_values is None:
|
| 790 |
+
y_values = np.atleast_2d(np.arange(0, np.max(self.endog)+1))
|
| 791 |
+
|
| 792 |
+
if len(exog_infl.shape) < 2:
|
| 793 |
+
transform = True
|
| 794 |
+
w = np.atleast_2d(
|
| 795 |
+
self.model_infl.predict(params_infl, exog_infl))[:, None]
|
| 796 |
+
else:
|
| 797 |
+
transform = False
|
| 798 |
+
w = self.model_infl.predict(params_infl, exog_infl)[:, None]
|
| 799 |
+
|
| 800 |
+
w[w == 1.] = np.nextafter(1, 0)
|
| 801 |
+
mu = self.model_main.predict(params_main, exog,
|
| 802 |
+
exposure=exposure, offset=offset)[:, None]
|
| 803 |
+
result = self.distribution.pmf(y_values, mu, params_main[-1], p, w)
|
| 804 |
+
return result[0] if transform else result
|
| 805 |
+
|
| 806 |
+
def _predict_var(self, params, mu, prob_infl):
|
| 807 |
+
"""predict values for conditional variance V(endog | exog)
|
| 808 |
+
|
| 809 |
+
Parameters
|
| 810 |
+
----------
|
| 811 |
+
params : array_like
|
| 812 |
+
The model parameters. This is only used to extract extra params
|
| 813 |
+
like dispersion parameter.
|
| 814 |
+
mu : array_like
|
| 815 |
+
Array of mean predictions for main model.
|
| 816 |
+
prob_inlf : array_like
|
| 817 |
+
Array of predicted probabilities of zero-inflation `w`.
|
| 818 |
+
|
| 819 |
+
Returns
|
| 820 |
+
-------
|
| 821 |
+
Predicted conditional variance.
|
| 822 |
+
"""
|
| 823 |
+
alpha = params[-1]
|
| 824 |
+
w = prob_infl
|
| 825 |
+
p = self.model_main.parameterization
|
| 826 |
+
var_ = (1 - w) * mu * ((1 + alpha * mu**p)**2 + w * mu)
|
| 827 |
+
return var_
|
| 828 |
+
|
| 829 |
+
def _get_start_params(self):
|
| 830 |
+
with warnings.catch_warnings():
|
| 831 |
+
warnings.simplefilter("ignore", category=ConvergenceWarning)
|
| 832 |
+
start_params = ZeroInflatedPoisson(self.endog, self.exog,
|
| 833 |
+
exog_infl=self.exog_infl).fit(disp=0).params
|
| 834 |
+
start_params = np.append(start_params, 0.1)
|
| 835 |
+
return start_params
|
| 836 |
+
|
| 837 |
+
@Appender(ZeroInflatedPoisson.get_distribution.__doc__)
|
| 838 |
+
def get_distribution(self, params, exog=None, exog_infl=None,
|
| 839 |
+
exposure=None, offset=None):
|
| 840 |
+
|
| 841 |
+
p = self.model_main.parameterization + 1
|
| 842 |
+
mu = self.predict(params, exog=exog, exog_infl=exog_infl,
|
| 843 |
+
exposure=exposure, offset=offset, which="mean-main")
|
| 844 |
+
w = self.predict(params, exog=exog, exog_infl=exog_infl,
|
| 845 |
+
exposure=exposure, offset=offset, which="prob-main")
|
| 846 |
+
# distr = self.distribution(mu[:, None], params[-1], p, 1 - w[:, None])
|
| 847 |
+
distr = self.distribution(mu, params[-1], p, 1 - w)
|
| 848 |
+
return distr
|
| 849 |
+
|
| 850 |
+
|
| 851 |
+
class ZeroInflatedNegativeBinomialP(GenericZeroInflated):
|
| 852 |
+
__doc__ = """
|
| 853 |
+
Zero Inflated Generalized Negative Binomial Model
|
| 854 |
+
|
| 855 |
+
%(params)s
|
| 856 |
+
%(extra_params)s
|
| 857 |
+
|
| 858 |
+
Attributes
|
| 859 |
+
----------
|
| 860 |
+
endog : ndarray
|
| 861 |
+
A reference to the endogenous response variable
|
| 862 |
+
exog : ndarray
|
| 863 |
+
A reference to the exogenous design.
|
| 864 |
+
exog_infl : ndarray
|
| 865 |
+
A reference to the zero-inflated exogenous design.
|
| 866 |
+
p : scalar
|
| 867 |
+
P denotes parametrizations for ZINB regression. p=1 for ZINB-1 and
|
| 868 |
+
p=2 for ZINB-2. Default is p=2
|
| 869 |
+
""" % {'params' : base._model_params_doc,
|
| 870 |
+
'extra_params' : _doc_zi_params +
|
| 871 |
+
"""p : float
|
| 872 |
+
dispersion power parameter for the NegativeBinomialP model. p=1 for
|
| 873 |
+
ZINB-1 and p=2 for ZINM-2. Default is p=2
|
| 874 |
+
""" + base._missing_param_doc}
|
| 875 |
+
|
| 876 |
+
def __init__(self, endog, exog, exog_infl=None, offset=None, exposure=None,
|
| 877 |
+
inflation='logit', p=2, missing='none', **kwargs):
|
| 878 |
+
super().__init__(endog, exog,
|
| 879 |
+
offset=offset,
|
| 880 |
+
inflation=inflation,
|
| 881 |
+
exog_infl=exog_infl,
|
| 882 |
+
exposure=exposure,
|
| 883 |
+
missing=missing, **kwargs)
|
| 884 |
+
self.model_main = NegativeBinomialP(self.endog, self.exog,
|
| 885 |
+
offset=offset, exposure=exposure, p=p)
|
| 886 |
+
self.distribution = zinegbin
|
| 887 |
+
self.k_exog += 1
|
| 888 |
+
self.k_extra += 1
|
| 889 |
+
self.exog_names.append("alpha")
|
| 890 |
+
self.result_class = ZeroInflatedNegativeBinomialResults
|
| 891 |
+
self.result_class_wrapper = ZeroInflatedNegativeBinomialResultsWrapper
|
| 892 |
+
self.result_class_reg = L1ZeroInflatedNegativeBinomialResults
|
| 893 |
+
self.result_class_reg_wrapper = L1ZeroInflatedNegativeBinomialResultsWrapper
|
| 894 |
+
|
| 895 |
+
def _get_init_kwds(self):
|
| 896 |
+
kwds = super()._get_init_kwds()
|
| 897 |
+
kwds['p'] = self.model_main.parameterization
|
| 898 |
+
return kwds
|
| 899 |
+
|
| 900 |
+
def _predict_prob(self, params, exog, exog_infl, exposure, offset,
|
| 901 |
+
y_values=None):
|
| 902 |
+
params_infl = params[:self.k_inflate]
|
| 903 |
+
params_main = params[self.k_inflate:]
|
| 904 |
+
|
| 905 |
+
p = self.model_main.parameterization
|
| 906 |
+
if y_values is None:
|
| 907 |
+
y_values = np.arange(0, np.max(self.endog)+1)
|
| 908 |
+
|
| 909 |
+
if len(exog_infl.shape) < 2:
|
| 910 |
+
transform = True
|
| 911 |
+
w = np.atleast_2d(
|
| 912 |
+
self.model_infl.predict(params_infl, exog_infl))[:, None]
|
| 913 |
+
else:
|
| 914 |
+
transform = False
|
| 915 |
+
w = self.model_infl.predict(params_infl, exog_infl)[:, None]
|
| 916 |
+
|
| 917 |
+
w = np.clip(w, np.finfo(float).eps, 1 - np.finfo(float).eps)
|
| 918 |
+
mu = self.model_main.predict(params_main, exog,
|
| 919 |
+
exposure=exposure, offset=offset)[:, None]
|
| 920 |
+
result = self.distribution.pmf(y_values, mu, params_main[-1], p, w)
|
| 921 |
+
return result[0] if transform else result
|
| 922 |
+
|
| 923 |
+
def _predict_var(self, params, mu, prob_infl):
|
| 924 |
+
"""predict values for conditional variance V(endog | exog)
|
| 925 |
+
|
| 926 |
+
Parameters
|
| 927 |
+
----------
|
| 928 |
+
params : array_like
|
| 929 |
+
The model parameters. This is only used to extract extra params
|
| 930 |
+
like dispersion parameter.
|
| 931 |
+
mu : array_like
|
| 932 |
+
Array of mean predictions for main model.
|
| 933 |
+
prob_inlf : array_like
|
| 934 |
+
Array of predicted probabilities of zero-inflation `w`.
|
| 935 |
+
|
| 936 |
+
Returns
|
| 937 |
+
-------
|
| 938 |
+
Predicted conditional variance.
|
| 939 |
+
"""
|
| 940 |
+
alpha = params[-1]
|
| 941 |
+
w = prob_infl
|
| 942 |
+
p = self.model_main.parameterization
|
| 943 |
+
var_ = (1 - w) * mu * (1 + alpha * mu**(p - 1) + w * mu)
|
| 944 |
+
return var_
|
| 945 |
+
|
| 946 |
+
def _get_start_params(self):
|
| 947 |
+
with warnings.catch_warnings():
|
| 948 |
+
warnings.simplefilter("ignore", category=ConvergenceWarning)
|
| 949 |
+
start_params = self.model_main.fit(disp=0, method='nm').params
|
| 950 |
+
start_params = np.append(np.zeros(self.k_inflate), start_params)
|
| 951 |
+
return start_params
|
| 952 |
+
|
| 953 |
+
@Appender(ZeroInflatedPoisson.get_distribution.__doc__)
|
| 954 |
+
def get_distribution(self, params, exog=None, exog_infl=None,
|
| 955 |
+
exposure=None, offset=None):
|
| 956 |
+
|
| 957 |
+
p = self.model_main.parameterization
|
| 958 |
+
mu = self.predict(params, exog=exog, exog_infl=exog_infl,
|
| 959 |
+
exposure=exposure, offset=offset, which="mean-main")
|
| 960 |
+
w = self.predict(params, exog=exog, exog_infl=exog_infl,
|
| 961 |
+
exposure=exposure, offset=offset, which="prob-main")
|
| 962 |
+
|
| 963 |
+
# distr = self.distribution(mu[:, None], params[-1], p, 1 - w[:, None])
|
| 964 |
+
distr = self.distribution(mu, params[-1], p, 1 - w)
|
| 965 |
+
return distr
|
| 966 |
+
|
| 967 |
+
|
| 968 |
+
class ZeroInflatedResults(CountResults):
|
| 969 |
+
|
| 970 |
+
def get_prediction(self, exog=None, exog_infl=None, exposure=None,
|
| 971 |
+
offset=None, which='mean', average=False,
|
| 972 |
+
agg_weights=None, y_values=None,
|
| 973 |
+
transform=True, row_labels=None):
|
| 974 |
+
|
| 975 |
+
import statsmodels.base._prediction_inference as pred
|
| 976 |
+
|
| 977 |
+
pred_kwds = {
|
| 978 |
+
'exog_infl': exog_infl,
|
| 979 |
+
'exposure': exposure,
|
| 980 |
+
'offset': offset,
|
| 981 |
+
'y_values': y_values,
|
| 982 |
+
}
|
| 983 |
+
|
| 984 |
+
res = pred.get_prediction_delta(self, exog=exog, which=which,
|
| 985 |
+
average=average,
|
| 986 |
+
agg_weights=agg_weights,
|
| 987 |
+
pred_kwds=pred_kwds)
|
| 988 |
+
return res
|
| 989 |
+
|
| 990 |
+
def get_influence(self):
|
| 991 |
+
"""
|
| 992 |
+
Influence and outlier measures
|
| 993 |
+
|
| 994 |
+
See notes section for influence measures that do not apply for
|
| 995 |
+
zero inflated models.
|
| 996 |
+
|
| 997 |
+
Returns
|
| 998 |
+
-------
|
| 999 |
+
MLEInfluence
|
| 1000 |
+
The instance has methods to calculate the main influence and
|
| 1001 |
+
outlier measures as attributes.
|
| 1002 |
+
|
| 1003 |
+
See Also
|
| 1004 |
+
--------
|
| 1005 |
+
statsmodels.stats.outliers_influence.MLEInfluence
|
| 1006 |
+
|
| 1007 |
+
Notes
|
| 1008 |
+
-----
|
| 1009 |
+
ZeroInflated models have functions that are not differentiable
|
| 1010 |
+
with respect to sample endog if endog=0. This means that generalized
|
| 1011 |
+
leverage cannot be computed in the usual definition.
|
| 1012 |
+
|
| 1013 |
+
Currently, both the generalized leverage, in `hat_matrix_diag`
|
| 1014 |
+
attribute and studetized residuals are not available. In the influence
|
| 1015 |
+
plot generalized leverage is replaced by a hat matrix diagonal that
|
| 1016 |
+
only takes combined exog into account, computed in the same way as
|
| 1017 |
+
for OLS. This is a measure for exog outliers but does not take
|
| 1018 |
+
specific features of the model into account.
|
| 1019 |
+
"""
|
| 1020 |
+
# same as sumper in DiscreteResults, only added for docstring
|
| 1021 |
+
from statsmodels.stats.outliers_influence import MLEInfluence
|
| 1022 |
+
return MLEInfluence(self)
|
| 1023 |
+
|
| 1024 |
+
|
| 1025 |
+
class ZeroInflatedPoissonResults(ZeroInflatedResults):
|
| 1026 |
+
__doc__ = _discrete_results_docs % {
|
| 1027 |
+
"one_line_description": "A results class for Zero Inflated Poisson",
|
| 1028 |
+
"extra_attr": ""}
|
| 1029 |
+
|
| 1030 |
+
@cache_readonly
|
| 1031 |
+
def _dispersion_factor(self):
|
| 1032 |
+
mu = self.predict(which='linear')
|
| 1033 |
+
w = 1 - self.predict() / np.exp(self.predict(which='linear'))
|
| 1034 |
+
return (1 + w * np.exp(mu))
|
| 1035 |
+
|
| 1036 |
+
def get_margeff(self, at='overall', method='dydx', atexog=None,
|
| 1037 |
+
dummy=False, count=False):
|
| 1038 |
+
"""Get marginal effects of the fitted model.
|
| 1039 |
+
|
| 1040 |
+
Not yet implemented for Zero Inflated Models
|
| 1041 |
+
"""
|
| 1042 |
+
raise NotImplementedError("not yet implemented for zero inflation")
|
| 1043 |
+
|
| 1044 |
+
|
| 1045 |
+
class L1ZeroInflatedPoissonResults(L1CountResults, ZeroInflatedPoissonResults):
|
| 1046 |
+
pass
|
| 1047 |
+
|
| 1048 |
+
|
| 1049 |
+
class ZeroInflatedPoissonResultsWrapper(lm.RegressionResultsWrapper):
|
| 1050 |
+
pass
|
| 1051 |
+
wrap.populate_wrapper(ZeroInflatedPoissonResultsWrapper,
|
| 1052 |
+
ZeroInflatedPoissonResults)
|
| 1053 |
+
|
| 1054 |
+
|
| 1055 |
+
class L1ZeroInflatedPoissonResultsWrapper(lm.RegressionResultsWrapper):
|
| 1056 |
+
pass
|
| 1057 |
+
wrap.populate_wrapper(L1ZeroInflatedPoissonResultsWrapper,
|
| 1058 |
+
L1ZeroInflatedPoissonResults)
|
| 1059 |
+
|
| 1060 |
+
|
| 1061 |
+
class ZeroInflatedGeneralizedPoissonResults(ZeroInflatedResults):
|
| 1062 |
+
__doc__ = _discrete_results_docs % {
|
| 1063 |
+
"one_line_description": "A results class for Zero Inflated Generalized Poisson",
|
| 1064 |
+
"extra_attr": ""}
|
| 1065 |
+
|
| 1066 |
+
@cache_readonly
|
| 1067 |
+
def _dispersion_factor(self):
|
| 1068 |
+
p = self.model.model_main.parameterization
|
| 1069 |
+
alpha = self.params[self.model.k_inflate:][-1]
|
| 1070 |
+
mu = np.exp(self.predict(which='linear'))
|
| 1071 |
+
w = 1 - self.predict() / mu
|
| 1072 |
+
return ((1 + alpha * mu**p)**2 + w * mu)
|
| 1073 |
+
|
| 1074 |
+
def get_margeff(self, at='overall', method='dydx', atexog=None,
|
| 1075 |
+
dummy=False, count=False):
|
| 1076 |
+
"""Get marginal effects of the fitted model.
|
| 1077 |
+
|
| 1078 |
+
Not yet implemented for Zero Inflated Models
|
| 1079 |
+
"""
|
| 1080 |
+
raise NotImplementedError("not yet implemented for zero inflation")
|
| 1081 |
+
|
| 1082 |
+
|
| 1083 |
+
class L1ZeroInflatedGeneralizedPoissonResults(L1CountResults,
|
| 1084 |
+
ZeroInflatedGeneralizedPoissonResults):
|
| 1085 |
+
pass
|
| 1086 |
+
|
| 1087 |
+
|
| 1088 |
+
class ZeroInflatedGeneralizedPoissonResultsWrapper(
|
| 1089 |
+
lm.RegressionResultsWrapper):
|
| 1090 |
+
pass
|
| 1091 |
+
wrap.populate_wrapper(ZeroInflatedGeneralizedPoissonResultsWrapper,
|
| 1092 |
+
ZeroInflatedGeneralizedPoissonResults)
|
| 1093 |
+
|
| 1094 |
+
|
| 1095 |
+
class L1ZeroInflatedGeneralizedPoissonResultsWrapper(
|
| 1096 |
+
lm.RegressionResultsWrapper):
|
| 1097 |
+
pass
|
| 1098 |
+
wrap.populate_wrapper(L1ZeroInflatedGeneralizedPoissonResultsWrapper,
|
| 1099 |
+
L1ZeroInflatedGeneralizedPoissonResults)
|
| 1100 |
+
|
| 1101 |
+
|
| 1102 |
+
class ZeroInflatedNegativeBinomialResults(ZeroInflatedResults):
|
| 1103 |
+
__doc__ = _discrete_results_docs % {
|
| 1104 |
+
"one_line_description": "A results class for Zero Inflated Generalized Negative Binomial",
|
| 1105 |
+
"extra_attr": ""}
|
| 1106 |
+
|
| 1107 |
+
@cache_readonly
|
| 1108 |
+
def _dispersion_factor(self):
|
| 1109 |
+
p = self.model.model_main.parameterization
|
| 1110 |
+
alpha = self.params[self.model.k_inflate:][-1]
|
| 1111 |
+
mu = np.exp(self.predict(which='linear'))
|
| 1112 |
+
w = 1 - self.predict() / mu
|
| 1113 |
+
return (1 + alpha * mu**(p-1) + w * mu)
|
| 1114 |
+
|
| 1115 |
+
def get_margeff(self, at='overall', method='dydx', atexog=None,
|
| 1116 |
+
dummy=False, count=False):
|
| 1117 |
+
"""Get marginal effects of the fitted model.
|
| 1118 |
+
|
| 1119 |
+
Not yet implemented for Zero Inflated Models
|
| 1120 |
+
"""
|
| 1121 |
+
raise NotImplementedError("not yet implemented for zero inflation")
|
| 1122 |
+
|
| 1123 |
+
|
| 1124 |
+
class L1ZeroInflatedNegativeBinomialResults(L1CountResults,
|
| 1125 |
+
ZeroInflatedNegativeBinomialResults):
|
| 1126 |
+
pass
|
| 1127 |
+
|
| 1128 |
+
|
| 1129 |
+
class ZeroInflatedNegativeBinomialResultsWrapper(
|
| 1130 |
+
lm.RegressionResultsWrapper):
|
| 1131 |
+
pass
|
| 1132 |
+
wrap.populate_wrapper(ZeroInflatedNegativeBinomialResultsWrapper,
|
| 1133 |
+
ZeroInflatedNegativeBinomialResults)
|
| 1134 |
+
|
| 1135 |
+
|
| 1136 |
+
class L1ZeroInflatedNegativeBinomialResultsWrapper(
|
| 1137 |
+
lm.RegressionResultsWrapper):
|
| 1138 |
+
pass
|
| 1139 |
+
wrap.populate_wrapper(L1ZeroInflatedNegativeBinomialResultsWrapper,
|
| 1140 |
+
L1ZeroInflatedNegativeBinomialResults)
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/diagnostic.py
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Created on Wed Nov 18 15:17:58 2020
|
| 3 |
+
|
| 4 |
+
Author: Josef Perktold
|
| 5 |
+
License: BSD-3
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import warnings
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
|
| 13 |
+
from statsmodels.tools.decorators import cache_readonly
|
| 14 |
+
|
| 15 |
+
from statsmodels.stats.diagnostic_gen import (
|
| 16 |
+
test_chisquare_binning
|
| 17 |
+
)
|
| 18 |
+
from statsmodels.discrete._diagnostics_count import (
|
| 19 |
+
test_poisson_dispersion,
|
| 20 |
+
# _test_poisson_dispersion_generic,
|
| 21 |
+
test_poisson_zeroinflation_jh,
|
| 22 |
+
test_poisson_zeroinflation_broek,
|
| 23 |
+
test_poisson_zeros,
|
| 24 |
+
test_chisquare_prob,
|
| 25 |
+
plot_probs
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class CountDiagnostic:
|
| 30 |
+
"""Diagnostic and specification tests and plots for Count model
|
| 31 |
+
|
| 32 |
+
status: experimental
|
| 33 |
+
|
| 34 |
+
Parameters
|
| 35 |
+
----------
|
| 36 |
+
results : Results instance of a count model.
|
| 37 |
+
y_max : int
|
| 38 |
+
Largest count to include when computing predicted probabilities for
|
| 39 |
+
counts. Default is the largest observed count.
|
| 40 |
+
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
def __init__(self, results, y_max=None):
|
| 44 |
+
self.results = results
|
| 45 |
+
self.y_max = y_max
|
| 46 |
+
|
| 47 |
+
@cache_readonly
|
| 48 |
+
def probs_predicted(self):
|
| 49 |
+
if self.y_max is not None:
|
| 50 |
+
kwds = {"y_values": np.arange(self.y_max + 1)}
|
| 51 |
+
else:
|
| 52 |
+
kwds = {}
|
| 53 |
+
return self.results.predict(which="prob", **kwds)
|
| 54 |
+
|
| 55 |
+
def test_chisquare_prob(self, bin_edges=None, method=None):
|
| 56 |
+
"""Moment test for binned probabilites using OPG.
|
| 57 |
+
|
| 58 |
+
Paramters
|
| 59 |
+
---------
|
| 60 |
+
binedges : array_like or None
|
| 61 |
+
This defines which counts are included in the test on frequencies
|
| 62 |
+
and how counts are combined in bins.
|
| 63 |
+
The default if bin_edges is None will change in future.
|
| 64 |
+
See Notes and Example sections below.
|
| 65 |
+
method : str
|
| 66 |
+
Currently only `method = "opg"` is available.
|
| 67 |
+
If method is None, the OPG will be used, but the default might
|
| 68 |
+
change in future versions.
|
| 69 |
+
See Notes section below.
|
| 70 |
+
|
| 71 |
+
Returns
|
| 72 |
+
-------
|
| 73 |
+
test result
|
| 74 |
+
|
| 75 |
+
Notes
|
| 76 |
+
-----
|
| 77 |
+
Warning: The current default can have many empty or nearly empty bins.
|
| 78 |
+
The default number of bins is given by max(endog).
|
| 79 |
+
Currently it is recommended to limit the number of bins explicitly,
|
| 80 |
+
see Examples below.
|
| 81 |
+
Binning will change in future and automatic binning will be added.
|
| 82 |
+
|
| 83 |
+
Currently only the outer product of gradient, OPG, method is
|
| 84 |
+
implemented. In many case, the OPG version of a specification test
|
| 85 |
+
overrejects in small samples.
|
| 86 |
+
Specialized tests that use observed or expected information matrix
|
| 87 |
+
often have better small sample properties.
|
| 88 |
+
The default method will change if better methods are added.
|
| 89 |
+
|
| 90 |
+
Examples
|
| 91 |
+
--------
|
| 92 |
+
The following call is a test for the probability of zeros
|
| 93 |
+
`test_chisquare_prob(bin_edges=np.arange(3))`
|
| 94 |
+
|
| 95 |
+
`test_chisquare_prob(bin_edges=np.arange(10))` tests the hypothesis
|
| 96 |
+
that the frequencies for counts up to 7 correspond to the estimated
|
| 97 |
+
Poisson distributions.
|
| 98 |
+
In this case, edges are 0, ..., 9 which defines 9 bins for
|
| 99 |
+
counts 0 to 8. The last bin is dropped, so the joint test hypothesis is
|
| 100 |
+
that the observed aggregated frequencies for counts 0 to 7 correspond
|
| 101 |
+
to the model prediction for those frequencies. Predicted probabilites
|
| 102 |
+
Prob(y_i = k | x) are aggregated over observations ``i``.
|
| 103 |
+
|
| 104 |
+
"""
|
| 105 |
+
kwds = {}
|
| 106 |
+
if bin_edges is not None:
|
| 107 |
+
# TODO: verify upper bound, we drop last bin (may be open, inf)
|
| 108 |
+
kwds["y_values"] = np.arange(bin_edges[-2] + 1)
|
| 109 |
+
probs = self.results.predict(which="prob", **kwds)
|
| 110 |
+
res = test_chisquare_prob(self.results, probs, bin_edges=bin_edges,
|
| 111 |
+
method=method)
|
| 112 |
+
return res
|
| 113 |
+
|
| 114 |
+
def plot_probs(self, label='predicted', upp_xlim=None,
|
| 115 |
+
fig=None):
|
| 116 |
+
"""Plot observed versus predicted frequencies for entire sample.
|
| 117 |
+
"""
|
| 118 |
+
probs_predicted = self.probs_predicted.sum(0)
|
| 119 |
+
k_probs = len(probs_predicted)
|
| 120 |
+
freq = np.bincount(self.results.model.endog.astype(int),
|
| 121 |
+
minlength=k_probs)[:k_probs]
|
| 122 |
+
fig = plot_probs(freq, probs_predicted,
|
| 123 |
+
label=label, upp_xlim=upp_xlim,
|
| 124 |
+
fig=fig)
|
| 125 |
+
return fig
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
class PoissonDiagnostic(CountDiagnostic):
|
| 129 |
+
"""Diagnostic and specification tests and plots for Poisson model
|
| 130 |
+
|
| 131 |
+
status: experimental
|
| 132 |
+
|
| 133 |
+
Parameters
|
| 134 |
+
----------
|
| 135 |
+
results : PoissonResults instance
|
| 136 |
+
|
| 137 |
+
"""
|
| 138 |
+
|
| 139 |
+
def _init__(self, results):
|
| 140 |
+
self.results = results
|
| 141 |
+
|
| 142 |
+
def test_dispersion(self):
|
| 143 |
+
"""Test for excess (over or under) dispersion in Poisson.
|
| 144 |
+
|
| 145 |
+
Returns
|
| 146 |
+
-------
|
| 147 |
+
dispersion results
|
| 148 |
+
"""
|
| 149 |
+
res = test_poisson_dispersion(self.results)
|
| 150 |
+
return res
|
| 151 |
+
|
| 152 |
+
def test_poisson_zeroinflation(self, method="prob", exog_infl=None):
|
| 153 |
+
"""Test for excess zeros, zero inflation or deflation.
|
| 154 |
+
|
| 155 |
+
Parameters
|
| 156 |
+
----------
|
| 157 |
+
method : str
|
| 158 |
+
Three methods ara available for the test:
|
| 159 |
+
|
| 160 |
+
- "prob" : moment test for the probability of zeros
|
| 161 |
+
- "broek" : score test against zero inflation with or without
|
| 162 |
+
explanatory variables for inflation
|
| 163 |
+
|
| 164 |
+
exog_infl : array_like or None
|
| 165 |
+
Optional explanatory variables under the alternative of zero
|
| 166 |
+
inflation, or deflation. Only used if method is "broek".
|
| 167 |
+
|
| 168 |
+
Returns
|
| 169 |
+
-------
|
| 170 |
+
results
|
| 171 |
+
|
| 172 |
+
Notes
|
| 173 |
+
-----
|
| 174 |
+
If method = "prob", then the moment test of He et al 1_ is used based
|
| 175 |
+
on the explicit formula in Tang and Tang 2_.
|
| 176 |
+
|
| 177 |
+
If method = "broek" and exog_infl is None, then the test by Van den
|
| 178 |
+
Broek 3_ is used. This is a score test against and alternative of
|
| 179 |
+
constant zero inflation or deflation.
|
| 180 |
+
|
| 181 |
+
If method = "broek" and exog_infl is provided, then the extension of
|
| 182 |
+
the broek test to varying zero inflation or deflation by Jansakul and
|
| 183 |
+
Hinde is used.
|
| 184 |
+
|
| 185 |
+
Warning: The Broek and the Jansakul and Hinde tests are not numerically
|
| 186 |
+
stable when the probability of zeros in Poisson is small, i.e. if the
|
| 187 |
+
conditional means of the estimated Poisson distribution are large.
|
| 188 |
+
In these cases, p-values will not be accurate.
|
| 189 |
+
"""
|
| 190 |
+
if method == "prob":
|
| 191 |
+
if exog_infl is not None:
|
| 192 |
+
warnings.warn('exog_infl is only used if method = "broek"')
|
| 193 |
+
res = test_poisson_zeros(self.results)
|
| 194 |
+
elif method == "broek":
|
| 195 |
+
if exog_infl is None:
|
| 196 |
+
res = test_poisson_zeroinflation_broek(self.results)
|
| 197 |
+
else:
|
| 198 |
+
exog_infl = np.asarray(exog_infl)
|
| 199 |
+
if exog_infl.ndim == 1:
|
| 200 |
+
exog_infl = exog_infl[:, None]
|
| 201 |
+
res = test_poisson_zeroinflation_jh(self.results,
|
| 202 |
+
exog_infl=exog_infl)
|
| 203 |
+
|
| 204 |
+
return res
|
| 205 |
+
|
| 206 |
+
def _chisquare_binned(self, sort_var=None, bins=10, k_max=None, df=None,
|
| 207 |
+
sort_method="quicksort", frac_upp=0.1,
|
| 208 |
+
alpha_nc=0.05):
|
| 209 |
+
"""Hosmer-Lemeshow style test for count data.
|
| 210 |
+
|
| 211 |
+
Note, this does not take into account that parameters are estimated.
|
| 212 |
+
The distribution of the test statistic is only an approximation.
|
| 213 |
+
|
| 214 |
+
This corresponds to the Hosmer-Lemeshow type test for an ordinal
|
| 215 |
+
response variable. The outcome space y = k is partitioned into bins
|
| 216 |
+
and treated as ordinal variable.
|
| 217 |
+
The observations are split into approximately equal sized groups
|
| 218 |
+
of observations sorted according the ``sort_var``.
|
| 219 |
+
|
| 220 |
+
"""
|
| 221 |
+
|
| 222 |
+
if sort_var is None:
|
| 223 |
+
sort_var = self.results.predict(which="lin")
|
| 224 |
+
|
| 225 |
+
endog = self.results.model.endog
|
| 226 |
+
# not sure yet how this is supposed to work
|
| 227 |
+
# max_count = endog.max * 2
|
| 228 |
+
# no option for max count in predict
|
| 229 |
+
# counts = (endog == np.arange(max_count)).astype(int)
|
| 230 |
+
expected = self.results.predict(which="prob")
|
| 231 |
+
counts = (endog[:, None] == np.arange(expected.shape[1])).astype(int)
|
| 232 |
+
|
| 233 |
+
# truncate upper tail
|
| 234 |
+
if k_max is None:
|
| 235 |
+
nobs = len(endog)
|
| 236 |
+
icumcounts_sum = nobs - counts.sum(0).cumsum(0)
|
| 237 |
+
k_max = np.argmax(icumcounts_sum < nobs * frac_upp) - 1
|
| 238 |
+
expected = expected[:, :k_max]
|
| 239 |
+
counts = counts[:, :k_max]
|
| 240 |
+
# we should correct for or include truncated upper bin
|
| 241 |
+
# inplace modification, we cannot reuse expected and counts anymore
|
| 242 |
+
expected[:, -1] += 1 - expected.sum(1)
|
| 243 |
+
counts[:, -1] += 1 - counts.sum(1)
|
| 244 |
+
|
| 245 |
+
# TODO: what's the correct df, same as for multinomial/ordered ?
|
| 246 |
+
res = test_chisquare_binning(counts, expected, sort_var=sort_var,
|
| 247 |
+
bins=bins, df=df, ordered=True,
|
| 248 |
+
sort_method=sort_method,
|
| 249 |
+
alpha_nc=alpha_nc)
|
| 250 |
+
return res
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/discrete_margins.py
ADDED
|
@@ -0,0 +1,732 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#Splitting out maringal effects to see if they can be generalized
|
| 2 |
+
|
| 3 |
+
from statsmodels.compat.python import lzip
|
| 4 |
+
import numpy as np
|
| 5 |
+
from scipy.stats import norm
|
| 6 |
+
from statsmodels.tools.decorators import cache_readonly
|
| 7 |
+
|
| 8 |
+
#### margeff helper functions ####
|
| 9 |
+
#NOTE: todo marginal effects for group 2
|
| 10 |
+
# group 2 oprobit, ologit, gologit, mlogit, biprobit
|
| 11 |
+
|
| 12 |
+
def _check_margeff_args(at, method):
|
| 13 |
+
"""
|
| 14 |
+
Checks valid options for margeff
|
| 15 |
+
"""
|
| 16 |
+
if at not in ['overall','mean','median','zero','all']:
|
| 17 |
+
raise ValueError("%s not a valid option for `at`." % at)
|
| 18 |
+
if method not in ['dydx','eyex','dyex','eydx']:
|
| 19 |
+
raise ValueError("method is not understood. Got %s" % method)
|
| 20 |
+
|
| 21 |
+
def _check_discrete_args(at, method):
|
| 22 |
+
"""
|
| 23 |
+
Checks the arguments for margeff if the exogenous variables are discrete.
|
| 24 |
+
"""
|
| 25 |
+
if method in ['dyex','eyex']:
|
| 26 |
+
raise ValueError("%s not allowed for discrete variables" % method)
|
| 27 |
+
if at in ['median', 'zero']:
|
| 28 |
+
raise ValueError("%s not allowed for discrete variables" % at)
|
| 29 |
+
|
| 30 |
+
def _get_const_index(exog):
|
| 31 |
+
"""
|
| 32 |
+
Returns a boolean array of non-constant column indices in exog and
|
| 33 |
+
an scalar array of where the constant is or None
|
| 34 |
+
"""
|
| 35 |
+
effects_idx = exog.var(0) != 0
|
| 36 |
+
if np.any(~effects_idx):
|
| 37 |
+
const_idx = np.where(~effects_idx)[0]
|
| 38 |
+
else:
|
| 39 |
+
const_idx = None
|
| 40 |
+
return effects_idx, const_idx
|
| 41 |
+
|
| 42 |
+
def _isdummy(X):
|
| 43 |
+
"""
|
| 44 |
+
Given an array X, returns the column indices for the dummy variables.
|
| 45 |
+
|
| 46 |
+
Parameters
|
| 47 |
+
----------
|
| 48 |
+
X : array_like
|
| 49 |
+
A 1d or 2d array of numbers
|
| 50 |
+
|
| 51 |
+
Examples
|
| 52 |
+
--------
|
| 53 |
+
>>> X = np.random.randint(0, 2, size=(15,5)).astype(float)
|
| 54 |
+
>>> X[:,1:3] = np.random.randn(15,2)
|
| 55 |
+
>>> ind = _isdummy(X)
|
| 56 |
+
>>> ind
|
| 57 |
+
array([0, 3, 4])
|
| 58 |
+
"""
|
| 59 |
+
X = np.asarray(X)
|
| 60 |
+
if X.ndim > 1:
|
| 61 |
+
ind = np.zeros(X.shape[1]).astype(bool)
|
| 62 |
+
max = (np.max(X, axis=0) == 1)
|
| 63 |
+
min = (np.min(X, axis=0) == 0)
|
| 64 |
+
remainder = np.all(X % 1. == 0, axis=0)
|
| 65 |
+
ind = min & max & remainder
|
| 66 |
+
if X.ndim == 1:
|
| 67 |
+
ind = np.asarray([ind])
|
| 68 |
+
return np.where(ind)[0]
|
| 69 |
+
|
| 70 |
+
def _get_dummy_index(X, const_idx):
|
| 71 |
+
dummy_ind = _isdummy(X)
|
| 72 |
+
dummy = True
|
| 73 |
+
|
| 74 |
+
if dummy_ind.size == 0: # do not waste your time
|
| 75 |
+
dummy = False
|
| 76 |
+
dummy_ind = None # this gets passed to stand err func
|
| 77 |
+
return dummy_ind, dummy
|
| 78 |
+
|
| 79 |
+
def _iscount(X):
|
| 80 |
+
"""
|
| 81 |
+
Given an array X, returns the column indices for count variables.
|
| 82 |
+
|
| 83 |
+
Parameters
|
| 84 |
+
----------
|
| 85 |
+
X : array_like
|
| 86 |
+
A 1d or 2d array of numbers
|
| 87 |
+
|
| 88 |
+
Examples
|
| 89 |
+
--------
|
| 90 |
+
>>> X = np.random.randint(0, 10, size=(15,5)).astype(float)
|
| 91 |
+
>>> X[:,1:3] = np.random.randn(15,2)
|
| 92 |
+
>>> ind = _iscount(X)
|
| 93 |
+
>>> ind
|
| 94 |
+
array([0, 3, 4])
|
| 95 |
+
"""
|
| 96 |
+
X = np.asarray(X)
|
| 97 |
+
remainder = np.logical_and(np.logical_and(np.all(X % 1. == 0, axis = 0),
|
| 98 |
+
X.var(0) != 0), np.all(X >= 0, axis=0))
|
| 99 |
+
dummy = _isdummy(X)
|
| 100 |
+
remainder = np.where(remainder)[0].tolist()
|
| 101 |
+
for idx in dummy:
|
| 102 |
+
remainder.remove(idx)
|
| 103 |
+
return np.array(remainder)
|
| 104 |
+
|
| 105 |
+
def _get_count_index(X, const_idx):
|
| 106 |
+
count_ind = _iscount(X)
|
| 107 |
+
count = True
|
| 108 |
+
|
| 109 |
+
if count_ind.size == 0: # do not waste your time
|
| 110 |
+
count = False
|
| 111 |
+
count_ind = None # for stand err func
|
| 112 |
+
return count_ind, count
|
| 113 |
+
|
| 114 |
+
def _get_margeff_exog(exog, at, atexog, ind):
|
| 115 |
+
if atexog is not None: # user supplied
|
| 116 |
+
if isinstance(atexog, dict):
|
| 117 |
+
# assumes values are singular or of len(exog)
|
| 118 |
+
for key in atexog:
|
| 119 |
+
exog[:,key] = atexog[key]
|
| 120 |
+
elif isinstance(atexog, np.ndarray): #TODO: handle DataFrames
|
| 121 |
+
if atexog.ndim == 1:
|
| 122 |
+
k_vars = len(atexog)
|
| 123 |
+
else:
|
| 124 |
+
k_vars = atexog.shape[1]
|
| 125 |
+
try:
|
| 126 |
+
assert k_vars == exog.shape[1]
|
| 127 |
+
except:
|
| 128 |
+
raise ValueError("atexog does not have the same number "
|
| 129 |
+
"of variables as exog")
|
| 130 |
+
exog = atexog
|
| 131 |
+
|
| 132 |
+
#NOTE: we should fill in atexog after we process at
|
| 133 |
+
if at == 'mean':
|
| 134 |
+
exog = np.atleast_2d(exog.mean(0))
|
| 135 |
+
elif at == 'median':
|
| 136 |
+
exog = np.atleast_2d(np.median(exog, axis=0))
|
| 137 |
+
elif at == 'zero':
|
| 138 |
+
exog = np.zeros((1,exog.shape[1]))
|
| 139 |
+
exog[0,~ind] = 1
|
| 140 |
+
return exog
|
| 141 |
+
|
| 142 |
+
def _get_count_effects(effects, exog, count_ind, method, model, params):
|
| 143 |
+
"""
|
| 144 |
+
If there's a count variable, the predicted difference is taken by
|
| 145 |
+
subtracting one and adding one to exog then averaging the difference
|
| 146 |
+
"""
|
| 147 |
+
# this is the index for the effect and the index for count col in exog
|
| 148 |
+
for i in count_ind:
|
| 149 |
+
exog0 = exog.copy()
|
| 150 |
+
exog0[:, i] -= 1
|
| 151 |
+
effect0 = model.predict(params, exog0)
|
| 152 |
+
exog0[:, i] += 2
|
| 153 |
+
effect1 = model.predict(params, exog0)
|
| 154 |
+
#NOTE: done by analogy with dummy effects but untested bc
|
| 155 |
+
# stata does not handle both count and eydx anywhere
|
| 156 |
+
if 'ey' in method:
|
| 157 |
+
effect0 = np.log(effect0)
|
| 158 |
+
effect1 = np.log(effect1)
|
| 159 |
+
effects[:, i] = ((effect1 - effect0)/2)
|
| 160 |
+
return effects
|
| 161 |
+
|
| 162 |
+
def _get_dummy_effects(effects, exog, dummy_ind, method, model, params):
|
| 163 |
+
"""
|
| 164 |
+
If there's a dummy variable, the predicted difference is taken at
|
| 165 |
+
0 and 1
|
| 166 |
+
"""
|
| 167 |
+
# this is the index for the effect and the index for dummy col in exog
|
| 168 |
+
for i in dummy_ind:
|
| 169 |
+
exog0 = exog.copy() # only copy once, can we avoid a copy?
|
| 170 |
+
exog0[:,i] = 0
|
| 171 |
+
effect0 = model.predict(params, exog0)
|
| 172 |
+
#fittedvalues0 = np.dot(exog0,params)
|
| 173 |
+
exog0[:,i] = 1
|
| 174 |
+
effect1 = model.predict(params, exog0)
|
| 175 |
+
if 'ey' in method:
|
| 176 |
+
effect0 = np.log(effect0)
|
| 177 |
+
effect1 = np.log(effect1)
|
| 178 |
+
effects[:, i] = (effect1 - effect0)
|
| 179 |
+
return effects
|
| 180 |
+
|
| 181 |
+
def _effects_at(effects, at):
|
| 182 |
+
if at == 'all':
|
| 183 |
+
effects = effects
|
| 184 |
+
elif at == 'overall':
|
| 185 |
+
effects = effects.mean(0)
|
| 186 |
+
else:
|
| 187 |
+
effects = effects[0,:]
|
| 188 |
+
return effects
|
| 189 |
+
|
| 190 |
+
def _margeff_cov_params_dummy(model, cov_margins, params, exog, dummy_ind,
|
| 191 |
+
method, J):
|
| 192 |
+
r"""
|
| 193 |
+
Returns the Jacobian for discrete regressors for use in margeff_cov_params.
|
| 194 |
+
|
| 195 |
+
For discrete regressors the marginal effect is
|
| 196 |
+
|
| 197 |
+
\Delta F = F(XB) | d = 1 - F(XB) | d = 0
|
| 198 |
+
|
| 199 |
+
The row of the Jacobian for this variable is given by
|
| 200 |
+
|
| 201 |
+
f(XB)*X | d = 1 - f(XB)*X | d = 0
|
| 202 |
+
|
| 203 |
+
Where F is the default prediction of the model.
|
| 204 |
+
"""
|
| 205 |
+
for i in dummy_ind:
|
| 206 |
+
exog0 = exog.copy()
|
| 207 |
+
exog1 = exog.copy()
|
| 208 |
+
exog0[:,i] = 0
|
| 209 |
+
exog1[:,i] = 1
|
| 210 |
+
dfdb0 = model._derivative_predict(params, exog0, method)
|
| 211 |
+
dfdb1 = model._derivative_predict(params, exog1, method)
|
| 212 |
+
dfdb = (dfdb1 - dfdb0)
|
| 213 |
+
if dfdb.ndim >= 2: # for overall
|
| 214 |
+
dfdb = dfdb.mean(0)
|
| 215 |
+
if J > 1:
|
| 216 |
+
K = dfdb.shape[1] // (J-1)
|
| 217 |
+
cov_margins[i::K, :] = dfdb
|
| 218 |
+
else:
|
| 219 |
+
# dfdb could be too short if there are extra params, k_extra > 0
|
| 220 |
+
cov_margins[i, :len(dfdb)] = dfdb # how each F changes with change in B
|
| 221 |
+
return cov_margins
|
| 222 |
+
|
| 223 |
+
def _margeff_cov_params_count(model, cov_margins, params, exog, count_ind,
|
| 224 |
+
method, J):
|
| 225 |
+
r"""
|
| 226 |
+
Returns the Jacobian for discrete regressors for use in margeff_cov_params.
|
| 227 |
+
|
| 228 |
+
For discrete regressors the marginal effect is
|
| 229 |
+
|
| 230 |
+
\Delta F = F(XB) | d += 1 - F(XB) | d -= 1
|
| 231 |
+
|
| 232 |
+
The row of the Jacobian for this variable is given by
|
| 233 |
+
|
| 234 |
+
(f(XB)*X | d += 1 - f(XB)*X | d -= 1) / 2
|
| 235 |
+
|
| 236 |
+
where F is the default prediction for the model.
|
| 237 |
+
"""
|
| 238 |
+
for i in count_ind:
|
| 239 |
+
exog0 = exog.copy()
|
| 240 |
+
exog0[:,i] -= 1
|
| 241 |
+
dfdb0 = model._derivative_predict(params, exog0, method)
|
| 242 |
+
exog0[:,i] += 2
|
| 243 |
+
dfdb1 = model._derivative_predict(params, exog0, method)
|
| 244 |
+
dfdb = (dfdb1 - dfdb0)
|
| 245 |
+
if dfdb.ndim >= 2: # for overall
|
| 246 |
+
dfdb = dfdb.mean(0) / 2
|
| 247 |
+
if J > 1:
|
| 248 |
+
K = dfdb.shape[1] / (J-1)
|
| 249 |
+
cov_margins[i::K, :] = dfdb
|
| 250 |
+
else:
|
| 251 |
+
# dfdb could be too short if there are extra params, k_extra > 0
|
| 252 |
+
cov_margins[i, :len(dfdb)] = dfdb # how each F changes with change in B
|
| 253 |
+
return cov_margins
|
| 254 |
+
|
| 255 |
+
def margeff_cov_params(model, params, exog, cov_params, at, derivative,
|
| 256 |
+
dummy_ind, count_ind, method, J):
|
| 257 |
+
"""
|
| 258 |
+
Computes the variance-covariance of marginal effects by the delta method.
|
| 259 |
+
|
| 260 |
+
Parameters
|
| 261 |
+
----------
|
| 262 |
+
model : model instance
|
| 263 |
+
The model that returned the fitted results. Its pdf method is used
|
| 264 |
+
for computing the Jacobian of discrete variables in dummy_ind and
|
| 265 |
+
count_ind
|
| 266 |
+
params : array_like
|
| 267 |
+
estimated model parameters
|
| 268 |
+
exog : array_like
|
| 269 |
+
exogenous variables at which to calculate the derivative
|
| 270 |
+
cov_params : array_like
|
| 271 |
+
The variance-covariance of the parameters
|
| 272 |
+
at : str
|
| 273 |
+
Options are:
|
| 274 |
+
|
| 275 |
+
- 'overall', The average of the marginal effects at each
|
| 276 |
+
observation.
|
| 277 |
+
- 'mean', The marginal effects at the mean of each regressor.
|
| 278 |
+
- 'median', The marginal effects at the median of each regressor.
|
| 279 |
+
- 'zero', The marginal effects at zero for each regressor.
|
| 280 |
+
- 'all', The marginal effects at each observation.
|
| 281 |
+
|
| 282 |
+
Only overall has any effect here.you
|
| 283 |
+
|
| 284 |
+
derivative : function or array_like
|
| 285 |
+
If a function, it returns the marginal effects of the model with
|
| 286 |
+
respect to the exogenous variables evaluated at exog. Expected to be
|
| 287 |
+
called derivative(params, exog). This will be numerically
|
| 288 |
+
differentiated. Otherwise, it can be the Jacobian of the marginal
|
| 289 |
+
effects with respect to the parameters.
|
| 290 |
+
dummy_ind : array_like
|
| 291 |
+
Indices of the columns of exog that contain dummy variables
|
| 292 |
+
count_ind : array_like
|
| 293 |
+
Indices of the columns of exog that contain count variables
|
| 294 |
+
|
| 295 |
+
Notes
|
| 296 |
+
-----
|
| 297 |
+
For continuous regressors, the variance-covariance is given by
|
| 298 |
+
|
| 299 |
+
Asy. Var[MargEff] = [d margeff / d params] V [d margeff / d params]'
|
| 300 |
+
|
| 301 |
+
where V is the parameter variance-covariance.
|
| 302 |
+
|
| 303 |
+
The outer Jacobians are computed via numerical differentiation if
|
| 304 |
+
derivative is a function.
|
| 305 |
+
"""
|
| 306 |
+
if callable(derivative):
|
| 307 |
+
from statsmodels.tools.numdiff import approx_fprime_cs
|
| 308 |
+
params = params.ravel('F') # for Multinomial
|
| 309 |
+
try:
|
| 310 |
+
jacobian_mat = approx_fprime_cs(params, derivative,
|
| 311 |
+
args=(exog,method))
|
| 312 |
+
except TypeError: # norm.cdf does not take complex values
|
| 313 |
+
from statsmodels.tools.numdiff import approx_fprime
|
| 314 |
+
jacobian_mat = approx_fprime(params, derivative,
|
| 315 |
+
args=(exog,method))
|
| 316 |
+
if at == 'overall':
|
| 317 |
+
jacobian_mat = np.mean(jacobian_mat, axis=1)
|
| 318 |
+
else:
|
| 319 |
+
jacobian_mat = jacobian_mat.squeeze() # exog was 2d row vector
|
| 320 |
+
if dummy_ind is not None:
|
| 321 |
+
jacobian_mat = _margeff_cov_params_dummy(model, jacobian_mat,
|
| 322 |
+
params, exog, dummy_ind, method, J)
|
| 323 |
+
if count_ind is not None:
|
| 324 |
+
jacobian_mat = _margeff_cov_params_count(model, jacobian_mat,
|
| 325 |
+
params, exog, count_ind, method, J)
|
| 326 |
+
else:
|
| 327 |
+
jacobian_mat = derivative
|
| 328 |
+
|
| 329 |
+
#NOTE: this will not go through for at == 'all'
|
| 330 |
+
return np.dot(np.dot(jacobian_mat, cov_params), jacobian_mat.T)
|
| 331 |
+
|
| 332 |
+
def margeff_cov_with_se(model, params, exog, cov_params, at, derivative,
|
| 333 |
+
dummy_ind, count_ind, method, J):
|
| 334 |
+
"""
|
| 335 |
+
See margeff_cov_params.
|
| 336 |
+
|
| 337 |
+
Same function but returns both the covariance of the marginal effects
|
| 338 |
+
and their standard errors.
|
| 339 |
+
"""
|
| 340 |
+
cov_me = margeff_cov_params(model, params, exog, cov_params, at,
|
| 341 |
+
derivative, dummy_ind,
|
| 342 |
+
count_ind, method, J)
|
| 343 |
+
return cov_me, np.sqrt(np.diag(cov_me))
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
def margeff():
|
| 347 |
+
raise NotImplementedError
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
def _check_at_is_all(method):
|
| 352 |
+
if method['at'] == 'all':
|
| 353 |
+
raise ValueError("Only margeff are available when `at` is "
|
| 354 |
+
"'all'. Please input specific points if you would "
|
| 355 |
+
"like to do inference.")
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
_transform_names = dict(dydx='dy/dx',
|
| 359 |
+
eyex='d(lny)/d(lnx)',
|
| 360 |
+
dyex='dy/d(lnx)',
|
| 361 |
+
eydx='d(lny)/dx')
|
| 362 |
+
|
| 363 |
+
class Margins:
|
| 364 |
+
"""
|
| 365 |
+
Mostly a do nothing class. Lays out the methods expected of a sub-class.
|
| 366 |
+
|
| 367 |
+
This is just a sketch of what we may want out of a general margins class.
|
| 368 |
+
I (SS) need to look at details of other models.
|
| 369 |
+
"""
|
| 370 |
+
def __init__(self, results, get_margeff, derivative, dist=None,
|
| 371 |
+
margeff_args=()):
|
| 372 |
+
self._cache = {}
|
| 373 |
+
self.results = results
|
| 374 |
+
self.dist = dist
|
| 375 |
+
self.get_margeff(margeff_args)
|
| 376 |
+
|
| 377 |
+
def _reset(self):
|
| 378 |
+
self._cache = {}
|
| 379 |
+
|
| 380 |
+
def get_margeff(self, *args, **kwargs):
|
| 381 |
+
self._reset()
|
| 382 |
+
self.margeff = self.get_margeff(*args)
|
| 383 |
+
|
| 384 |
+
@cache_readonly
|
| 385 |
+
def tvalues(self):
|
| 386 |
+
raise NotImplementedError
|
| 387 |
+
|
| 388 |
+
@cache_readonly
|
| 389 |
+
def cov_margins(self):
|
| 390 |
+
raise NotImplementedError
|
| 391 |
+
|
| 392 |
+
@cache_readonly
|
| 393 |
+
def margins_se(self):
|
| 394 |
+
raise NotImplementedError
|
| 395 |
+
|
| 396 |
+
def summary_frame(self):
|
| 397 |
+
raise NotImplementedError
|
| 398 |
+
|
| 399 |
+
@cache_readonly
|
| 400 |
+
def pvalues(self):
|
| 401 |
+
raise NotImplementedError
|
| 402 |
+
|
| 403 |
+
def conf_int(self, alpha=.05):
|
| 404 |
+
raise NotImplementedError
|
| 405 |
+
|
| 406 |
+
def summary(self, alpha=.05):
|
| 407 |
+
raise NotImplementedError
|
| 408 |
+
|
| 409 |
+
#class DiscreteMargins(Margins):
|
| 410 |
+
class DiscreteMargins:
|
| 411 |
+
"""Get marginal effects of a Discrete Choice model.
|
| 412 |
+
|
| 413 |
+
Parameters
|
| 414 |
+
----------
|
| 415 |
+
results : DiscreteResults instance
|
| 416 |
+
The results instance of a fitted discrete choice model
|
| 417 |
+
args : tuple
|
| 418 |
+
Args are passed to `get_margeff`. This is the same as
|
| 419 |
+
results.get_margeff. See there for more information.
|
| 420 |
+
kwargs : dict
|
| 421 |
+
Keyword args are passed to `get_margeff`. This is the same as
|
| 422 |
+
results.get_margeff. See there for more information.
|
| 423 |
+
"""
|
| 424 |
+
def __init__(self, results, args, kwargs={}):
|
| 425 |
+
self._cache = {}
|
| 426 |
+
self.results = results
|
| 427 |
+
self.get_margeff(*args, **kwargs)
|
| 428 |
+
|
| 429 |
+
def _reset(self):
|
| 430 |
+
self._cache = {}
|
| 431 |
+
|
| 432 |
+
@cache_readonly
|
| 433 |
+
def tvalues(self):
|
| 434 |
+
_check_at_is_all(self.margeff_options)
|
| 435 |
+
return self.margeff / self.margeff_se
|
| 436 |
+
|
| 437 |
+
def summary_frame(self, alpha=.05):
|
| 438 |
+
"""
|
| 439 |
+
Returns a DataFrame summarizing the marginal effects.
|
| 440 |
+
|
| 441 |
+
Parameters
|
| 442 |
+
----------
|
| 443 |
+
alpha : float
|
| 444 |
+
Number between 0 and 1. The confidence intervals have the
|
| 445 |
+
probability 1-alpha.
|
| 446 |
+
|
| 447 |
+
Returns
|
| 448 |
+
-------
|
| 449 |
+
frame : DataFrames
|
| 450 |
+
A DataFrame summarizing the marginal effects.
|
| 451 |
+
|
| 452 |
+
Notes
|
| 453 |
+
-----
|
| 454 |
+
The dataframe is created on each call and not cached, as are the
|
| 455 |
+
tables build in `summary()`
|
| 456 |
+
"""
|
| 457 |
+
_check_at_is_all(self.margeff_options)
|
| 458 |
+
results = self.results
|
| 459 |
+
model = self.results.model
|
| 460 |
+
from pandas import DataFrame, MultiIndex
|
| 461 |
+
names = [_transform_names[self.margeff_options['method']],
|
| 462 |
+
'Std. Err.', 'z', 'Pr(>|z|)',
|
| 463 |
+
'Conf. Int. Low', 'Cont. Int. Hi.']
|
| 464 |
+
ind = self.results.model.exog.var(0) != 0 # True if not a constant
|
| 465 |
+
exog_names = self.results.model.exog_names
|
| 466 |
+
k_extra = getattr(model, 'k_extra', 0)
|
| 467 |
+
if k_extra > 0:
|
| 468 |
+
exog_names = exog_names[:-k_extra]
|
| 469 |
+
var_names = [name for i,name in enumerate(exog_names) if ind[i]]
|
| 470 |
+
|
| 471 |
+
if self.margeff.ndim == 2:
|
| 472 |
+
# MNLogit case
|
| 473 |
+
ci = self.conf_int(alpha)
|
| 474 |
+
table = np.column_stack([i.ravel("F") for i in
|
| 475 |
+
[self.margeff, self.margeff_se, self.tvalues,
|
| 476 |
+
self.pvalues, ci[:, 0, :], ci[:, 1, :]]])
|
| 477 |
+
|
| 478 |
+
_, yname_list = results._get_endog_name(model.endog_names,
|
| 479 |
+
None, all=True)
|
| 480 |
+
ynames = np.repeat(yname_list, len(var_names))
|
| 481 |
+
xnames = np.tile(var_names, len(yname_list))
|
| 482 |
+
index = MultiIndex.from_tuples(list(zip(ynames, xnames)),
|
| 483 |
+
names=['endog', 'exog'])
|
| 484 |
+
else:
|
| 485 |
+
table = np.column_stack((self.margeff, self.margeff_se, self.tvalues,
|
| 486 |
+
self.pvalues, self.conf_int(alpha)))
|
| 487 |
+
index=var_names
|
| 488 |
+
|
| 489 |
+
return DataFrame(table, columns=names, index=index)
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
@cache_readonly
|
| 493 |
+
def pvalues(self):
|
| 494 |
+
_check_at_is_all(self.margeff_options)
|
| 495 |
+
return norm.sf(np.abs(self.tvalues)) * 2
|
| 496 |
+
|
| 497 |
+
def conf_int(self, alpha=.05):
|
| 498 |
+
"""
|
| 499 |
+
Returns the confidence intervals of the marginal effects
|
| 500 |
+
|
| 501 |
+
Parameters
|
| 502 |
+
----------
|
| 503 |
+
alpha : float
|
| 504 |
+
Number between 0 and 1. The confidence intervals have the
|
| 505 |
+
probability 1-alpha.
|
| 506 |
+
|
| 507 |
+
Returns
|
| 508 |
+
-------
|
| 509 |
+
conf_int : ndarray
|
| 510 |
+
An array with lower, upper confidence intervals for the marginal
|
| 511 |
+
effects.
|
| 512 |
+
"""
|
| 513 |
+
_check_at_is_all(self.margeff_options)
|
| 514 |
+
me_se = self.margeff_se
|
| 515 |
+
q = norm.ppf(1 - alpha / 2)
|
| 516 |
+
lower = self.margeff - q * me_se
|
| 517 |
+
upper = self.margeff + q * me_se
|
| 518 |
+
return np.asarray(lzip(lower, upper))
|
| 519 |
+
|
| 520 |
+
def summary(self, alpha=.05):
|
| 521 |
+
"""
|
| 522 |
+
Returns a summary table for marginal effects
|
| 523 |
+
|
| 524 |
+
Parameters
|
| 525 |
+
----------
|
| 526 |
+
alpha : float
|
| 527 |
+
Number between 0 and 1. The confidence intervals have the
|
| 528 |
+
probability 1-alpha.
|
| 529 |
+
|
| 530 |
+
Returns
|
| 531 |
+
-------
|
| 532 |
+
Summary : SummaryTable
|
| 533 |
+
A SummaryTable instance
|
| 534 |
+
"""
|
| 535 |
+
_check_at_is_all(self.margeff_options)
|
| 536 |
+
results = self.results
|
| 537 |
+
model = results.model
|
| 538 |
+
title = model.__class__.__name__ + " Marginal Effects"
|
| 539 |
+
method = self.margeff_options['method']
|
| 540 |
+
top_left = [('Dep. Variable:', [model.endog_names]),
|
| 541 |
+
('Method:', [method]),
|
| 542 |
+
('At:', [self.margeff_options['at']]),]
|
| 543 |
+
|
| 544 |
+
from statsmodels.iolib.summary import (Summary, summary_params,
|
| 545 |
+
table_extend)
|
| 546 |
+
exog_names = model.exog_names[:] # copy
|
| 547 |
+
smry = Summary()
|
| 548 |
+
|
| 549 |
+
# TODO: sigh, we really need to hold on to this in _data...
|
| 550 |
+
_, const_idx = _get_const_index(model.exog)
|
| 551 |
+
if const_idx is not None:
|
| 552 |
+
exog_names.pop(const_idx[0])
|
| 553 |
+
if getattr(model, 'k_extra', 0) > 0:
|
| 554 |
+
exog_names = exog_names[:-model.k_extra]
|
| 555 |
+
|
| 556 |
+
J = int(getattr(model, "J", 1))
|
| 557 |
+
if J > 1:
|
| 558 |
+
yname, yname_list = results._get_endog_name(model.endog_names,
|
| 559 |
+
None, all=True)
|
| 560 |
+
else:
|
| 561 |
+
yname = model.endog_names
|
| 562 |
+
yname_list = [yname]
|
| 563 |
+
|
| 564 |
+
smry.add_table_2cols(self, gleft=top_left, gright=[],
|
| 565 |
+
yname=yname, xname=exog_names, title=title)
|
| 566 |
+
|
| 567 |
+
# NOTE: add_table_params is not general enough yet for margeff
|
| 568 |
+
# could use a refactor with getattr instead of hard-coded params
|
| 569 |
+
# tvalues etc.
|
| 570 |
+
table = []
|
| 571 |
+
conf_int = self.conf_int(alpha)
|
| 572 |
+
margeff = self.margeff
|
| 573 |
+
margeff_se = self.margeff_se
|
| 574 |
+
tvalues = self.tvalues
|
| 575 |
+
pvalues = self.pvalues
|
| 576 |
+
if J > 1:
|
| 577 |
+
for eq in range(J):
|
| 578 |
+
restup = (results, margeff[:,eq], margeff_se[:,eq],
|
| 579 |
+
tvalues[:,eq], pvalues[:,eq], conf_int[:,:,eq])
|
| 580 |
+
tble = summary_params(restup, yname=yname_list[eq],
|
| 581 |
+
xname=exog_names, alpha=alpha, use_t=False,
|
| 582 |
+
skip_header=True)
|
| 583 |
+
tble.title = yname_list[eq]
|
| 584 |
+
# overwrite coef with method name
|
| 585 |
+
header = ['', _transform_names[method], 'std err', 'z',
|
| 586 |
+
'P>|z|', '[' + str(alpha/2), str(1-alpha/2) + ']']
|
| 587 |
+
tble.insert_header_row(0, header)
|
| 588 |
+
table.append(tble)
|
| 589 |
+
|
| 590 |
+
table = table_extend(table, keep_headers=True)
|
| 591 |
+
else:
|
| 592 |
+
restup = (results, margeff, margeff_se, tvalues, pvalues, conf_int)
|
| 593 |
+
table = summary_params(restup, yname=yname, xname=exog_names,
|
| 594 |
+
alpha=alpha, use_t=False, skip_header=True)
|
| 595 |
+
header = ['', _transform_names[method], 'std err', 'z',
|
| 596 |
+
'P>|z|', '[' + str(alpha/2), str(1-alpha/2) + ']']
|
| 597 |
+
table.insert_header_row(0, header)
|
| 598 |
+
|
| 599 |
+
smry.tables.append(table)
|
| 600 |
+
return smry
|
| 601 |
+
|
| 602 |
+
def get_margeff(self, at='overall', method='dydx', atexog=None,
|
| 603 |
+
dummy=False, count=False):
|
| 604 |
+
"""Get marginal effects of the fitted model.
|
| 605 |
+
|
| 606 |
+
Parameters
|
| 607 |
+
----------
|
| 608 |
+
at : str, optional
|
| 609 |
+
Options are:
|
| 610 |
+
|
| 611 |
+
- 'overall', The average of the marginal effects at each
|
| 612 |
+
observation.
|
| 613 |
+
- 'mean', The marginal effects at the mean of each regressor.
|
| 614 |
+
- 'median', The marginal effects at the median of each regressor.
|
| 615 |
+
- 'zero', The marginal effects at zero for each regressor.
|
| 616 |
+
- 'all', The marginal effects at each observation. If `at` is all
|
| 617 |
+
only margeff will be available.
|
| 618 |
+
|
| 619 |
+
Note that if `exog` is specified, then marginal effects for all
|
| 620 |
+
variables not specified by `exog` are calculated using the `at`
|
| 621 |
+
option.
|
| 622 |
+
method : str, optional
|
| 623 |
+
Options are:
|
| 624 |
+
|
| 625 |
+
- 'dydx' - dy/dx - No transformation is made and marginal effects
|
| 626 |
+
are returned. This is the default.
|
| 627 |
+
- 'eyex' - estimate elasticities of variables in `exog` --
|
| 628 |
+
d(lny)/d(lnx)
|
| 629 |
+
- 'dyex' - estimate semi-elasticity -- dy/d(lnx)
|
| 630 |
+
- 'eydx' - estimate semi-elasticity -- d(lny)/dx
|
| 631 |
+
|
| 632 |
+
Note that tranformations are done after each observation is
|
| 633 |
+
calculated. Semi-elasticities for binary variables are computed
|
| 634 |
+
using the midpoint method. 'dyex' and 'eyex' do not make sense
|
| 635 |
+
for discrete variables.
|
| 636 |
+
atexog : array_like, optional
|
| 637 |
+
Optionally, you can provide the exogenous variables over which to
|
| 638 |
+
get the marginal effects. This should be a dictionary with the key
|
| 639 |
+
as the zero-indexed column number and the value of the dictionary.
|
| 640 |
+
Default is None for all independent variables less the constant.
|
| 641 |
+
dummy : bool, optional
|
| 642 |
+
If False, treats binary variables (if present) as continuous. This
|
| 643 |
+
is the default. Else if True, treats binary variables as
|
| 644 |
+
changing from 0 to 1. Note that any variable that is either 0 or 1
|
| 645 |
+
is treated as binary. Each binary variable is treated separately
|
| 646 |
+
for now.
|
| 647 |
+
count : bool, optional
|
| 648 |
+
If False, treats count variables (if present) as continuous. This
|
| 649 |
+
is the default. Else if True, the marginal effect is the
|
| 650 |
+
change in probabilities when each observation is increased by one.
|
| 651 |
+
|
| 652 |
+
Returns
|
| 653 |
+
-------
|
| 654 |
+
effects : ndarray
|
| 655 |
+
the marginal effect corresponding to the input options
|
| 656 |
+
|
| 657 |
+
Notes
|
| 658 |
+
-----
|
| 659 |
+
When using after Poisson, returns the expected number of events
|
| 660 |
+
per period, assuming that the model is loglinear.
|
| 661 |
+
"""
|
| 662 |
+
self._reset() # always reset the cache when this is called
|
| 663 |
+
#TODO: if at is not all or overall, we can also put atexog values
|
| 664 |
+
# in summary table head
|
| 665 |
+
method = method.lower()
|
| 666 |
+
at = at.lower()
|
| 667 |
+
_check_margeff_args(at, method)
|
| 668 |
+
self.margeff_options = dict(method=method, at=at)
|
| 669 |
+
results = self.results
|
| 670 |
+
model = results.model
|
| 671 |
+
params = results.params
|
| 672 |
+
exog = model.exog.copy() # copy because values are changed
|
| 673 |
+
effects_idx, const_idx = _get_const_index(exog)
|
| 674 |
+
|
| 675 |
+
if dummy:
|
| 676 |
+
_check_discrete_args(at, method)
|
| 677 |
+
dummy_idx, dummy = _get_dummy_index(exog, const_idx)
|
| 678 |
+
else:
|
| 679 |
+
dummy_idx = None
|
| 680 |
+
|
| 681 |
+
if count:
|
| 682 |
+
_check_discrete_args(at, method)
|
| 683 |
+
count_idx, count = _get_count_index(exog, const_idx)
|
| 684 |
+
else:
|
| 685 |
+
count_idx = None
|
| 686 |
+
|
| 687 |
+
# attach dummy_idx and cout_idx
|
| 688 |
+
self.dummy_idx = dummy_idx
|
| 689 |
+
self.count_idx = count_idx
|
| 690 |
+
|
| 691 |
+
# get the exogenous variables
|
| 692 |
+
exog = _get_margeff_exog(exog, at, atexog, effects_idx)
|
| 693 |
+
|
| 694 |
+
# get base marginal effects, handled by sub-classes
|
| 695 |
+
effects = model._derivative_exog(params, exog, method,
|
| 696 |
+
dummy_idx, count_idx)
|
| 697 |
+
|
| 698 |
+
J = getattr(model, 'J', 1)
|
| 699 |
+
effects_idx = np.tile(effects_idx, J) # adjust for multi-equation.
|
| 700 |
+
|
| 701 |
+
effects = _effects_at(effects, at)
|
| 702 |
+
|
| 703 |
+
if at == 'all':
|
| 704 |
+
if J > 1:
|
| 705 |
+
K = model.K - np.any(~effects_idx) # subtract constant
|
| 706 |
+
self.margeff = effects[:, effects_idx].reshape(-1, K, J,
|
| 707 |
+
order='F')
|
| 708 |
+
else:
|
| 709 |
+
self.margeff = effects[:, effects_idx]
|
| 710 |
+
else:
|
| 711 |
+
# Set standard error of the marginal effects by Delta method.
|
| 712 |
+
margeff_cov, margeff_se = margeff_cov_with_se(model, params, exog,
|
| 713 |
+
results.cov_params(), at,
|
| 714 |
+
model._derivative_exog,
|
| 715 |
+
dummy_idx, count_idx,
|
| 716 |
+
method, J)
|
| 717 |
+
|
| 718 |
+
# reshape for multi-equation
|
| 719 |
+
if J > 1:
|
| 720 |
+
K = model.K - np.any(~effects_idx) # subtract constant
|
| 721 |
+
self.margeff = effects[effects_idx].reshape(K, J, order='F')
|
| 722 |
+
self.margeff_se = margeff_se[effects_idx].reshape(K, J,
|
| 723 |
+
order='F')
|
| 724 |
+
self.margeff_cov = margeff_cov[effects_idx][:, effects_idx]
|
| 725 |
+
else:
|
| 726 |
+
# do not care about at constant
|
| 727 |
+
# hack truncate effects_idx again if necessary
|
| 728 |
+
# if eyex, then effects is truncated to be without extra params
|
| 729 |
+
effects_idx = effects_idx[:len(effects)]
|
| 730 |
+
self.margeff_cov = margeff_cov[effects_idx][:, effects_idx]
|
| 731 |
+
self.margeff_se = margeff_se[effects_idx]
|
| 732 |
+
self.margeff = effects[effects_idx]
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/discrete_model.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__init__.py
ADDED
|
File without changes
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (200 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_conditional.cpython-310.pyc
ADDED
|
Binary file (8.08 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_constrained.cpython-310.pyc
ADDED
|
Binary file (15.4 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_count_model.cpython-310.pyc
ADDED
|
Binary file (22.4 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_diagnostic.cpython-310.pyc
ADDED
|
Binary file (4.02 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_discrete.cpython-310.pyc
ADDED
|
Binary file (91.1 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_margins.cpython-310.pyc
ADDED
|
Binary file (3.96 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_predict.cpython-310.pyc
ADDED
|
Binary file (11.2 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_sandwich_cov.cpython-310.pyc
ADDED
|
Binary file (22.2 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/__pycache__/test_truncated_model.cpython-310.pyc
ADDED
|
Binary file (16.9 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__init__.py
ADDED
|
File without changes
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (208 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_count_margins.cpython-310.pyc
ADDED
|
Binary file (9.04 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_count_robust_cluster.cpython-310.pyc
ADDED
|
Binary file (11.5 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_discrete.cpython-310.pyc
ADDED
|
Binary file (32 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_glm_logit_constrained.cpython-310.pyc
ADDED
|
Binary file (12.5 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_poisson_constrained.cpython-310.pyc
ADDED
|
Binary file (14.3 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_predict.cpython-310.pyc
ADDED
|
Binary file (8.29 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_truncated.cpython-310.pyc
ADDED
|
Binary file (1.41 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/__pycache__/results_truncated_st.cpython-310.pyc
ADDED
|
Binary file (13.7 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/mn_logit_summary.txt
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
==============================================================================
|
| 2 |
+
y=1 coef std err z P>|z| [0.025 0.975]
|
| 3 |
+
------------------------------------------------------------------------------
|
| 4 |
+
const -0.2794 0.612 -0.457 0.648 -1.479 0.920
|
| 5 |
+
x1 -0.0119 0.034 -0.350 0.727 -0.079 0.055
|
| 6 |
+
x2 0.2946 0.093 3.152 0.002 0.111 0.478
|
| 7 |
+
x3 -0.0257 0.007 -3.873 0.000 -0.039 -0.013
|
| 8 |
+
x4 0.0897 0.069 1.297 0.195 -0.046 0.225
|
| 9 |
+
------------------------------------------------------------------------------
|
| 10 |
+
y=2 coef std err z P>|z| [0.025 0.975]
|
| 11 |
+
------------------------------------------------------------------------------
|
| 12 |
+
const -1.7392 0.720 -2.414 0.016 -3.151 -0.327
|
| 13 |
+
x1 -0.0941 0.039 -2.415 0.016 -0.170 -0.018
|
| 14 |
+
x2 0.3838 0.108 3.559 0.000 0.172 0.595
|
| 15 |
+
x3 -0.0230 0.008 -2.914 0.004 -0.038 -0.008
|
| 16 |
+
x4 0.2451 0.080 3.053 0.002 0.088 0.402
|
| 17 |
+
------------------------------------------------------------------------------
|
| 18 |
+
y=3 coef std err z P>|z| [0.025 0.975]
|
| 19 |
+
------------------------------------------------------------------------------
|
| 20 |
+
const -3.0091 1.069 -2.815 0.005 -5.104 -0.914
|
| 21 |
+
x1 -0.1115 0.057 -1.965 0.049 -0.223 -0.000
|
| 22 |
+
x2 0.5641 0.159 3.557 0.000 0.253 0.875
|
| 23 |
+
x3 -0.0156 0.011 -1.391 0.164 -0.038 0.006
|
| 24 |
+
x4 0.0687 0.119 0.577 0.564 -0.165 0.302
|
| 25 |
+
------------------------------------------------------------------------------
|
| 26 |
+
y=4 coef std err z P>|z| [0.025 0.975]
|
| 27 |
+
------------------------------------------------------------------------------
|
| 28 |
+
const -6.5607 0.870 -7.540 0.000 -8.266 -4.855
|
| 29 |
+
x1 -0.0949 0.043 -2.183 0.029 -0.180 -0.010
|
| 30 |
+
x2 1.2668 0.128 9.897 0.000 1.016 1.518
|
| 31 |
+
x3 -0.0109 0.008 -1.315 0.189 -0.027 0.005
|
| 32 |
+
x4 0.3067 0.088 3.475 0.001 0.134 0.480
|
| 33 |
+
------------------------------------------------------------------------------
|
| 34 |
+
y=5 coef std err z P>|z| [0.025 0.975]
|
| 35 |
+
------------------------------------------------------------------------------
|
| 36 |
+
const -6.0760 0.774 -7.851 0.000 -7.593 -4.559
|
| 37 |
+
x1 -0.0967 0.039 -2.479 0.013 -0.173 -0.020
|
| 38 |
+
x2 1.3377 0.116 11.493 0.000 1.110 1.566
|
| 39 |
+
x3 -0.0198 0.008 -2.631 0.009 -0.035 -0.005
|
| 40 |
+
x4 0.3193 0.080 4.001 0.000 0.163 0.476
|
| 41 |
+
------------------------------------------------------------------------------
|
| 42 |
+
y=6 coef std err z P>|z| [0.025 0.975]
|
| 43 |
+
------------------------------------------------------------------------------
|
| 44 |
+
const -10.5973 0.957 -11.076 0.000 -12.473 -8.722
|
| 45 |
+
x1 -0.1447 0.042 -3.475 0.001 -0.226 -0.063
|
| 46 |
+
x2 2.0395 0.141 14.479 0.000 1.763 2.316
|
| 47 |
+
x3 -0.0129 0.008 -1.612 0.107 -0.029 0.003
|
| 48 |
+
x4 0.4576 0.085 5.352 0.000 0.290 0.625
|
| 49 |
+
==============================================================================
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/mnlogit_resid.csv
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
0.00,0.00,0.00,0.00,0.00,0.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,0.00,1.00,0.00,1.00,0.00,0.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,0.00,0.00,0.00,0.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,0.00,0.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,0.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,0.00,0.00,1.00,1.00,0.00,0.00,0.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,0.00,0.00,0.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,0.00,0.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,0.00,1.00,0.00,0.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,0.00,0.00,0.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,0.00,0.00,0.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,0.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,0.00,0.00,0.00,0.00,1.00,0.00,0.00,0.00,1.00,0.00,0.00,1.00,0.00,1.00,1.00,0.00,0.00,0.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,0.00,0.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,0.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,1.00,1.00,0.00,0.00,0.00,0.00,1.00,0.00,0.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,1.00,0.00,0.00,1.00,1.00,1.00,0.00,1.00,0.00,0.00,0.00,0.00,1.00,0.00,0.00,0.00,0.00,1.00,0.00,0.00,0.00,0.00,0.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,1.00,1.00,0.00,0.00,1.00,0.00,0.00,1.00,0.00,1.00,0.00,0.00,0.00,1.00,0.00,1.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,0.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,0.00,0.00,1.00,0.00,1.00,1.00,0.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,0.00,0.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,0.00,0.00,1.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,0.00,0.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,0.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,0.00,0.00,1.00,1.00,0.00,0.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,0.00,0.00,0.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,0.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,0.00,0.00,1.00,0.00,0.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,0.00,0.00,1.00,0.00,1.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,0.00,0.00,1.00,0.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,0.00,0.00,1.00,0.00,1.00,0.00,1.00,0.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,0.00,1.00,1.00,0.00,0.00,0.00,1.00,0.00,0.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,0.00,0.00,0.00,0.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,0.00,0.00,0.00,0.00,0.00,0.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,0.00,1.00,0.00,1.00,1.00,0.00,0.00,1.00,1.00,0.00,0.00,1.00,1.00,1.00,0.00,1.00,1.00,0.00,1.00,1.00,1.00,0.00,1.00,1.00,1.00,1.00,0.00,0.00,0.00,0.00,1.00,0.00,1.00,0.00,1.00
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/nbinom_resids.csv
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-.5049508,-.6297218,-83.54991,-1.306285,-6.620286
|
| 2 |
+
-.2341522,-.2554235,-216.8307,-.758866,-7.183702
|
| 3 |
+
1.024237,.7987758,483.7363,2.503515,22.51353
|
| 4 |
+
-.2850617,-.3177966,-70411.51,-2.379918,-141.7456
|
| 5 |
+
.2099025,.1967877,2247.514,.9519455,21.77242
|
| 6 |
+
-.4034835,-.4757415,-19563.36,-2.635026,-88.94614
|
| 7 |
+
-.1644134,-.1744011,-17331.03,-1.162355,-53.42135
|
| 8 |
+
-.4296077,-.5134667,-5300.37,-2.244962,-47.82603
|
| 9 |
+
.323713,.2941846,4110.794,1.486844,36.55984
|
| 10 |
+
.1503672,.1434294,7285.321,.8855429,33.1355
|
| 11 |
+
.4212886,.373428,1373.157,1.521332,24.15702
|
| 12 |
+
.4506587,.3965867,1701.469,1.661779,27.80326
|
| 13 |
+
.2435375,.226174,3184.023,1.136562,27.90734
|
| 14 |
+
1.051829,.8162054,6001.352,3.890797,79.71313
|
| 15 |
+
-.5544503,-.712749,-2094.852,-2.454965,-34.21899
|
| 16 |
+
-.6057506,-.8064111,-274.7382,-1.907744,-13.05105
|
| 17 |
+
-.3412157,-.3902446,-631.138,-1.270229,-14.76001
|
| 18 |
+
.2218985,.2073287,691.1358,.8168764,12.43929
|
| 19 |
+
.2455925,.2266392,.1992506,.2579483,.2747237
|
| 20 |
+
-.7589526,-1.153008,-256.739,-2.407166,-14.14742
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/phat_mnlogit.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/poisson_resid.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/predict_prob_poisson.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_count_margins.py
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from statsmodels.tools.testing import MarginTableTestBunch
|
| 4 |
+
|
| 5 |
+
est = dict(
|
| 6 |
+
rank=7,
|
| 7 |
+
N=17,
|
| 8 |
+
ic=6,
|
| 9 |
+
k=7,
|
| 10 |
+
k_eq=1,
|
| 11 |
+
k_dv=1,
|
| 12 |
+
converged=1,
|
| 13 |
+
rc=0,
|
| 14 |
+
k_autoCns=0,
|
| 15 |
+
ll=-28.46285727296058,
|
| 16 |
+
k_eq_model=1,
|
| 17 |
+
ll_0=-101.6359341820935,
|
| 18 |
+
df_m=6,
|
| 19 |
+
chi2=146.3461538182658,
|
| 20 |
+
p=4.58013206701e-29,
|
| 21 |
+
r2_p=.719952814897477,
|
| 22 |
+
properties="b V",
|
| 23 |
+
depvar="sexecutions",
|
| 24 |
+
which="max",
|
| 25 |
+
technique="nr",
|
| 26 |
+
singularHmethod="m-marquardt",
|
| 27 |
+
ml_method="e2",
|
| 28 |
+
crittype="log likelihood",
|
| 29 |
+
user="poiss_lf",
|
| 30 |
+
title="Poisson regression",
|
| 31 |
+
vce="oim",
|
| 32 |
+
opt="moptimize",
|
| 33 |
+
chi2type="LR",
|
| 34 |
+
gof="poiss_g",
|
| 35 |
+
estat_cmd="poisson_estat",
|
| 36 |
+
predict="poisso_p",
|
| 37 |
+
cmd="poisson",
|
| 38 |
+
cmdline="poisson sexecutions sincome sperpoverty sperblack LN_VC100k96 south sdegree", # noqa:E501
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
margins_table = np.array([
|
| 42 |
+
47.514189267677, 12.722695157081, 3.7346009380122, .000188013074,
|
| 43 |
+
22.578164973516, 72.450213561838, np.nan, 1.9599639845401,
|
| 44 |
+
0, 2.3754103372885, 7.6314378245266, .31126642081184,
|
| 45 |
+
.75559809249357, -12.58193294904, 17.332753623617, np.nan,
|
| 46 |
+
1.9599639845401, 0, -11.583732327397, 3.8511214886273,
|
| 47 |
+
-3.007885459237, .00263072269737, -19.131791745195, -4.0356729095995,
|
| 48 |
+
np.nan, 1.9599639845401, 0, -1.807106397978,
|
| 49 |
+
14.19277372084, -.12732580914219, .89868253380624, -29.624431731551,
|
| 50 |
+
26.010218935595, np.nan, 1.9599639845401, 0,
|
| 51 |
+
10.852916363139, 2.6197368291491, 4.1427506161617, .00003431650408,
|
| 52 |
+
5.7183265290336, 15.987506197244, np.nan, 1.9599639845401,
|
| 53 |
+
0, -26.588397789444, 7.6315578612519, -3.4840065780596,
|
| 54 |
+
.00049396734722, -41.545976343431, -11.630819235457, np.nan,
|
| 55 |
+
1.9599639845401, 0]).reshape(6, 9)
|
| 56 |
+
|
| 57 |
+
margins_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 58 |
+
|
| 59 |
+
margins_table_rownames = ['sincome', 'sperpoverty', 'sperblack',
|
| 60 |
+
'LN_VC100k96', 'south', 'sdegree']
|
| 61 |
+
|
| 62 |
+
margins_cov = np.array([
|
| 63 |
+
10.87507957467, 3.4816608831283, .87483487811437, 3.1229403520191,
|
| 64 |
+
-.87306122632875, -2.2870394487277, -12.321063650937, 3.4816608831283,
|
| 65 |
+
5.1715652306254, .27473956091394, 1.7908952063684, -.92880259796684,
|
| 66 |
+
1.8964947971413, -9.0063087868006, .87483487811437, .27473956091394,
|
| 67 |
+
1.1098392181639, -.99390727840297, -.34477731736542, -.98869834020742,
|
| 68 |
+
.41772084541889, 3.1229403520191, 1.7908952063684, -.99390727840297,
|
| 69 |
+
17.912620004361, -.30763138390107, 2.8490197200257, -21.269786576194,
|
| 70 |
+
-.87306122632875, -.92880259796684, -.34477731736542, -.30763138390107,
|
| 71 |
+
.42666000427673, .05265352402592, 1.461997775289, -2.2870394487277,
|
| 72 |
+
1.8964947971413, -.98869834020742, 2.8490197200257, .05265352402592,
|
| 73 |
+
4.0773252373088, -4.46154120848, -12.321063650937, -9.0063087868006,
|
| 74 |
+
.41772084541889, -21.269786576194, 1.461997775289, -4.46154120848,
|
| 75 |
+
37.559994394326]).reshape(7, 7)
|
| 76 |
+
|
| 77 |
+
margins_cov_colnames = ['sincome', 'sperpoverty', 'sperblack', 'LN_VC100k96',
|
| 78 |
+
'south', 'sdegree', '_cons']
|
| 79 |
+
|
| 80 |
+
margins_cov_rownames = ['sincome', 'sperpoverty', 'sperblack', 'LN_VC100k96',
|
| 81 |
+
'south', 'sdegree', '_cons']
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
results_poisson_margins_cont = MarginTableTestBunch(
|
| 85 |
+
margins_table=margins_table,
|
| 86 |
+
margins_table_colnames=margins_table_colnames,
|
| 87 |
+
margins_table_rownames=margins_table_rownames,
|
| 88 |
+
margins_cov=margins_cov,
|
| 89 |
+
margins_cov_colnames=margins_cov_colnames,
|
| 90 |
+
margins_cov_rownames=margins_cov_rownames,
|
| 91 |
+
**est
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
est = dict(
|
| 95 |
+
alpha=1.1399915663048,
|
| 96 |
+
rank=8,
|
| 97 |
+
N=17,
|
| 98 |
+
ic=6,
|
| 99 |
+
k=8,
|
| 100 |
+
k_eq=2,
|
| 101 |
+
k_dv=1,
|
| 102 |
+
converged=1,
|
| 103 |
+
rc=0,
|
| 104 |
+
k_autoCns=0,
|
| 105 |
+
ll=-27.58269157281191,
|
| 106 |
+
k_eq_model=1,
|
| 107 |
+
ll_0=-32.87628220135203,
|
| 108 |
+
rank0=2,
|
| 109 |
+
df_m=6,
|
| 110 |
+
chi2=10.58718125708024,
|
| 111 |
+
p=.1020042170100994,
|
| 112 |
+
ll_c=-28.46285727296058,
|
| 113 |
+
chi2_c=1.760331400297339,
|
| 114 |
+
r2_p=.1610154881905236,
|
| 115 |
+
k_aux=1,
|
| 116 |
+
properties="b V",
|
| 117 |
+
depvar="sexecutions",
|
| 118 |
+
which="max",
|
| 119 |
+
technique="nr",
|
| 120 |
+
singularHmethod="m-marquardt",
|
| 121 |
+
ml_method="e2",
|
| 122 |
+
crittype="log likelihood",
|
| 123 |
+
user="nbreg_lf",
|
| 124 |
+
diparm1="lnalpha, exp label(",
|
| 125 |
+
title="Negative binomial regression",
|
| 126 |
+
vce="oim",
|
| 127 |
+
opt="moptimize",
|
| 128 |
+
chi2type="LR",
|
| 129 |
+
chi2_ct="LR",
|
| 130 |
+
diparm_opt2="noprob",
|
| 131 |
+
dispers="mean",
|
| 132 |
+
predict="nbreg_p",
|
| 133 |
+
cmd="nbreg",
|
| 134 |
+
cmdline="nbreg sexecutions sincome sperpoverty sperblack LN_VC100k96 south sdegree", # noqa:E501
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
margins_table = np.array([
|
| 138 |
+
38.76996449636, 35.863089953808, 1.0810547709719, .27967275079666,
|
| 139 |
+
-31.520400187424, 109.06032918014, np.nan, 1.9599639845401,
|
| 140 |
+
0, 2.5208248279391, 11.710699937092, .21525825454332,
|
| 141 |
+
.82956597472339, -20.431725282518, 25.473374938396, np.nan,
|
| 142 |
+
1.9599639845401, 0, -8.225606184332, 9.557721280021,
|
| 143 |
+
-.86062419517573, .38944505570119, -26.958395667445, 10.507183298781,
|
| 144 |
+
np.nan, 1.9599639845401, 0, -4.4150939806524,
|
| 145 |
+
28.010544627225, -.15762256819387, .87475421903252, -59.314752637366,
|
| 146 |
+
50.484564676062, np.nan, 1.9599639845401, 0,
|
| 147 |
+
7.0049476220304, 6.3399264323903, 1.1048941492826, .26920545789466,
|
| 148 |
+
-5.4210798500881, 19.430975094149, np.nan, 1.9599639845401,
|
| 149 |
+
0, -25.128303596214, 23.247820190364, -1.0808885904335,
|
| 150 |
+
.279746674501, -70.693193888391, 20.436586695964, np.nan,
|
| 151 |
+
1.9599639845401, 0]).reshape(6, 9)
|
| 152 |
+
|
| 153 |
+
margins_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 154 |
+
|
| 155 |
+
margins_table_rownames = ['sincome', 'sperpoverty', 'sperblack',
|
| 156 |
+
'LN_VC100k96', 'south', 'sdegree']
|
| 157 |
+
|
| 158 |
+
margins_cov = np.array([
|
| 159 |
+
44.468037032422, 13.291812805254, .84306554343753, -.38095027773819,
|
| 160 |
+
-2.1265212254924, -18.06714825989, -30.427077474507, .36347806905257,
|
| 161 |
+
13.291812805254, 15.093124820143, 3.3717840254072, -7.6860995498613,
|
| 162 |
+
-3.3867901970823, -1.4200645173727, -12.979849717094, .51706617429388,
|
| 163 |
+
.84306554343753, 3.3717840254072, 5.6928040093481, -12.140553562993,
|
| 164 |
+
-2.5831646721297, -1.8071496111137, 7.961664784177, .27439267406128,
|
| 165 |
+
-.38095027773819, -7.6860995498613, -12.140553562993, 91.950706114029,
|
| 166 |
+
6.6107070350689, 9.5470604840407, -82.665769963947, -1.1433180909155,
|
| 167 |
+
-2.1265212254924, -3.3867901970823, -2.5831646721297, 6.6107070350689,
|
| 168 |
+
2.0499053083335, 1.7094543055869, -3.029543334606, -.34297224102579,
|
| 169 |
+
-18.06714825989, -1.4200645173727, -1.8071496111137, 9.5470604840407,
|
| 170 |
+
1.7094543055869, 18.442703265156, -6.5839965105886, -.61952491151176,
|
| 171 |
+
-30.427077474507, -12.979849717094, 7.961664784177, -82.665769963947,
|
| 172 |
+
-3.029543334606, -6.5839965105886, 111.12618806587, .88600743091011,
|
| 173 |
+
.36347806905257, .51706617429388, .27439267406128, -1.1433180909155,
|
| 174 |
+
-.34297224102579, -.61952491151176, .88600743091011, .71851239110057
|
| 175 |
+
]).reshape(8, 8)
|
| 176 |
+
|
| 177 |
+
margins_cov_colnames = ['sincome', 'sperpoverty', 'sperblack', 'LN_VC100k96',
|
| 178 |
+
'south', 'sdegree', '_cons', '_cons']
|
| 179 |
+
|
| 180 |
+
margins_cov_rownames = ['sincome', 'sperpoverty', 'sperblack', 'LN_VC100k96',
|
| 181 |
+
'south', 'sdegree', '_cons', '_cons']
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
results_negbin_margins_cont = MarginTableTestBunch(
|
| 185 |
+
margins_table=margins_table,
|
| 186 |
+
margins_table_colnames=margins_table_colnames,
|
| 187 |
+
margins_table_rownames=margins_table_rownames,
|
| 188 |
+
margins_cov=margins_cov,
|
| 189 |
+
margins_cov_colnames=margins_cov_colnames,
|
| 190 |
+
margins_cov_rownames=margins_cov_rownames,
|
| 191 |
+
**est
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
est = dict(
|
| 195 |
+
rank=7,
|
| 196 |
+
N=17,
|
| 197 |
+
ic=6,
|
| 198 |
+
k=8,
|
| 199 |
+
k_eq=1,
|
| 200 |
+
k_dv=1,
|
| 201 |
+
converged=1,
|
| 202 |
+
rc=0,
|
| 203 |
+
k_autoCns=1,
|
| 204 |
+
ll=-28.46285727296058,
|
| 205 |
+
k_eq_model=1,
|
| 206 |
+
ll_0=-101.6359341820935,
|
| 207 |
+
df_m=6,
|
| 208 |
+
chi2=146.3461538182658,
|
| 209 |
+
p=4.58013206701e-29,
|
| 210 |
+
r2_p=.719952814897477,
|
| 211 |
+
properties="b V",
|
| 212 |
+
depvar="sexecutions",
|
| 213 |
+
which="max",
|
| 214 |
+
technique="nr",
|
| 215 |
+
singularHmethod="m-marquardt",
|
| 216 |
+
ml_method="e2",
|
| 217 |
+
crittype="log likelihood",
|
| 218 |
+
user="poiss_lf",
|
| 219 |
+
title="Poisson regression",
|
| 220 |
+
vce="oim",
|
| 221 |
+
opt="moptimize",
|
| 222 |
+
chi2type="LR",
|
| 223 |
+
gof="poiss_g",
|
| 224 |
+
estat_cmd="poisson_estat",
|
| 225 |
+
predict="poisso_p",
|
| 226 |
+
cmd="poisson",
|
| 227 |
+
cmdline="poisson sexecutions sincome sperpoverty sperblack LN_VC100k96 i.south sdegree", # noqa:E501
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
margins_table = np.array([
|
| 231 |
+
47.514189267677, 12.72269515678, 3.7346009381004, .00018801307393,
|
| 232 |
+
22.578164974105, 72.450213561249, np.nan, 1.9599639845401,
|
| 233 |
+
0, 2.3754103372885, 7.6314378245485, .31126642081095,
|
| 234 |
+
.75559809249425, -12.581932949083, 17.33275362366, np.nan,
|
| 235 |
+
1.9599639845401, 0, -11.583732327397, 3.8511214887188,
|
| 236 |
+
-3.0078854591656, .00263072269799, -19.131791745374, -4.0356729094203,
|
| 237 |
+
np.nan, 1.9599639845401, 0, -1.807106397978,
|
| 238 |
+
14.192773720841, -.12732580914219, .89868253380624, -29.624431731552,
|
| 239 |
+
26.010218935596, np.nan, 1.9599639845401, 0,
|
| 240 |
+
0, np.nan, np.nan, np.nan,
|
| 241 |
+
np.nan, np.nan, np.nan, 1.9599639845401,
|
| 242 |
+
0, 12.894515685772, 5.7673506886042, 2.2357779822979,
|
| 243 |
+
.02536631788468, 1.5907160498956, 24.198315321648, np.nan,
|
| 244 |
+
1.9599639845401, 0, -26.588397789444, 7.6315578608763,
|
| 245 |
+
-3.4840065782311, .00049396734691, -41.545976342695, -11.630819236193,
|
| 246 |
+
np.nan, 1.9599639845401, 0]).reshape(7, 9)
|
| 247 |
+
|
| 248 |
+
margins_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 249 |
+
|
| 250 |
+
margins_table_rownames = ['sincome', 'sperpoverty', 'sperblack', 'LN_VC100k96',
|
| 251 |
+
'0b.south', '1.south', 'sdegree']
|
| 252 |
+
|
| 253 |
+
margins_cov = np.array([
|
| 254 |
+
10.875079574674, 3.4816608831298, .87483487811447, 3.1229403520208,
|
| 255 |
+
0, -.873061226329, -2.2870394487282, -12.321063650942,
|
| 256 |
+
3.4816608831298, 5.1715652306252, .27473956091396, 1.7908952063684,
|
| 257 |
+
0, -.92880259796679, 1.8964947971405, -9.0063087868012,
|
| 258 |
+
.87483487811447, .27473956091396, 1.109839218164, -.9939072784041,
|
| 259 |
+
0, -.34477731736544, -.98869834020768, .41772084541996,
|
| 260 |
+
3.1229403520208, 1.7908952063684, -.9939072784041, 17.912620004373,
|
| 261 |
+
0, -.30763138390086, 2.8490197200274, -21.269786576207,
|
| 262 |
+
0, 0, 0, 0,
|
| 263 |
+
0, 0, 0, 0,
|
| 264 |
+
-.873061226329, -.92880259796679, -.34477731736544, -.30763138390086,
|
| 265 |
+
0, .42666000427672, .05265352402609, 1.4619977752889,
|
| 266 |
+
-2.2870394487282, 1.8964947971405, -.98869834020768, 2.8490197200274,
|
| 267 |
+
0, .05265352402609, 4.0773252373089, -4.4615412084808,
|
| 268 |
+
-12.321063650942, -9.0063087868012, .41772084541996, -21.269786576207,
|
| 269 |
+
0, 1.4619977752889, -4.4615412084808, 37.559994394343
|
| 270 |
+
]).reshape(8, 8)
|
| 271 |
+
|
| 272 |
+
margins_cov_colnames = ['sincome', 'sperpoverty', 'sperblack', 'LN_VC100k96',
|
| 273 |
+
'0b.south', '1.south', 'sdegree', '_cons']
|
| 274 |
+
|
| 275 |
+
margins_cov_rownames = ['sincome', 'sperpoverty', 'sperblack', 'LN_VC100k96',
|
| 276 |
+
'0b.south', '1.south', 'sdegree', '_cons']
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
results_poisson_margins_dummy = MarginTableTestBunch(
|
| 280 |
+
margins_table=margins_table,
|
| 281 |
+
margins_table_colnames=margins_table_colnames,
|
| 282 |
+
margins_table_rownames=margins_table_rownames,
|
| 283 |
+
margins_cov=margins_cov,
|
| 284 |
+
margins_cov_colnames=margins_cov_colnames,
|
| 285 |
+
margins_cov_rownames=margins_cov_rownames,
|
| 286 |
+
**est
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
est = dict(
|
| 290 |
+
alpha=1.139991566304804,
|
| 291 |
+
rank=8,
|
| 292 |
+
N=17,
|
| 293 |
+
ic=6,
|
| 294 |
+
k=9,
|
| 295 |
+
k_eq=2,
|
| 296 |
+
k_dv=1,
|
| 297 |
+
converged=1,
|
| 298 |
+
rc=0,
|
| 299 |
+
k_autoCns=1,
|
| 300 |
+
ll=-27.58269157281191,
|
| 301 |
+
k_eq_model=1,
|
| 302 |
+
ll_0=-32.87628220135203,
|
| 303 |
+
rank0=2,
|
| 304 |
+
df_m=6,
|
| 305 |
+
chi2=10.58718125708025,
|
| 306 |
+
p=.1020042170100991,
|
| 307 |
+
ll_c=-28.46285727296058,
|
| 308 |
+
chi2_c=1.760331400297339,
|
| 309 |
+
r2_p=.1610154881905237,
|
| 310 |
+
k_aux=1,
|
| 311 |
+
properties="b V",
|
| 312 |
+
depvar="sexecutions",
|
| 313 |
+
which="max",
|
| 314 |
+
technique="nr",
|
| 315 |
+
singularHmethod="m-marquardt",
|
| 316 |
+
ml_method="e2",
|
| 317 |
+
crittype="log likelihood",
|
| 318 |
+
user="nbreg_lf",
|
| 319 |
+
diparm1="lnalpha, exp label(",
|
| 320 |
+
title="Negative binomial regression",
|
| 321 |
+
vce="oim",
|
| 322 |
+
opt="moptimize",
|
| 323 |
+
chi2type="LR",
|
| 324 |
+
chi2_ct="LR",
|
| 325 |
+
diparm_opt2="noprob",
|
| 326 |
+
dispers="mean",
|
| 327 |
+
predict="nbreg_p",
|
| 328 |
+
cmd="nbreg",
|
| 329 |
+
cmdline="nbreg sexecutions sincome sperpoverty sperblack LN_VC100k96 i.south sdegree", # noqa:E501
|
| 330 |
+
)
|
| 331 |
+
|
| 332 |
+
margins_table = np.array([
|
| 333 |
+
38.769964496355, 35.863089979665, 1.0810547701924, .27967275114341,
|
| 334 |
+
-31.520400238107, 109.06032923082, np.nan, 1.9599639845401,
|
| 335 |
+
0, 2.5208248279388, 11.710699937639, .21525825453324,
|
| 336 |
+
.82956597473124, -20.43172528359, 25.473374939467, np.nan,
|
| 337 |
+
1.9599639845401, 0, -8.2256061843309, 9.5577212853699,
|
| 338 |
+
-.86062419469397, .38944505596662, -26.958395677928, 10.507183309266,
|
| 339 |
+
np.nan, 1.9599639845401, 0, -4.4150939806521,
|
| 340 |
+
28.010544626815, -.15762256819618, .87475421903071, -59.314752636561,
|
| 341 |
+
50.484564675257, np.nan, 1.9599639845401, 0,
|
| 342 |
+
0, np.nan, np.nan, np.nan,
|
| 343 |
+
np.nan, np.nan, np.nan, 1.9599639845401,
|
| 344 |
+
0, 8.0380552593041, 8.8634487485248, .90687671214231,
|
| 345 |
+
.36447199739385, -9.3339850666211, 25.410095585229, np.nan,
|
| 346 |
+
1.9599639845401, 0, -25.12830359621, 23.247820207656,
|
| 347 |
+
-1.0808885896294, .27974667485873, -70.693193922279, 20.436586729858,
|
| 348 |
+
np.nan, 1.9599639845401, 0]).reshape(7, 9)
|
| 349 |
+
|
| 350 |
+
margins_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 351 |
+
|
| 352 |
+
margins_table_rownames = ['sincome', 'sperpoverty', 'sperblack', 'LN_VC100k96',
|
| 353 |
+
'0b.south', '1.south', 'sdegree']
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
margins_cov = np.array([
|
| 357 |
+
44.468037032424, 13.291812805256, .84306554343906, -.38095027774827,
|
| 358 |
+
0, -2.1265212254934, -18.067148259892, -30.427077474499,
|
| 359 |
+
.36347806905277, 13.291812805256, 15.093124820144, 3.3717840254072,
|
| 360 |
+
-7.6860995498609, 0, -3.3867901970823, -1.4200645173736,
|
| 361 |
+
-12.979849717095, .51706617429393, .84306554343906, 3.3717840254072,
|
| 362 |
+
5.6928040093478, -12.14055356299, 0, -2.5831646721296,
|
| 363 |
+
-1.8071496111144, 7.9616647841741, .27439267406129, -.38095027774827,
|
| 364 |
+
-7.6860995498609, -12.14055356299, 91.950706114005, 0,
|
| 365 |
+
6.6107070350678, 9.5470604840447, -82.665769963921, -1.1433180909154,
|
| 366 |
+
0, 0, 0, 0,
|
| 367 |
+
0, 0, 0, 0,
|
| 368 |
+
0, -2.1265212254934, -3.3867901970823, -2.5831646721296,
|
| 369 |
+
6.6107070350678, 0, 2.0499053083335, 1.7094543055874,
|
| 370 |
+
-3.0295433346046, -.34297224102581, -18.067148259892, -1.4200645173736,
|
| 371 |
+
-1.8071496111144, 9.5470604840447, 0, 1.7094543055874,
|
| 372 |
+
18.442703265157, -6.5839965105912, -.61952491151187, -30.427077474499,
|
| 373 |
+
-12.979849717095, 7.9616647841741, -82.665769963921, 0,
|
| 374 |
+
-3.0295433346046, -6.5839965105912, 111.12618806584, .88600743090998,
|
| 375 |
+
.36347806905277, .51706617429393, .27439267406129, -1.1433180909154,
|
| 376 |
+
0, -.34297224102581, -.61952491151187, .88600743090998,
|
| 377 |
+
.71851239110059]).reshape(9, 9)
|
| 378 |
+
|
| 379 |
+
margins_cov_colnames = ['sincome', 'sperpoverty', 'sperblack', 'LN_VC100k96',
|
| 380 |
+
'0b.south', '1.south', 'sdegree', '_cons', '_cons']
|
| 381 |
+
|
| 382 |
+
margins_cov_rownames = ['sincome', 'sperpoverty', 'sperblack', 'LN_VC100k96',
|
| 383 |
+
'0b.south', '1.south', 'sdegree', '_cons', '_cons']
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
results_negbin_margins_dummy = MarginTableTestBunch(
|
| 387 |
+
margins_table=margins_table,
|
| 388 |
+
margins_table_colnames=margins_table_colnames,
|
| 389 |
+
margins_table_rownames=margins_table_rownames,
|
| 390 |
+
margins_cov=margins_cov,
|
| 391 |
+
margins_cov_colnames=margins_cov_colnames,
|
| 392 |
+
margins_cov_rownames=margins_cov_rownames,
|
| 393 |
+
**est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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from statsmodels.tools.testing import ParamsTableTestBunch
|
| 4 |
+
|
| 5 |
+
est = dict(
|
| 6 |
+
rank=3,
|
| 7 |
+
N=34,
|
| 8 |
+
ic=1,
|
| 9 |
+
k=3,
|
| 10 |
+
k_eq=1,
|
| 11 |
+
k_dv=1,
|
| 12 |
+
converged=1,
|
| 13 |
+
rc=0,
|
| 14 |
+
k_autoCns=0,
|
| 15 |
+
N_clust=5,
|
| 16 |
+
ll=-354.2436413025559,
|
| 17 |
+
k_eq_model=1,
|
| 18 |
+
ll_0=-356.2029100704882,
|
| 19 |
+
df_m=2,
|
| 20 |
+
chi2=5.204189583786304,
|
| 21 |
+
p=.0741181533729996,
|
| 22 |
+
r2_p=.0055004288638308,
|
| 23 |
+
cmdline="poisson accident yr_con op_75_79, vce(cluster ship)",
|
| 24 |
+
cmd="poisson",
|
| 25 |
+
predict="poisso_p",
|
| 26 |
+
estat_cmd="poisson_estat",
|
| 27 |
+
gof="poiss_g",
|
| 28 |
+
chi2type="Wald",
|
| 29 |
+
opt="moptimize",
|
| 30 |
+
vcetype="Robust",
|
| 31 |
+
clustvar="ship",
|
| 32 |
+
vce="cluster",
|
| 33 |
+
title="Poisson regression",
|
| 34 |
+
user="poiss_lf",
|
| 35 |
+
crittype="log pseudolikelihood",
|
| 36 |
+
ml_method="e2",
|
| 37 |
+
singularHmethod="m-marquardt",
|
| 38 |
+
technique="nr",
|
| 39 |
+
which="max",
|
| 40 |
+
depvar="accident",
|
| 41 |
+
properties="b V",
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
params_table = np.array([
|
| 45 |
+
-.02172061893549, .19933709357097, -.10896426022065, .91323083771076,
|
| 46 |
+
-.41241414311748, .36897290524649, np.nan, 1.9599639845401,
|
| 47 |
+
0, .22148585072024, .11093628220713, 1.9965140918162,
|
| 48 |
+
.04587799343723, .00405473301549, .43891696842499, np.nan,
|
| 49 |
+
1.9599639845401, 0, 2.2697077143215, 1.1048569901548,
|
| 50 |
+
2.054299999499, .03994666479943, .10422780555076, 4.4351876230922,
|
| 51 |
+
np.nan, 1.9599639845401, 0]).reshape(3, 9)
|
| 52 |
+
|
| 53 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 54 |
+
|
| 55 |
+
params_table_rownames = 'yr_con op_75_79 _cons'.split()
|
| 56 |
+
|
| 57 |
+
cov = np.array([
|
| 58 |
+
.03973527687332, .00976206273414, -.21171095768584, .00976206273414,
|
| 59 |
+
.01230685870994, -.06297293767114, -.21171095768584, -.06297293767114,
|
| 60 |
+
1.2207089686939]).reshape(3, 3)
|
| 61 |
+
|
| 62 |
+
cov_colnames = 'yr_con op_75_79 _cons'.split()
|
| 63 |
+
|
| 64 |
+
cov_rownames = 'yr_con op_75_79 _cons'.split()
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
results_poisson_clu = ParamsTableTestBunch(
|
| 68 |
+
params_table=params_table,
|
| 69 |
+
params_table_colnames=params_table_colnames,
|
| 70 |
+
params_table_rownames=params_table_rownames,
|
| 71 |
+
cov=cov,
|
| 72 |
+
cov_colnames=cov_colnames,
|
| 73 |
+
cov_rownames=cov_rownames,
|
| 74 |
+
**est
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
est = dict(
|
| 78 |
+
rank=3,
|
| 79 |
+
N=34,
|
| 80 |
+
ic=1,
|
| 81 |
+
k=3,
|
| 82 |
+
k_eq=1,
|
| 83 |
+
k_dv=1,
|
| 84 |
+
converged=1,
|
| 85 |
+
rc=0,
|
| 86 |
+
k_autoCns=0,
|
| 87 |
+
ll=-354.2436413025559,
|
| 88 |
+
k_eq_model=1,
|
| 89 |
+
ll_0=-356.2029100704882,
|
| 90 |
+
df_m=2,
|
| 91 |
+
chi2=.1635672212515404,
|
| 92 |
+
p=.9214713337295277,
|
| 93 |
+
r2_p=.0055004288638308,
|
| 94 |
+
cmdline="poisson accident yr_con op_75_79, vce(robust)",
|
| 95 |
+
cmd="poisson",
|
| 96 |
+
predict="poisso_p",
|
| 97 |
+
estat_cmd="poisson_estat",
|
| 98 |
+
gof="poiss_g",
|
| 99 |
+
chi2type="Wald",
|
| 100 |
+
opt="moptimize",
|
| 101 |
+
vcetype="Robust",
|
| 102 |
+
vce="robust",
|
| 103 |
+
title="Poisson regression",
|
| 104 |
+
user="poiss_lf",
|
| 105 |
+
crittype="log pseudolikelihood",
|
| 106 |
+
ml_method="e2",
|
| 107 |
+
singularHmethod="m-marquardt",
|
| 108 |
+
technique="nr",
|
| 109 |
+
which="max",
|
| 110 |
+
depvar="accident",
|
| 111 |
+
properties="b V",
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
params_table = np.array([
|
| 115 |
+
-.02172061893549, .19233713248134, -.11292993014545, .91008610728406,
|
| 116 |
+
-.39869447148862, .35525323361764, np.nan, 1.9599639845401,
|
| 117 |
+
0, .22148585072024, .55301404772037, .400506735106,
|
| 118 |
+
.68878332380143, -.8624017657564, 1.3053734671969, np.nan,
|
| 119 |
+
1.9599639845401, 0, 2.2697077143215, .66532523368388,
|
| 120 |
+
3.4114258702533, .00064624070669, .96569421829539, 3.5737212103476,
|
| 121 |
+
np.nan, 1.9599639845401, 0]).reshape(3, 9)
|
| 122 |
+
|
| 123 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 124 |
+
|
| 125 |
+
params_table_rownames = 'yr_con op_75_79 _cons'.split()
|
| 126 |
+
|
| 127 |
+
cov = np.array([
|
| 128 |
+
.03699357253114, -.01521223175214, -.09585501859714, -.01521223175214,
|
| 129 |
+
.30582453697607, -.1649339692102, -.09585501859714, -.1649339692102,
|
| 130 |
+
.44265766657651]).reshape(3, 3)
|
| 131 |
+
|
| 132 |
+
cov_colnames = 'yr_con op_75_79 _cons'.split()
|
| 133 |
+
|
| 134 |
+
cov_rownames = 'yr_con op_75_79 _cons'.split()
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
results_poisson_hc1 = ParamsTableTestBunch(
|
| 138 |
+
params_table=params_table,
|
| 139 |
+
params_table_colnames=params_table_colnames,
|
| 140 |
+
params_table_rownames=params_table_rownames,
|
| 141 |
+
cov=cov,
|
| 142 |
+
cov_colnames=cov_colnames,
|
| 143 |
+
cov_rownames=cov_rownames,
|
| 144 |
+
**est
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
est = dict(
|
| 148 |
+
rank=3,
|
| 149 |
+
N=34,
|
| 150 |
+
ic=4,
|
| 151 |
+
k=3,
|
| 152 |
+
k_eq=1,
|
| 153 |
+
k_dv=1,
|
| 154 |
+
converged=1,
|
| 155 |
+
rc=0,
|
| 156 |
+
k_autoCns=0,
|
| 157 |
+
ll=-91.28727940081573,
|
| 158 |
+
k_eq_model=1,
|
| 159 |
+
ll_0=-122.0974139280415,
|
| 160 |
+
df_m=2,
|
| 161 |
+
chi2=61.62026905445154,
|
| 162 |
+
p=4.16225408420e-14,
|
| 163 |
+
r2_p=.2523405986746273,
|
| 164 |
+
cmdline="poisson accident yr_con op_75_79, exposure(service)",
|
| 165 |
+
cmd="poisson",
|
| 166 |
+
predict="poisso_p",
|
| 167 |
+
estat_cmd="poisson_estat",
|
| 168 |
+
offset="ln(service)",
|
| 169 |
+
gof="poiss_g",
|
| 170 |
+
chi2type="LR",
|
| 171 |
+
opt="moptimize",
|
| 172 |
+
vce="oim",
|
| 173 |
+
title="Poisson regression",
|
| 174 |
+
user="poiss_lf",
|
| 175 |
+
crittype="log likelihood",
|
| 176 |
+
ml_method="e2",
|
| 177 |
+
singularHmethod="m-marquardt",
|
| 178 |
+
technique="nr",
|
| 179 |
+
which="max",
|
| 180 |
+
depvar="accident",
|
| 181 |
+
properties="b V",
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
params_table = np.array([
|
| 185 |
+
.30633819450439, .05790831365493, 5.290055523458, 1.222792336e-07,
|
| 186 |
+
.19283998533528, .4198364036735, np.nan, 1.9599639845401,
|
| 187 |
+
0, .35592229608495, .12151759298719, 2.9289775030556,
|
| 188 |
+
.00340079035234, .11775219034206, .59409240182785, np.nan,
|
| 189 |
+
1.9599639845401, 0, -6.974712802772, .13252425018256,
|
| 190 |
+
-52.629709605328, 0, -7.234455560208, -6.714970045336,
|
| 191 |
+
np.nan, 1.9599639845401, 0]).reshape(3, 9)
|
| 192 |
+
|
| 193 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 194 |
+
|
| 195 |
+
params_table_rownames = 'yr_con op_75_79 _cons'.split()
|
| 196 |
+
|
| 197 |
+
cov = np.array([
|
| 198 |
+
.00335337279036, -.00315267340017, -.00589654294427, -.00315267340017,
|
| 199 |
+
.0147665254054, -.00165060980569, -.00589654294427, -.00165060980569,
|
| 200 |
+
.01756267688645]).reshape(3, 3)
|
| 201 |
+
|
| 202 |
+
cov_colnames = 'yr_con op_75_79 _cons'.split()
|
| 203 |
+
|
| 204 |
+
cov_rownames = 'yr_con op_75_79 _cons'.split()
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
results_poisson_exposure_nonrobust = ParamsTableTestBunch(
|
| 208 |
+
params_table=params_table,
|
| 209 |
+
params_table_colnames=params_table_colnames,
|
| 210 |
+
params_table_rownames=params_table_rownames,
|
| 211 |
+
cov=cov,
|
| 212 |
+
cov_colnames=cov_colnames,
|
| 213 |
+
cov_rownames=cov_rownames,
|
| 214 |
+
**est
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
est = dict(
|
| 218 |
+
rank=3,
|
| 219 |
+
N=34,
|
| 220 |
+
ic=4,
|
| 221 |
+
k=3,
|
| 222 |
+
k_eq=1,
|
| 223 |
+
k_dv=1,
|
| 224 |
+
converged=1,
|
| 225 |
+
rc=0,
|
| 226 |
+
k_autoCns=0,
|
| 227 |
+
ll=-91.28727940081573,
|
| 228 |
+
k_eq_model=1,
|
| 229 |
+
ll_0=-122.0974139280415,
|
| 230 |
+
df_m=2,
|
| 231 |
+
chi2=15.1822804640621,
|
| 232 |
+
p=.0005049050167458,
|
| 233 |
+
r2_p=.2523405986746273,
|
| 234 |
+
cmdline="poisson accident yr_con op_75_79, exposure(service) vce(robust)", # noqa:E501
|
| 235 |
+
cmd="poisson",
|
| 236 |
+
predict="poisso_p",
|
| 237 |
+
estat_cmd="poisson_estat",
|
| 238 |
+
offset="ln(service)",
|
| 239 |
+
gof="poiss_g",
|
| 240 |
+
chi2type="Wald",
|
| 241 |
+
opt="moptimize",
|
| 242 |
+
vcetype="Robust",
|
| 243 |
+
vce="robust",
|
| 244 |
+
title="Poisson regression",
|
| 245 |
+
user="poiss_lf",
|
| 246 |
+
crittype="log pseudolikelihood",
|
| 247 |
+
ml_method="e2",
|
| 248 |
+
singularHmethod="m-marquardt",
|
| 249 |
+
technique="nr",
|
| 250 |
+
which="max",
|
| 251 |
+
depvar="accident",
|
| 252 |
+
properties="b V",
|
| 253 |
+
)
|
| 254 |
+
|
| 255 |
+
params_table = np.array([
|
| 256 |
+
.30633819450439, .09144457613957, 3.3499875819514, .00080815183366,
|
| 257 |
+
.12711011868929, .48556627031949, np.nan, 1.9599639845401,
|
| 258 |
+
0, .35592229608495, .16103531267836, 2.2102127177276,
|
| 259 |
+
.02709040275274, .04029888299621, .67154570917369, np.nan,
|
| 260 |
+
1.9599639845401, 0, -6.974712802772, .2558675415017,
|
| 261 |
+
-27.259076168227, 1.29723387e-163, -7.4762039689282, -6.4732216366159,
|
| 262 |
+
np.nan, 1.9599639845401, 0]).reshape(3, 9)
|
| 263 |
+
|
| 264 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 265 |
+
|
| 266 |
+
params_table_rownames = 'yr_con op_75_79 _cons'.split()
|
| 267 |
+
|
| 268 |
+
cov = np.array([
|
| 269 |
+
.00836211050535, .00098797681063, -.01860743122756, .00098797681063,
|
| 270 |
+
.02593237192942, -.02395236210603, -.01860743122756, -.02395236210603,
|
| 271 |
+
.06546819879413]).reshape(3, 3)
|
| 272 |
+
|
| 273 |
+
cov_colnames = 'yr_con op_75_79 _cons'.split()
|
| 274 |
+
|
| 275 |
+
cov_rownames = 'yr_con op_75_79 _cons'.split()
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
results_poisson_exposure_hc1 = ParamsTableTestBunch(
|
| 279 |
+
params_table=params_table,
|
| 280 |
+
params_table_colnames=params_table_colnames,
|
| 281 |
+
params_table_rownames=params_table_rownames,
|
| 282 |
+
cov=cov,
|
| 283 |
+
cov_colnames=cov_colnames,
|
| 284 |
+
cov_rownames=cov_rownames,
|
| 285 |
+
**est
|
| 286 |
+
)
|
| 287 |
+
|
| 288 |
+
est = dict(
|
| 289 |
+
rank=3,
|
| 290 |
+
N=34,
|
| 291 |
+
ic=4,
|
| 292 |
+
k=3,
|
| 293 |
+
k_eq=1,
|
| 294 |
+
k_dv=1,
|
| 295 |
+
converged=1,
|
| 296 |
+
rc=0,
|
| 297 |
+
k_autoCns=0,
|
| 298 |
+
N_clust=5,
|
| 299 |
+
ll=-91.28727940081573,
|
| 300 |
+
k_eq_model=1,
|
| 301 |
+
ll_0=-122.0974139280415,
|
| 302 |
+
df_m=2,
|
| 303 |
+
chi2=340.7343047354823,
|
| 304 |
+
p=1.02443835269e-74,
|
| 305 |
+
r2_p=.2523405986746273,
|
| 306 |
+
cmdline="poisson accident yr_con op_75_79, exposure(service) vce(cluster ship)", # noqa:E501
|
| 307 |
+
cmd="poisson",
|
| 308 |
+
predict="poisso_p",
|
| 309 |
+
estat_cmd="poisson_estat",
|
| 310 |
+
offset="ln(service)",
|
| 311 |
+
gof="poiss_g",
|
| 312 |
+
chi2type="Wald",
|
| 313 |
+
opt="moptimize",
|
| 314 |
+
vcetype="Robust",
|
| 315 |
+
clustvar="ship",
|
| 316 |
+
vce="cluster",
|
| 317 |
+
title="Poisson regression",
|
| 318 |
+
user="poiss_lf",
|
| 319 |
+
crittype="log pseudolikelihood",
|
| 320 |
+
ml_method="e2",
|
| 321 |
+
singularHmethod="m-marquardt",
|
| 322 |
+
technique="nr",
|
| 323 |
+
which="max",
|
| 324 |
+
depvar="accident",
|
| 325 |
+
properties="b V",
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
+
params_table = np.array([
|
| 329 |
+
.30633819450439, .03817694295902, 8.0241677504982, 1.022165435e-15,
|
| 330 |
+
.23151276126487, .38116362774391, np.nan, 1.9599639845401,
|
| 331 |
+
0, .35592229608495, .09213163536669, 3.8631930787765,
|
| 332 |
+
.00011191448109, .17534760892947, .53649698324044, np.nan,
|
| 333 |
+
1.9599639845401, 0, -6.974712802772, .0968656626603,
|
| 334 |
+
-72.003975518463, 0, -7.1645660129248, -6.7848595926192,
|
| 335 |
+
np.nan, 1.9599639845401, 0]).reshape(3, 9)
|
| 336 |
+
|
| 337 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 338 |
+
|
| 339 |
+
params_table_rownames = 'yr_con op_75_79 _cons'.split()
|
| 340 |
+
|
| 341 |
+
cov = np.array([
|
| 342 |
+
.0014574789737, -.00277745275086, .00108765624666, -.00277745275086,
|
| 343 |
+
.00848823823534, -.00469929607507, .00108765624666, -.00469929607507,
|
| 344 |
+
.00938295660262]).reshape(3, 3)
|
| 345 |
+
|
| 346 |
+
cov_colnames = 'yr_con op_75_79 _cons'.split()
|
| 347 |
+
|
| 348 |
+
cov_rownames = 'yr_con op_75_79 _cons'.split()
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
results_poisson_exposure_clu = ParamsTableTestBunch(
|
| 352 |
+
params_table=params_table,
|
| 353 |
+
params_table_colnames=params_table_colnames,
|
| 354 |
+
params_table_rownames=params_table_rownames,
|
| 355 |
+
cov=cov,
|
| 356 |
+
cov_colnames=cov_colnames,
|
| 357 |
+
cov_rownames=cov_rownames,
|
| 358 |
+
**est
|
| 359 |
+
)
|
| 360 |
+
|
| 361 |
+
est = dict(
|
| 362 |
+
rank=4,
|
| 363 |
+
N=34,
|
| 364 |
+
ic=2,
|
| 365 |
+
k=4,
|
| 366 |
+
k_eq=2,
|
| 367 |
+
k_dv=1,
|
| 368 |
+
converged=1,
|
| 369 |
+
rc=0,
|
| 370 |
+
k_autoCns=0,
|
| 371 |
+
N_clust=5,
|
| 372 |
+
ll=-109.0877965183258,
|
| 373 |
+
k_eq_model=1,
|
| 374 |
+
ll_0=-109.1684720604314,
|
| 375 |
+
rank0=2,
|
| 376 |
+
df_m=2,
|
| 377 |
+
chi2=5.472439553195301,
|
| 378 |
+
p=.0648148991694882,
|
| 379 |
+
k_aux=1,
|
| 380 |
+
alpha=2.330298308905143,
|
| 381 |
+
cmdline="nbreg accident yr_con op_75_79, vce(cluster ship)",
|
| 382 |
+
cmd="nbreg",
|
| 383 |
+
predict="nbreg_p",
|
| 384 |
+
dispers="mean",
|
| 385 |
+
diparm_opt2="noprob",
|
| 386 |
+
chi2type="Wald",
|
| 387 |
+
opt="moptimize",
|
| 388 |
+
vcetype="Robust",
|
| 389 |
+
clustvar="ship",
|
| 390 |
+
vce="cluster",
|
| 391 |
+
title="Negative binomial regression",
|
| 392 |
+
diparm1="lnalpha, exp label(",
|
| 393 |
+
user="nbreg_lf",
|
| 394 |
+
crittype="log pseudolikelihood",
|
| 395 |
+
ml_method="e2",
|
| 396 |
+
singularHmethod="m-marquardt",
|
| 397 |
+
technique="nr",
|
| 398 |
+
which="max",
|
| 399 |
+
depvar="accident",
|
| 400 |
+
properties="b V",
|
| 401 |
+
)
|
| 402 |
+
|
| 403 |
+
params_table = np.array([
|
| 404 |
+
-.03536709401845, .27216090050938, -.12994921001605, .89660661037787,
|
| 405 |
+
-.56879265701682, .49805846897992, np.nan, 1.9599639845401,
|
| 406 |
+
0, .23211570238882, .09972456245386, 2.3275680201277,
|
| 407 |
+
.01993505322091, .03665915160525, .42757225317239, np.nan,
|
| 408 |
+
1.9599639845401, 0, 2.2952623989519, 1.2335785495143,
|
| 409 |
+
1.8606536242509, .06279310688494, -.12250713019722, 4.7130319281011,
|
| 410 |
+
np.nan, 1.9599639845401, 0, .84599628895555,
|
| 411 |
+
.22483100011931, np.nan, np.nan, .40533562611357,
|
| 412 |
+
1.2866569517975, np.nan, 1.9599639845401, 0,
|
| 413 |
+
2.3302983089051, .52392329936749, np.nan, np.nan,
|
| 414 |
+
1.4998057895818, 3.6206622525444, np.nan, 1.9599639845401,
|
| 415 |
+
0]).reshape(5, 9)
|
| 416 |
+
|
| 417 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 418 |
+
|
| 419 |
+
params_table_rownames = 'yr_con op_75_79 _cons _cons alpha'.split()
|
| 420 |
+
|
| 421 |
+
cov = np.array([
|
| 422 |
+
.07407155576607, -.00421355148283, -.32663130963457, .02015715724983,
|
| 423 |
+
-.00421355148283, .00994498835661, .00992613461881, -.00714955450361,
|
| 424 |
+
-.32663130963457, .00992613461881, 1.5217160378218, -.09288283512096,
|
| 425 |
+
.02015715724983, -.00714955450361, -.09288283512096, .05054897861465
|
| 426 |
+
]).reshape(4, 4)
|
| 427 |
+
|
| 428 |
+
cov_colnames = 'yr_con op_75_79 _cons _cons'.split()
|
| 429 |
+
|
| 430 |
+
cov_rownames = 'yr_con op_75_79 _cons _cons'.split()
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
results_negbin_clu = ParamsTableTestBunch(
|
| 434 |
+
params_table=params_table,
|
| 435 |
+
params_table_colnames=params_table_colnames,
|
| 436 |
+
params_table_rownames=params_table_rownames,
|
| 437 |
+
cov=cov,
|
| 438 |
+
cov_colnames=cov_colnames,
|
| 439 |
+
cov_rownames=cov_rownames,
|
| 440 |
+
**est
|
| 441 |
+
)
|
| 442 |
+
|
| 443 |
+
est = dict(
|
| 444 |
+
rank=4,
|
| 445 |
+
N=34,
|
| 446 |
+
ic=2,
|
| 447 |
+
k=4,
|
| 448 |
+
k_eq=2,
|
| 449 |
+
k_dv=1,
|
| 450 |
+
converged=1,
|
| 451 |
+
rc=0,
|
| 452 |
+
k_autoCns=0,
|
| 453 |
+
ll=-109.0877965183258,
|
| 454 |
+
k_eq_model=1,
|
| 455 |
+
ll_0=-109.1684720604314,
|
| 456 |
+
rank0=2,
|
| 457 |
+
df_m=2,
|
| 458 |
+
chi2=.1711221347493475,
|
| 459 |
+
p=.9179970816706797,
|
| 460 |
+
r2_p=.0007390003778831,
|
| 461 |
+
k_aux=1,
|
| 462 |
+
alpha=2.330298308905143,
|
| 463 |
+
cmdline="nbreg accident yr_con op_75_79, vce(robust)",
|
| 464 |
+
cmd="nbreg",
|
| 465 |
+
predict="nbreg_p",
|
| 466 |
+
dispers="mean",
|
| 467 |
+
diparm_opt2="noprob",
|
| 468 |
+
chi2type="Wald",
|
| 469 |
+
opt="moptimize",
|
| 470 |
+
vcetype="Robust",
|
| 471 |
+
vce="robust",
|
| 472 |
+
title="Negative binomial regression",
|
| 473 |
+
diparm1="lnalpha, exp label(",
|
| 474 |
+
user="nbreg_lf",
|
| 475 |
+
crittype="log pseudolikelihood",
|
| 476 |
+
ml_method="e2",
|
| 477 |
+
singularHmethod="m-marquardt",
|
| 478 |
+
technique="nr",
|
| 479 |
+
which="max",
|
| 480 |
+
depvar="accident",
|
| 481 |
+
properties="b V",
|
| 482 |
+
)
|
| 483 |
+
|
| 484 |
+
params_table = np.array([
|
| 485 |
+
-.03536709401845, .26106873337039, -.13547043172065, .89223994079058,
|
| 486 |
+
-.5470524089139, .476318220877, np.nan, 1.9599639845401,
|
| 487 |
+
0, .23211570238882, .56245325203342, .41268443475019,
|
| 488 |
+
.67983783029986, -.87027241458412, 1.3345038193618, np.nan,
|
| 489 |
+
1.9599639845401, 0, 2.2952623989519, .76040210713867,
|
| 490 |
+
3.0184850586341, .00254041928465, .80490165519179, 3.7856231427121,
|
| 491 |
+
np.nan, 1.9599639845401, 0, .84599628895555,
|
| 492 |
+
.24005700345444, np.nan, np.nan, .37549320794823,
|
| 493 |
+
1.3164993699629, np.nan, 1.9599639845401, 0,
|
| 494 |
+
2.3302983089051, .55940442919073, np.nan, np.nan,
|
| 495 |
+
1.4557092049439, 3.7303399539165, np.nan, 1.9599639845401,
|
| 496 |
+
0]).reshape(5, 9)
|
| 497 |
+
|
| 498 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 499 |
+
|
| 500 |
+
params_table_rownames = 'yr_con op_75_79 _cons _cons alpha'.split()
|
| 501 |
+
|
| 502 |
+
cov = np.array([
|
| 503 |
+
.06815688354362, -.03840590969835, -.16217402790798, .02098165591138,
|
| 504 |
+
-.03840590969835, .31635366072297, -.11049674936104, -.02643483668568,
|
| 505 |
+
-.16217402790798, -.11049674936104, .57821136454093, -.03915049342584,
|
| 506 |
+
.02098165591138, -.02643483668568, -.03915049342584, .05762736490753
|
| 507 |
+
]).reshape(4, 4)
|
| 508 |
+
|
| 509 |
+
cov_colnames = 'yr_con op_75_79 _cons _cons'.split()
|
| 510 |
+
|
| 511 |
+
cov_rownames = 'yr_con op_75_79 _cons _cons'.split()
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
results_negbin_hc1 = ParamsTableTestBunch(
|
| 515 |
+
params_table=params_table,
|
| 516 |
+
params_table_colnames=params_table_colnames,
|
| 517 |
+
params_table_rownames=params_table_rownames,
|
| 518 |
+
cov=cov,
|
| 519 |
+
cov_colnames=cov_colnames,
|
| 520 |
+
cov_rownames=cov_rownames,
|
| 521 |
+
**est
|
| 522 |
+
)
|
| 523 |
+
|
| 524 |
+
est = dict(
|
| 525 |
+
rank=4,
|
| 526 |
+
N=34,
|
| 527 |
+
ic=4,
|
| 528 |
+
k=4,
|
| 529 |
+
k_eq=2,
|
| 530 |
+
k_dv=1,
|
| 531 |
+
converged=1,
|
| 532 |
+
rc=0,
|
| 533 |
+
k_autoCns=0,
|
| 534 |
+
ll=-82.49115612464289,
|
| 535 |
+
k_eq_model=1,
|
| 536 |
+
ll_0=-84.68893065247886,
|
| 537 |
+
rank0=2,
|
| 538 |
+
df_m=2,
|
| 539 |
+
chi2=4.39554905567195,
|
| 540 |
+
p=.1110500222994781,
|
| 541 |
+
ll_c=-91.28727940081573,
|
| 542 |
+
chi2_c=17.5922465523457,
|
| 543 |
+
r2_p=.0259511427397111,
|
| 544 |
+
k_aux=1,
|
| 545 |
+
alpha=.2457422083490335,
|
| 546 |
+
cmdline="nbreg accident yr_con op_75_79, exposure(service)",
|
| 547 |
+
cmd="nbreg",
|
| 548 |
+
predict="nbreg_p",
|
| 549 |
+
offset="ln(service)",
|
| 550 |
+
dispers="mean",
|
| 551 |
+
diparm_opt2="noprob",
|
| 552 |
+
chi2_ct="LR",
|
| 553 |
+
chi2type="LR",
|
| 554 |
+
opt="moptimize",
|
| 555 |
+
vce="oim",
|
| 556 |
+
title="Negative binomial regression",
|
| 557 |
+
diparm1="lnalpha, exp label(",
|
| 558 |
+
user="nbreg_lf",
|
| 559 |
+
crittype="log likelihood",
|
| 560 |
+
ml_method="e2",
|
| 561 |
+
singularHmethod="m-marquardt",
|
| 562 |
+
technique="nr",
|
| 563 |
+
which="max",
|
| 564 |
+
depvar="accident",
|
| 565 |
+
properties="b V",
|
| 566 |
+
)
|
| 567 |
+
|
| 568 |
+
params_table = np.array([
|
| 569 |
+
.28503762550355, .14983643534827, 1.9023251910727, .05712865433138,
|
| 570 |
+
-.00863639135093, .57871164235802, np.nan, 1.9599639845401,
|
| 571 |
+
0, .17127003537767, .27580549562862, .62098122804736,
|
| 572 |
+
.53461197443513, -.36929880279264, .71183887354798, np.nan,
|
| 573 |
+
1.9599639845401, 0, -6.5908639033905, .40391814231008,
|
| 574 |
+
-16.31732574748, 7.432080344e-60, -7.3825289150206, -5.7991988917604,
|
| 575 |
+
np.nan, 1.9599639845401, 0, -1.4034722260565,
|
| 576 |
+
.51305874839271, np.nan, np.nan, -2.4090488948595,
|
| 577 |
+
-.39789555725363, np.nan, 1.9599639845401, 0,
|
| 578 |
+
.24574220834903, .12608018984282, np.nan, np.nan,
|
| 579 |
+
.089900758997, .67173218155228, np.nan, 1.9599639845401,
|
| 580 |
+
0]).reshape(5, 9)
|
| 581 |
+
|
| 582 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 583 |
+
|
| 584 |
+
params_table_rownames = 'yr_con op_75_79 _cons _cons alpha'.split()
|
| 585 |
+
|
| 586 |
+
cov = np.array([
|
| 587 |
+
.02245095735788, -.01097939549632, -.05127649084781, .00045725833006,
|
| 588 |
+
-.01097939549632, .07606867141895, -.0197375670989, -.00926008351523,
|
| 589 |
+
-.05127649084781, -.0197375670989, .16314986568722, .02198323898312,
|
| 590 |
+
.00045725833006, -.00926008351523, .02198323898312, .26322927930229
|
| 591 |
+
]).reshape(4, 4)
|
| 592 |
+
|
| 593 |
+
cov_colnames = 'yr_con op_75_79 _cons _cons'.split()
|
| 594 |
+
|
| 595 |
+
cov_rownames = 'yr_con op_75_79 _cons _cons'.split()
|
| 596 |
+
|
| 597 |
+
|
| 598 |
+
results_negbin_exposure_nonrobust = ParamsTableTestBunch(
|
| 599 |
+
params_table=params_table,
|
| 600 |
+
params_table_colnames=params_table_colnames,
|
| 601 |
+
params_table_rownames=params_table_rownames,
|
| 602 |
+
cov=cov,
|
| 603 |
+
cov_colnames=cov_colnames,
|
| 604 |
+
cov_rownames=cov_rownames,
|
| 605 |
+
**est
|
| 606 |
+
)
|
| 607 |
+
|
| 608 |
+
est = dict(
|
| 609 |
+
rank=4,
|
| 610 |
+
N=34,
|
| 611 |
+
ic=4,
|
| 612 |
+
k=4,
|
| 613 |
+
k_eq=2,
|
| 614 |
+
k_dv=1,
|
| 615 |
+
converged=1,
|
| 616 |
+
rc=0,
|
| 617 |
+
k_autoCns=0,
|
| 618 |
+
N_clust=5,
|
| 619 |
+
ll=-82.49115612464289,
|
| 620 |
+
k_eq_model=1,
|
| 621 |
+
ll_0=-84.68893065247886,
|
| 622 |
+
rank0=2,
|
| 623 |
+
df_m=2,
|
| 624 |
+
chi2=5.473741859983782,
|
| 625 |
+
p=.0647727084656973,
|
| 626 |
+
k_aux=1,
|
| 627 |
+
alpha=.2457422083490335,
|
| 628 |
+
cmdline="nbreg accident yr_con op_75_79, exposure(service) vce(cluster ship)", # noqa:E501
|
| 629 |
+
cmd="nbreg",
|
| 630 |
+
predict="nbreg_p",
|
| 631 |
+
offset="ln(service)",
|
| 632 |
+
dispers="mean",
|
| 633 |
+
diparm_opt2="noprob",
|
| 634 |
+
chi2type="Wald",
|
| 635 |
+
opt="moptimize",
|
| 636 |
+
vcetype="Robust",
|
| 637 |
+
clustvar="ship",
|
| 638 |
+
vce="cluster",
|
| 639 |
+
title="Negative binomial regression",
|
| 640 |
+
diparm1="lnalpha, exp label(",
|
| 641 |
+
user="nbreg_lf",
|
| 642 |
+
crittype="log pseudolikelihood",
|
| 643 |
+
ml_method="e2",
|
| 644 |
+
singularHmethod="m-marquardt",
|
| 645 |
+
technique="nr",
|
| 646 |
+
which="max",
|
| 647 |
+
depvar="accident",
|
| 648 |
+
properties="b V",
|
| 649 |
+
)
|
| 650 |
+
|
| 651 |
+
params_table = np.array([
|
| 652 |
+
.28503762550355, .14270989695062, 1.9973220610073, .04579020833966,
|
| 653 |
+
.00533136724292, .56474388376418, np.nan, 1.9599639845401,
|
| 654 |
+
0, .17127003537767, .17997186802799, .95164892854829,
|
| 655 |
+
.34127505843023, -.18146834418759, .52400841494293, np.nan,
|
| 656 |
+
1.9599639845401, 0, -6.5908639033905, .62542746996715,
|
| 657 |
+
-10.538174640357, 5.760612980e-26, -7.8166792194681, -5.3650485873129,
|
| 658 |
+
np.nan, 1.9599639845401, 0, -1.4034722260565,
|
| 659 |
+
.86579403765571, np.nan, np.nan, -3.1003973578913,
|
| 660 |
+
.29345290577817, np.nan, 1.9599639845401, 0,
|
| 661 |
+
.24574220834903, .21276213878894, np.nan, np.nan,
|
| 662 |
+
.0450313052935, 1.3410500222158, np.nan, 1.9599639845401,
|
| 663 |
+
0]).reshape(5, 9)
|
| 664 |
+
|
| 665 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 666 |
+
|
| 667 |
+
params_table_rownames = 'yr_con op_75_79 _cons _cons alpha'.split()
|
| 668 |
+
|
| 669 |
+
cov = np.array([
|
| 670 |
+
.02036611468766, -.00330004038514, -.08114367170947, -.07133030733881,
|
| 671 |
+
-.00330004038514, .03238987328148, -.03020509748676, -.09492663454187,
|
| 672 |
+
-.08114367170947, -.03020509748676, .39115952018952, .43276143586693,
|
| 673 |
+
-.07133030733881, -.09492663454187, .43276143586693, .74959931564018
|
| 674 |
+
]).reshape(4, 4)
|
| 675 |
+
|
| 676 |
+
cov_colnames = 'yr_con op_75_79 _cons _cons'.split()
|
| 677 |
+
|
| 678 |
+
cov_rownames = 'yr_con op_75_79 _cons _cons'.split()
|
| 679 |
+
|
| 680 |
+
|
| 681 |
+
results_negbin_exposure_clu = ParamsTableTestBunch(
|
| 682 |
+
params_table=params_table,
|
| 683 |
+
params_table_colnames=params_table_colnames,
|
| 684 |
+
params_table_rownames=params_table_rownames,
|
| 685 |
+
cov=cov,
|
| 686 |
+
cov_colnames=cov_colnames,
|
| 687 |
+
cov_rownames=cov_rownames,
|
| 688 |
+
**est
|
| 689 |
+
)
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_discrete.py
ADDED
|
@@ -0,0 +1,1257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Test Results for discrete models from Stata
|
| 3 |
+
"""
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Namespace:
|
| 10 |
+
pass
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Discrete Model Tests
|
| 14 |
+
# Note that there is a slight refactor of the classes, so that one dataset
|
| 15 |
+
# might be used for more than one model
|
| 16 |
+
|
| 17 |
+
cur_dir = os.path.abspath(os.path.dirname(__file__))
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class Anes:
|
| 21 |
+
def __init__(self):
|
| 22 |
+
"""r
|
| 23 |
+
Results are from Stata 11 (checked vs R nnet package).
|
| 24 |
+
"""
|
| 25 |
+
self.nobs = 944
|
| 26 |
+
|
| 27 |
+
def mnlogit_basezero():
|
| 28 |
+
obj = Namespace()
|
| 29 |
+
obj.nobs = 944
|
| 30 |
+
params = [
|
| 31 |
+
-.01153598, .29771435, -.024945, .08249144, .00519655,
|
| 32 |
+
-.37340167, -.08875065, .39166864, -.02289784, .18104276,
|
| 33 |
+
.04787398, -2.2509132, -.1059667, .57345051, -.01485121,
|
| 34 |
+
-.00715242, .05757516, -3.6655835, -.0915567, 1.2787718,
|
| 35 |
+
-.00868135, .19982796, .08449838, -7.6138431, -.0932846,
|
| 36 |
+
1.3469616, -.01790407, .21693885, .08095841, -7.0604782,
|
| 37 |
+
-.14088069, 2.0700801, -.00943265, .3219257, .10889408,
|
| 38 |
+
-12.105751]
|
| 39 |
+
obj.params = np.reshape(params, (6, -1), order='F')
|
| 40 |
+
bse = [
|
| 41 |
+
.0342823657, .093626795, .0065248584, .0735865799,
|
| 42 |
+
.0176336937, .6298376313, .0391615553, .1082386919,
|
| 43 |
+
.0079144618, .0852893563, .0222809297, .7631899491,
|
| 44 |
+
.0570382292, .1585481337, .0113313133, .1262913234,
|
| 45 |
+
.0336142088, 1.156541492, .0437902764, .1288965854,
|
| 46 |
+
.0084187486, .0941250559, .0261963632, .9575809602,
|
| 47 |
+
.0393516553, .1171860107, .0076110152, .0850070091,
|
| 48 |
+
.0229760791, .8443638283, .042138047, .1434089089,
|
| 49 |
+
.0081338625, .0910979921, .025300888, 1.059954821]
|
| 50 |
+
obj.bse = np.reshape(bse, (6, -1), order='F')
|
| 51 |
+
obj.yhat = np.loadtxt(os.path.join(cur_dir, 'yhat_mnlogit.csv'))
|
| 52 |
+
obj.phat = np.loadtxt(os.path.join(cur_dir, 'phat_mnlogit.csv'))
|
| 53 |
+
obj.cov_params = None
|
| 54 |
+
obj.llf = -1461.922747312
|
| 55 |
+
obj.llnull = -1750.34670999
|
| 56 |
+
obj.llr = 576.8479253554
|
| 57 |
+
obj.llr_pvalue = 1.8223179e-102
|
| 58 |
+
obj.prsquared = .1647810465387
|
| 59 |
+
obj.df_model = 30
|
| 60 |
+
obj.df_resid = 944 - 36
|
| 61 |
+
obj.J = 7
|
| 62 |
+
obj.K = 6
|
| 63 |
+
obj.aic = 2995.84549462
|
| 64 |
+
obj.bic = 3170.45003661
|
| 65 |
+
z = [
|
| 66 |
+
-.3364988051, 3.179798597, -3.823070772, 1.121012042,
|
| 67 |
+
.2946945327, -.5928538661, -2.266269864, 3.618564069,
|
| 68 |
+
-2.893164162, 2.122688754, 2.148652536, -2.949348555,
|
| 69 |
+
-1.857818873, 3.616885888, -1.310634214, -.0566342868,
|
| 70 |
+
1.712822091, -3.169435381, -2.090799808, 9.920912816,
|
| 71 |
+
-1.031191864, 2.123004903, 3.225576554, -7.951122047,
|
| 72 |
+
-2.370538224, 11.49421878, -2.352389066, 2.552011323,
|
| 73 |
+
3.523595639, -8.361890935, -3.34331327, 14.43480847,
|
| 74 |
+
-1.159676452, 3.533839715, 4.303962885, -11.42100649]
|
| 75 |
+
obj.z = np.reshape(z, (6, -1), order='F')
|
| 76 |
+
pvalues = [
|
| 77 |
+
0.7364947525, 0.0014737744, 0.0001317999, 0.2622827367,
|
| 78 |
+
0.7682272401, 0.5532789548, 0.0234348654, 0.0002962422,
|
| 79 |
+
0.0038138191, 0.0337799420, 0.0316619538, 0.0031844460,
|
| 80 |
+
0.0631947400, 0.0002981687, 0.1899813744, 0.9548365214,
|
| 81 |
+
0.0867452747, 0.0015273542, 0.0365460134, 3.37654e-23,
|
| 82 |
+
0.3024508550, 0.0337534410, 0.0012571921, 1.84830e-15,
|
| 83 |
+
0.0177622072, 1.41051e-30, 0.0186532528, 0.0107103038,
|
| 84 |
+
0.0004257334, 6.17209e-17, 0.0008278439, 3.12513e-47,
|
| 85 |
+
0.2461805610, 0.0004095694, 0.0000167770, 3.28408e-30]
|
| 86 |
+
obj.pvalues = np.reshape(pvalues, (6, -1), order='F')
|
| 87 |
+
conf_int = [
|
| 88 |
+
[[-0.0787282, 0.0556562],
|
| 89 |
+
[0.1142092, 0.4812195],
|
| 90 |
+
[-0.0377335, -0.0121565],
|
| 91 |
+
[-0.0617356, 0.2267185],
|
| 92 |
+
[-0.0293649, 0.0397580],
|
| 93 |
+
[-1.6078610, 0.8610574]],
|
| 94 |
+
[[-0.1655059, -0.0119954],
|
| 95 |
+
[0.1795247, 0.6038126],
|
| 96 |
+
[-0.0384099, -0.0073858],
|
| 97 |
+
[0.0138787, 0.3482068],
|
| 98 |
+
[0.0042042, 0.0915438],
|
| 99 |
+
[-3.7467380, -0.7550884]],
|
| 100 |
+
[[-0.2177596, 0.0058262],
|
| 101 |
+
[0.2627019, 0.8841991],
|
| 102 |
+
[-0.0370602, 0.0073578],
|
| 103 |
+
[-0.2546789, 0.2403740],
|
| 104 |
+
[-0.0083075, 0.1234578],
|
| 105 |
+
[-5.9323630, -1.3988040]],
|
| 106 |
+
[[-0.1773841, -0.0057293],
|
| 107 |
+
[1.0261390, 1.5314040],
|
| 108 |
+
[-0.0251818, 0.0078191],
|
| 109 |
+
[0.0153462, 0.3843097],
|
| 110 |
+
[0.0331544, 0.1358423],
|
| 111 |
+
[-9.4906670, -5.7370190]],
|
| 112 |
+
[[-0.1704124, -0.0161568],
|
| 113 |
+
[1.1172810, 1.5766420],
|
| 114 |
+
[-0.0328214, -0.0029868],
|
| 115 |
+
[0.0503282, 0.3835495],
|
| 116 |
+
[0.0359261, 0.1259907],
|
| 117 |
+
[-8.7154010, -5.4055560]],
|
| 118 |
+
[[-0.2234697, -0.0582916],
|
| 119 |
+
[1.7890040, 2.3511560],
|
| 120 |
+
[-0.0253747, 0.0065094],
|
| 121 |
+
[0.1433769, 0.5004745],
|
| 122 |
+
[0.0593053, 0.1584829],
|
| 123 |
+
[-14.1832200, -10.0282800]]]
|
| 124 |
+
obj.conf_int = np.asarray(conf_int)
|
| 125 |
+
|
| 126 |
+
# margins, dydx(*) predict(outcome(#))
|
| 127 |
+
obj.margeff_dydx_overall = np.array([
|
| 128 |
+
[0.00868085993550, -0.09779854015456, 0.00272556969847,
|
| 129 |
+
-0.01992376579372, -0.00603133322764],
|
| 130 |
+
[0.00699386733148, -0.05022430802614, -0.00211003909752,
|
| 131 |
+
-0.00536980000265, -0.00554366741814],
|
| 132 |
+
[-0.00391040848820, -0.02824717135857, -0.00100551299310,
|
| 133 |
+
0.00664337806861, 0.00097987356999],
|
| 134 |
+
[-0.00182580888015, -0.00573744730031, -0.00004249256428,
|
| 135 |
+
-0.00546669558488, 0.00054101121854],
|
| 136 |
+
[-0.00098558129923, 0.01985550937033, 0.00047972250012,
|
| 137 |
+
0.00172605778905, 0.00211291403209],
|
| 138 |
+
[-0.00153469551647, 0.03755346502013, -0.00068531143399,
|
| 139 |
+
0.00472471794347, 0.00254733486106],
|
| 140 |
+
[-0.00741820702809, 0.12459834487569, 0.00063806819375,
|
| 141 |
+
0.01766610701188, 0.00539385283759]
|
| 142 |
+
]).T
|
| 143 |
+
obj.margeff_dydx_overall_se = np.array([
|
| 144 |
+
[.0038581061, .0080471125, .0007068488, .0082318967, .0020261706],
|
| 145 |
+
[.003904378, .0073600286, .000756431, .0084381578, .0020482238],
|
| 146 |
+
[.003137126, .0056813182, .0006601377, .0068932588, .0018481806],
|
| 147 |
+
[.0019427783, .0031904763, .0003865411, .004361789, .0011523221],
|
| 148 |
+
[.0029863227, .0054076092, .0005886612, .0064426365, .0018886818],
|
| 149 |
+
[.0035806552, .0069497362, .000722511, .0078287717, .0022352393],
|
| 150 |
+
[.0033641608, .008376629, .0006774697, .0073505286, .0021660086]
|
| 151 |
+
]).T
|
| 152 |
+
|
| 153 |
+
obj.margeff_dydx_mean = np.array([
|
| 154 |
+
[0.01149887431225, -0.13784207091973, 0.00273313385873,
|
| 155 |
+
-0.02542974260540, -0.00855346837482],
|
| 156 |
+
[0.01114846831102, -0.09864273512889, -0.00222435063712,
|
| 157 |
+
-0.01214617126321, -0.00903581444579],
|
| 158 |
+
[-0.00381702868421, -0.05132297961269, -0.00116763216994,
|
| 159 |
+
0.00624203027060, 0.00021912081810],
|
| 160 |
+
[-0.00233455327258, -0.00928554037343, -0.00000206561214,
|
| 161 |
+
-0.00775415690571, 0.00060004460394],
|
| 162 |
+
[-0.00352579921274, 0.06412187169362, 0.00073938948643,
|
| 163 |
+
0.00747778063206, 0.00459965010365],
|
| 164 |
+
[-0.00574308219449, 0.11126535089794, -0.00057337915464,
|
| 165 |
+
0.01467424346725, 0.00641760846097],
|
| 166 |
+
[-0.00722687818452, 0.12170608820238, 0.00049490419675,
|
| 167 |
+
0.01693601418978, 0.00575285798725]]).T
|
| 168 |
+
obj.margeff_dydx_mean_se = np.array([
|
| 169 |
+
[.0043729758, .0110343353, .0008149907, .0092551389, .0023752071],
|
| 170 |
+
[.004875051, .0124746358, .0009613152, .0105665812, .0026524426],
|
| 171 |
+
[.0040718954, .0103613938, .0008554615, .0089931297, .0024374625],
|
| 172 |
+
[.0026430804, .0070845916, .0005364369, .0057654258, .0015988838],
|
| 173 |
+
[.0037798151, .0103849291, .0007393481, .0082021938, .0023489261],
|
| 174 |
+
[.0045654631, .0130329403, .0009128134, .0100053262, .0028048602],
|
| 175 |
+
[.0027682389, .0113292677, .0005325113, .0061289353, .0017330763]
|
| 176 |
+
]).T
|
| 177 |
+
|
| 178 |
+
obj.margeff_dydx_dummy_overall = np.array([
|
| 179 |
+
[0.00549149574321, -0.05348235321783, 0.00298963549049,
|
| 180 |
+
-0.01479461677951, -0.00332167981255, -0.26502967041815],
|
| 181 |
+
[0.00345677928276, -0.00950322030929, -0.00189456107189,
|
| 182 |
+
0.00033893662061, -0.00314690167350, -0.21040878091828],
|
| 183 |
+
[-0.00645089013284, 0.00401746940204, -0.00083948249351,
|
| 184 |
+
0.01114202556889, 0.00277069841472, -0.15967397659686],
|
| 185 |
+
[-0.00215436802341, -0.00366545199370, -0.00000002297812,
|
| 186 |
+
-0.00457368049644, 0.00065303026027, -0.00094772782001],
|
| 187 |
+
[0.00058038428936, -0.00369080100124, 0.00035948233235,
|
| 188 |
+
-0.00018863693013, 0.00079351293461, 0.12640653743480],
|
| 189 |
+
[0.00217597030999, -0.01279456622853, -0.00091882392767,
|
| 190 |
+
0.00001651192759, -0.00037998290789, 0.27175070356670],
|
| 191 |
+
[-0.00309932483642, 0.07911868907484, 0.00030378521102,
|
| 192 |
+
0.00805941631677, 0.00263129901425, 0.23790291475181]]).T
|
| 193 |
+
obj.margeff_dydx_dummy_overall_se = np.array([
|
| 194 |
+
[.0037314453, .0094102332, .000688838, .0079744554, .0019365971,
|
| 195 |
+
.0243914836],
|
| 196 |
+
[.0038215262, .0095938828, .0007410885, .008259353, .0019984087,
|
| 197 |
+
.0317628806],
|
| 198 |
+
[.0031045718, .00785814, .0006504353, .0067892866, .0018060332,
|
| 199 |
+
0.0262803561],
|
| 200 |
+
[.0019756086, .0051031194, .0003862449, .0043621673, .0011796953,
|
| 201 |
+
.0219999601],
|
| 202 |
+
[.0029714074, .0081732018, .0005715192, .0064742872, .0019130195,
|
| 203 |
+
.0331694192],
|
| 204 |
+
[.0034443743, .0097296187, .0006774867, .0075996454, .0021993881,
|
| 205 |
+
.038600835],
|
| 206 |
+
[.0032003518, .0098741227, .0006335772, .0070902078, .0021003227,
|
| 207 |
+
.0255727127]]).T
|
| 208 |
+
|
| 209 |
+
obj.margeff_eydx_dummy_overall = np.array([
|
| 210 |
+
[.03939188, -.65758371, .01750922, -.12131806, -.03613241,
|
| 211 |
+
-3.2132513],
|
| 212 |
+
[.02752366, -.383165, -.00830021, -.03652935, -.03286046,
|
| 213 |
+
-1.8741853],
|
| 214 |
+
[-.05006681, -.2719659, -.00626481, .06525323, .01012554,
|
| 215 |
+
-2.0058029],
|
| 216 |
+
[-.05239558, -.22549142, .00025015, -.13104416, .01114517,
|
| 217 |
+
-.27052009],
|
| 218 |
+
[-.00296374, .25627809, .00140513, .03358712, .02296041,
|
| 219 |
+
1.3302701],
|
| 220 |
+
[.00328283, .2800168, -.0083912, .04332782, .01575863,
|
| 221 |
+
1.8441023],
|
| 222 |
+
[-.03257068, .98346111, -.00122118, .10847807, .0406456,
|
| 223 |
+
2.9119099]]).T
|
| 224 |
+
|
| 225 |
+
obj.margeff_eydx_dummy_overall_se = np.array([
|
| 226 |
+
[.0272085605, .0777760394, .0052427952, .0584011446, .0148618012,
|
| 227 |
+
.5796921383],
|
| 228 |
+
[.0262290023, .0724479385, .005174736, .0567743614, .0144447083,
|
| 229 |
+
.3015738731],
|
| 230 |
+
[.0321415498, .0895589422, .0067480662, .0701460193, .0190451865,
|
| 231 |
+
.3904138447],
|
| 232 |
+
[.0511305319, .1420904068, .0102342163, .1129912244, .0308618233,
|
| 233 |
+
.3693799595],
|
| 234 |
+
[.0340186217, .0991711703, .0065812158, .0737441012, .0212966336,
|
| 235 |
+
.2346982385],
|
| 236 |
+
[.0289250212, .0840662279, .0056743561, .0631772185, .0177278895,
|
| 237 |
+
.2089516714],
|
| 238 |
+
[.0318251305, .1085637405, .0062400589, .0699123044, .0201045606,
|
| 239 |
+
.3727166284]]).T
|
| 240 |
+
|
| 241 |
+
# taken from gretl
|
| 242 |
+
obj.resid = np.loadtxt(os.path.join(cur_dir, 'mnlogit_resid.csv'),
|
| 243 |
+
delimiter=",")
|
| 244 |
+
return obj
|
| 245 |
+
|
| 246 |
+
mnlogit_basezero = mnlogit_basezero()
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
class DiscreteL1:
|
| 250 |
+
def __init__(self):
|
| 251 |
+
"""
|
| 252 |
+
Special results for L1 models
|
| 253 |
+
Uses the Spector data and a script to generate the baseline results
|
| 254 |
+
"""
|
| 255 |
+
pass
|
| 256 |
+
|
| 257 |
+
def logit():
|
| 258 |
+
"""
|
| 259 |
+
Results generated with:
|
| 260 |
+
data = sm.datasets.spector.load()
|
| 261 |
+
data.exog = sm.add_constant(data.exog, prepend=True)
|
| 262 |
+
alpha = 3 * np.array([0, 1, 1, 1])
|
| 263 |
+
res2 = sm.Logit(data.endog, data.exog).fit_regularized(
|
| 264 |
+
method="l1", alpha=alpha, disp=0, trim_mode='size',
|
| 265 |
+
size_trim_tol=1e-5, acc=1e-10, maxiter=1000)
|
| 266 |
+
"""
|
| 267 |
+
obj = Namespace()
|
| 268 |
+
nan = np.nan
|
| 269 |
+
obj.params = [-4.10271595, 0., 0.15493781, 0.]
|
| 270 |
+
obj.conf_int = [
|
| 271 |
+
[-9.15205122, 0.94661932],
|
| 272 |
+
[nan, nan],
|
| 273 |
+
[-0.06539482, 0.37527044],
|
| 274 |
+
[nan, nan]]
|
| 275 |
+
obj.bse = [2.5762388, nan, 0.11241668, nan]
|
| 276 |
+
obj.nnz_params = 2
|
| 277 |
+
obj.aic = 42.091439368583671
|
| 278 |
+
obj.bic = 45.022911174183122
|
| 279 |
+
obj.cov_params = [
|
| 280 |
+
[6.63700638, nan, -0.28636261, nan],
|
| 281 |
+
[nan, nan, nan, nan],
|
| 282 |
+
[-0.28636261, nan, 0.01263751, nan],
|
| 283 |
+
[nan, nan, nan, nan]]
|
| 284 |
+
return obj
|
| 285 |
+
|
| 286 |
+
logit = logit()
|
| 287 |
+
|
| 288 |
+
def sweep():
|
| 289 |
+
"""
|
| 290 |
+
Results generated with
|
| 291 |
+
params = np.zeros((3, 4))
|
| 292 |
+
alphas = np.array(
|
| 293 |
+
[[0.1, 0.1, 0.1, 0.1],
|
| 294 |
+
[0.4, 0.4, 0.5, 0.5], [0.5, 0.5, 1, 1]])
|
| 295 |
+
model = sm.Logit(data.endog, data.exog)
|
| 296 |
+
for i in range(3):
|
| 297 |
+
alpha = alphas[i, :]
|
| 298 |
+
res2 = model.fit_regularized(method="l1", alpha=alpha,
|
| 299 |
+
disp=0, acc=1e-10,
|
| 300 |
+
maxiter=1000, trim_mode='off')
|
| 301 |
+
params[i, :] = res2.params
|
| 302 |
+
print(params)
|
| 303 |
+
"""
|
| 304 |
+
obj = Namespace()
|
| 305 |
+
obj.params = [
|
| 306 |
+
[-10.37593611, 2.27080968, 0.06670638, 2.05723691],
|
| 307 |
+
[-5.32670811, 1.18216019, 0.01402395, 1.45178712],
|
| 308 |
+
[-3.92630318, 0.90126958, -0., 1.09498178]]
|
| 309 |
+
return obj
|
| 310 |
+
|
| 311 |
+
sweep = sweep()
|
| 312 |
+
|
| 313 |
+
def probit():
|
| 314 |
+
"""
|
| 315 |
+
Results generated with
|
| 316 |
+
data = sm.datasets.spector.load()
|
| 317 |
+
data.exog = sm.add_constant(data.exog, prepend=True)
|
| 318 |
+
alpha = np.array([0.1, 0.2, 0.3, 10])
|
| 319 |
+
res2 = sm.Probit(data.endog, data.exog).fit_regularized(
|
| 320 |
+
method="l1", alpha=alpha, disp=0, trim_mode='auto',
|
| 321 |
+
auto_trim_tol=0.02, acc=1e-10, maxiter=1000)
|
| 322 |
+
"""
|
| 323 |
+
obj = Namespace()
|
| 324 |
+
nan = np.nan
|
| 325 |
+
obj.params = [-5.40476992, 1.25018458, 0.04744558, 0.]
|
| 326 |
+
obj.conf_int = [
|
| 327 |
+
[-9.44077951, -1.36876033],
|
| 328 |
+
[0.03716721, 2.46320194],
|
| 329 |
+
[-0.09727571, 0.19216687],
|
| 330 |
+
[np.nan, np.nan]]
|
| 331 |
+
obj.bse = [2.05922641, 0.61889778, 0.07383875, np.nan]
|
| 332 |
+
obj.nnz_params = 3
|
| 333 |
+
obj.aic = 38.399773877542927
|
| 334 |
+
obj.bic = 42.796981585942106
|
| 335 |
+
obj.cov_params = [
|
| 336 |
+
[4.24041339, -0.83432592, -0.06827915, nan],
|
| 337 |
+
[-0.83432592, 0.38303447, -0.01700249, nan],
|
| 338 |
+
[-0.06827915, -0.01700249, 0.00545216, nan],
|
| 339 |
+
[nan, nan, nan, nan]]
|
| 340 |
+
return obj
|
| 341 |
+
|
| 342 |
+
probit = probit()
|
| 343 |
+
|
| 344 |
+
def mnlogit():
|
| 345 |
+
"""
|
| 346 |
+
Results generated with
|
| 347 |
+
anes_data = sm.datasets.anes96.load()
|
| 348 |
+
anes_exog = anes_data.exog
|
| 349 |
+
anes_exog = sm.add_constant(anes_exog, prepend=False)
|
| 350 |
+
mlogit_mod = sm.MNLogit(anes_data.endog, anes_exog)
|
| 351 |
+
|
| 352 |
+
alpha = 10 * np.ones((mlogit_mod.J - 1, mlogit_mod.K))
|
| 353 |
+
alpha[-1, :] = 0
|
| 354 |
+
mlogit_l1_res = mlogit_mod.fit_regularized(
|
| 355 |
+
method='l1', alpha=alpha, trim_mode='auto', auto_trim_tol=0.02,
|
| 356 |
+
acc=1e-10)
|
| 357 |
+
"""
|
| 358 |
+
obj = Namespace()
|
| 359 |
+
obj.params = [
|
| 360 |
+
[0.00100163, -0.05864195, -0.06147822, -0.04769671, -0.05222987,
|
| 361 |
+
-0.09522432],
|
| 362 |
+
[0., 0.03186139, 0.12048999, 0.83211915, 0.92330292,
|
| 363 |
+
1.5680646],
|
| 364 |
+
[-0.0218185, -0.01988066, -0.00808564, -0.00487463, -0.01400173,
|
| 365 |
+
-0.00562079],
|
| 366 |
+
[0., 0.03306875, 0., 0.02362861, 0.05486435,
|
| 367 |
+
0.14656966],
|
| 368 |
+
[0., 0.04448213, 0.03252651, 0.07661761, 0.07265266,
|
| 369 |
+
0.0967758],
|
| 370 |
+
[0.90993803, -0.50081247, -2.08285102, -5.26132955, -4.86783179,
|
| 371 |
+
-9.31537963]]
|
| 372 |
+
obj.conf_int = [
|
| 373 |
+
[[-0.0646223, 0.06662556],
|
| 374 |
+
[np.nan, np.nan],
|
| 375 |
+
[-0.03405931, -0.00957768],
|
| 376 |
+
[np.nan, np.nan],
|
| 377 |
+
[np.nan, np.nan],
|
| 378 |
+
[0.26697895, 1.55289711]],
|
| 379 |
+
|
| 380 |
+
[[-0.1337913, 0.01650741],
|
| 381 |
+
[-0.14477255, 0.20849532],
|
| 382 |
+
[-0.03500303, -0.00475829],
|
| 383 |
+
[-0.11406121, 0.18019871],
|
| 384 |
+
[0.00479741, 0.08416684],
|
| 385 |
+
[-1.84626136, 0.84463642]],
|
| 386 |
+
|
| 387 |
+
[[-0.17237962, 0.04942317],
|
| 388 |
+
[-0.15146029, 0.39244026],
|
| 389 |
+
[-0.02947379, 0.01330252],
|
| 390 |
+
[np.nan, np.nan],
|
| 391 |
+
[-0.02501483, 0.09006785],
|
| 392 |
+
[-3.90379391, -0.26190812]],
|
| 393 |
+
|
| 394 |
+
[[-0.12938296, 0.03398954],
|
| 395 |
+
[0.62612955, 1.03810876],
|
| 396 |
+
[-0.02046322, 0.01071395],
|
| 397 |
+
[-0.13738534, 0.18464256],
|
| 398 |
+
[0.03017236, 0.12306286],
|
| 399 |
+
[-6.91227465, -3.61038444]],
|
| 400 |
+
|
| 401 |
+
[[-0.12469773, 0.02023799],
|
| 402 |
+
[0.742564, 1.10404183],
|
| 403 |
+
[-0.02791975, -0.00008371],
|
| 404 |
+
[-0.08491561, 0.19464431],
|
| 405 |
+
[0.0332926, 0.11201273],
|
| 406 |
+
[-6.29331126, -3.44235233]],
|
| 407 |
+
|
| 408 |
+
[[-0.17165567, -0.01879296],
|
| 409 |
+
[1.33994079, 1.79618841],
|
| 410 |
+
[-0.02027503, 0.00903345],
|
| 411 |
+
[-0.00267819, 0.29581751],
|
| 412 |
+
[0.05343135, 0.14012026],
|
| 413 |
+
[-11.10419107, -7.52656819]]]
|
| 414 |
+
|
| 415 |
+
obj.bse = [
|
| 416 |
+
[0.03348221, 0.03834221, 0.05658338, 0.04167742, 0.03697408,
|
| 417 |
+
0.03899631],
|
| 418 |
+
[np.nan, 0.09012101, 0.13875269, 0.10509867, 0.09221543,
|
| 419 |
+
0.11639184],
|
| 420 |
+
[0.00624543, 0.00771564, 0.01091253, 0.00795351, 0.00710116,
|
| 421 |
+
0.00747679],
|
| 422 |
+
[np.nan, 0.07506769, np.nan, 0.08215148, 0.07131762,
|
| 423 |
+
0.07614826],
|
| 424 |
+
[np.nan, 0.02024768, 0.02935837, 0.02369699, 0.02008204,
|
| 425 |
+
0.02211492],
|
| 426 |
+
[0.32804638, 0.68646613, 0.92906957, 0.84233441, 0.72729881,
|
| 427 |
+
0.91267567]]
|
| 428 |
+
|
| 429 |
+
obj.nnz_params = 32
|
| 430 |
+
obj.aic = 3019.4391360294126
|
| 431 |
+
obj.bic = 3174.6431733460686
|
| 432 |
+
return obj
|
| 433 |
+
|
| 434 |
+
mnlogit = mnlogit()
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
class Spector:
|
| 438 |
+
"""
|
| 439 |
+
Results are from Stata 11
|
| 440 |
+
"""
|
| 441 |
+
def __init__(self):
|
| 442 |
+
self.nobs = 32
|
| 443 |
+
|
| 444 |
+
def logit():
|
| 445 |
+
obj = Namespace()
|
| 446 |
+
obj.nobs = 32
|
| 447 |
+
obj.params = [2.82611297201, .0951576702557, 2.37868772835,
|
| 448 |
+
-13.0213483201]
|
| 449 |
+
obj.cov_params = [
|
| 450 |
+
[1.59502033639, -.036920566629, .427615725153, -4.57347950298],
|
| 451 |
+
[-.036920566629, .0200375937069, .0149126464275, -.346255757562],
|
| 452 |
+
[.427615725153, .0149126464275, 1.13329715236, -2.35916128427],
|
| 453 |
+
[-4.57347950298, -.346255757562, -2.35916128427, 24.3179625937]]
|
| 454 |
+
obj.bse = [1.26294114526, .141554207662, 1.06456430165, 4.93132462871]
|
| 455 |
+
|
| 456 |
+
obj.resid_pearson = [
|
| 457 |
+
-.1652382, -.2515266, -.4800059, -.1630655,
|
| 458 |
+
.8687437, -.1900454, -.165002, -.2331563,
|
| 459 |
+
-.3535812, .6647838, -.1583799, -.4843181,
|
| 460 |
+
-.689527, 2.043449, -.7516119, -.1764176,
|
| 461 |
+
-.2380445, -.2003426, -1.199277, .7164842,
|
| 462 |
+
-.255713, .3242821, -.5646816, -2.400189,
|
| 463 |
+
.4392082, 1.038473, .75747, -.6659256,
|
| 464 |
+
.4336657, .2404583, -1.060033, 2.829577]
|
| 465 |
+
|
| 466 |
+
obj.resid_dev = [
|
| 467 |
+
-.2321102, -.3502712, -.6439626, -.2290982,
|
| 468 |
+
1.060478, -.2663844, -.2317827, -.3253788, -.4853875,
|
| 469 |
+
.8555557, -.2225972, -.6491808, -.8819993, 1.813269,
|
| 470 |
+
-.9463985, -.247583, -.3320177, -.2805444, -1.335131,
|
| 471 |
+
.9103027, -.3559217, .4471892, -.744005, -1.955074,
|
| 472 |
+
.5939538, 1.209638, .952332, -.8567857, .5870719, .335292,
|
| 473 |
+
-1.227311, 2.096639]
|
| 474 |
+
|
| 475 |
+
# from gretl
|
| 476 |
+
obj.resid_generalized = [
|
| 477 |
+
-0.026578, -0.059501, -0.187260,
|
| 478 |
+
-0.025902, 0.430107, -0.034858, -0.026504, -0.051559,
|
| 479 |
+
-0.111127, 0.306489, -0.024470, -0.189997, -0.322240,
|
| 480 |
+
0.806789, -0.360990, -0.030184, -0.053626, -0.038588,
|
| 481 |
+
-0.589872, 0.339214, -0.061376, 0.095153, -0.241772,
|
| 482 |
+
-0.852091, 0.161709, 0.518867, 0.364579, -0.307219,
|
| 483 |
+
0.158296, 0.054660, -0.529117, 0.888969]
|
| 484 |
+
|
| 485 |
+
obj.phat = np.array([
|
| 486 |
+
.02657799236476,
|
| 487 |
+
.05950126051903,
|
| 488 |
+
.18725991249084,
|
| 489 |
+
.02590163610876,
|
| 490 |
+
.56989300251007,
|
| 491 |
+
.03485824912786,
|
| 492 |
+
.02650404907763,
|
| 493 |
+
.05155897513032,
|
| 494 |
+
.11112663894892,
|
| 495 |
+
.69351142644882,
|
| 496 |
+
.02447037212551,
|
| 497 |
+
.18999740481377,
|
| 498 |
+
.32223951816559,
|
| 499 |
+
.1932111531496,
|
| 500 |
+
.36098992824554,
|
| 501 |
+
.03018374741077,
|
| 502 |
+
.05362640321255,
|
| 503 |
+
.03858831897378,
|
| 504 |
+
.58987241983414,
|
| 505 |
+
.66078591346741,
|
| 506 |
+
.06137581542134,
|
| 507 |
+
.90484726428986,
|
| 508 |
+
.24177247285843,
|
| 509 |
+
.85209089517593,
|
| 510 |
+
.8382905125618,
|
| 511 |
+
.48113295435905,
|
| 512 |
+
.63542068004608,
|
| 513 |
+
.30721867084503,
|
| 514 |
+
.84170418977737,
|
| 515 |
+
.94534027576447,
|
| 516 |
+
.52911710739136,
|
| 517 |
+
.1110308393836])
|
| 518 |
+
obj.yhat = np.array([
|
| 519 |
+
-3.6007342338562,
|
| 520 |
+
-2.7604126930237,
|
| 521 |
+
-1.4679137468338,
|
| 522 |
+
-3.6272060871124,
|
| 523 |
+
.28141465783119,
|
| 524 |
+
-3.3209850788116,
|
| 525 |
+
-3.6035962104797,
|
| 526 |
+
-2.9120934009552,
|
| 527 |
+
-2.0792844295502,
|
| 528 |
+
.81658720970154,
|
| 529 |
+
-3.6855175495148,
|
| 530 |
+
-1.4500269889832,
|
| 531 |
+
-.74349880218506,
|
| 532 |
+
-1.429278254509,
|
| 533 |
+
-.57107019424438,
|
| 534 |
+
-3.4698030948639,
|
| 535 |
+
-2.8705959320068,
|
| 536 |
+
-3.2154531478882,
|
| 537 |
+
.36343798041344,
|
| 538 |
+
.66679841279984,
|
| 539 |
+
-2.7273993492126,
|
| 540 |
+
2.2522828578949,
|
| 541 |
+
-1.1429864168167,
|
| 542 |
+
1.7510952949524,
|
| 543 |
+
1.6455633640289,
|
| 544 |
+
-.07550399750471,
|
| 545 |
+
.55554306507111,
|
| 546 |
+
-.81315463781357,
|
| 547 |
+
1.6709630489349,
|
| 548 |
+
2.8504176139832,
|
| 549 |
+
.11660042405128,
|
| 550 |
+
-2.0802545547485])
|
| 551 |
+
obj.llf = -12.8896334653335
|
| 552 |
+
obj.llnull = -20.5917296966173
|
| 553 |
+
obj.df_model = 3
|
| 554 |
+
obj.df_resid = 32 - 4 # TODO: is this right? not reported in stata
|
| 555 |
+
obj.llr = 15.4041924625676
|
| 556 |
+
obj.prsquared = .374038332124624
|
| 557 |
+
obj.llr_pvalue = .00150187761112892
|
| 558 |
+
obj.aic = 33.779266930667
|
| 559 |
+
obj.bic = 39.642210541866
|
| 560 |
+
obj.z = [2.237723415, 0.6722348408, 2.234423721, -2.640537645]
|
| 561 |
+
obj.conf_int = [
|
| 562 |
+
[.3507938, 5.301432],
|
| 563 |
+
[-.1822835, .3725988],
|
| 564 |
+
[.29218, 4.465195],
|
| 565 |
+
[-22.68657, -3.35613]]
|
| 566 |
+
obj.pvalues = [.0252390974, .5014342039, .0254552063, .0082774596]
|
| 567 |
+
|
| 568 |
+
# taken from margins command
|
| 569 |
+
obj.margeff_nodummy_dydx = [
|
| 570 |
+
.36258084688424, .01220841099085, .30517768382304]
|
| 571 |
+
obj.margeff_nodummy_dydx_se = [.1094412, .0177942, .0923796]
|
| 572 |
+
obj.margeff_nodummy_dydxmean = [
|
| 573 |
+
.53385885781692, .01797548988961, .44933926079386]
|
| 574 |
+
obj.margeff_nodummy_dydxmean_se = [.237038, .0262369, .1967626]
|
| 575 |
+
obj.margeff_nodummy_dydxmedian = [
|
| 576 |
+
.25009492465091, .00842091261329, .2105003352955]
|
| 577 |
+
obj.margeff_nodummy_dydxmedian_se = [.1546708, .0134314, .0928183]
|
| 578 |
+
obj.margeff_nodummy_dydxzero = [
|
| 579 |
+
6.252993785e-06, 2.105437138e-07, 5.263030788e-06]
|
| 580 |
+
obj.margeff_nodummy_dydxzero_se = [.0000288, 9.24e-07, .000025]
|
| 581 |
+
obj.margeff_nodummy_dyex = [
|
| 582 |
+
1.1774000792198, .27896245178384, .16960002159996]
|
| 583 |
+
obj.margeff_nodummy_dyex_se = [.3616481, .4090679, .0635583]
|
| 584 |
+
obj.margeff_nodummy_dyexmean = [
|
| 585 |
+
1.6641381583512, .39433730945339, .19658592659731]
|
| 586 |
+
obj.margeff_nodummy_dyexmean_se = [.7388917, .5755722, .0860836]
|
| 587 |
+
# NOTE: PSI at median should be a NaN or 'omitted'
|
| 588 |
+
obj.margeff_nodummy_dyexmedian = [.76654095836557, .18947053379898, 0]
|
| 589 |
+
obj.margeff_nodummy_dyexmedian_se = [.4740659, .302207, 0]
|
| 590 |
+
# NOTE: all should be NaN
|
| 591 |
+
# TODO: re above Note, since the values below are *not* NaN,
|
| 592 |
+
# should something be done about this?
|
| 593 |
+
obj.margeff_nodummy_dyexzero = [0, 0, 0]
|
| 594 |
+
obj.margeff_nodummy_dyexzero_se = [0, 0, 0]
|
| 595 |
+
|
| 596 |
+
obj.margeff_nodummy_eydx = [
|
| 597 |
+
1.8546366266779, .06244722072812, 1.5610138123033]
|
| 598 |
+
obj.margeff_nodummy_eydx_se = [.847903, .0930901, .7146715]
|
| 599 |
+
obj.margeff_nodummy_eydxmean = [
|
| 600 |
+
2.1116143062702, .0710998816585, 1.7773072368626]
|
| 601 |
+
obj.margeff_nodummy_eydxmean_se = [1.076109, .1081501, .9120842]
|
| 602 |
+
obj.margeff_nodummy_eydxmedian = [
|
| 603 |
+
2.5488082240624, .0858205793373, 2.1452853812126]
|
| 604 |
+
obj.margeff_nodummy_eydxmedian_se = [1.255377, .1283771, 1.106872]
|
| 605 |
+
obj.margeff_nodummy_eydxzero = [
|
| 606 |
+
2.8261067189993, .0951574597115, 2.3786824653103]
|
| 607 |
+
obj.margeff_nodummy_eydxzero_se = [1.262961, .1415544, 1.064574]
|
| 608 |
+
obj.margeff_nodummy_eyex = [
|
| 609 |
+
5.4747106798973, 1.3173389907576, .44600395466634]
|
| 610 |
+
obj.margeff_nodummy_eyex_se = [2.44682, 1.943525, .1567618]
|
| 611 |
+
obj.margeff_nodummy_eyexmean = [
|
| 612 |
+
6.5822977203268, 1.5597536538833, .77757191612739]
|
| 613 |
+
obj.margeff_nodummy_eyexmean_se = [3.354433, 2.372543, .3990368]
|
| 614 |
+
obj.margeff_nodummy_eyexmedian = [7.8120973525952, 1.9309630350892, 0]
|
| 615 |
+
obj.margeff_nodummy_eyexmedian_se = [3.847731951, 2.888485089, 0]
|
| 616 |
+
|
| 617 |
+
obj.margeff_nodummy_eyexzero = [0, 0, 0]
|
| 618 |
+
obj.margeff_nodummy_eyexzero_se = [0, 0, 0]
|
| 619 |
+
|
| 620 |
+
# for below GPA = 2.0, psi = 1
|
| 621 |
+
obj.margeff_nodummy_atexog1 = [
|
| 622 |
+
.1456333017086, .00490359933927, .12257689308426]
|
| 623 |
+
obj.margeff_nodummy_atexog1_se = [.145633, .0111226, .1777101]
|
| 624 |
+
# for below GPA at mean, tuce = 21, psi = 0
|
| 625 |
+
obj.margeff_nodummy_atexog2 = [
|
| 626 |
+
.25105129214546, .00845311433473, .2113052923675]
|
| 627 |
+
obj.margeff_nodummy_atexog2_se = [.1735778, .012017, .0971515]
|
| 628 |
+
|
| 629 |
+
# must get this from older margeff or i.psi then margins
|
| 630 |
+
obj.margeff_dummy_dydx = [
|
| 631 |
+
.36258084688424, .01220841099085, .35751515254729]
|
| 632 |
+
obj.margeff_dummy_dydx_se = [.1094412, .0177942, .1420034]
|
| 633 |
+
obj.margeff_dummy_dydxmean = [
|
| 634 |
+
.53385885781692, .01797548988961, .4564984096959]
|
| 635 |
+
obj.margeff_dummy_dydxmean_se = [.237038, .0262369, .1810537]
|
| 636 |
+
# from margeff
|
| 637 |
+
obj.margeff_dummy_count_dydx_median = [
|
| 638 |
+
0.250110487483923, 0.008426867847905, 0.441897738279663]
|
| 639 |
+
obj.margeff_dummy_count_dydx_median_se = [
|
| 640 |
+
.1546736661, .0134551951, .1792363708]
|
| 641 |
+
|
| 642 |
+
# estimate with i.psi for the below then use margins
|
| 643 |
+
obj.margeff_dummy_eydx = [
|
| 644 |
+
1.8546366266779, .06244722072812, 1.5549034398832]
|
| 645 |
+
obj.margeff_dummy_eydx_se = [.847903, .0930901, .7283702]
|
| 646 |
+
# ie
|
| 647 |
+
# margins, eydx(*) at((mean) _all)
|
| 648 |
+
obj.margeff_dummy_eydxmean = [
|
| 649 |
+
2.1116143062702, .0710998816585, 1.6631775707188]
|
| 650 |
+
obj.margeff_dummy_eydxmean_se = [1.076109, .1081501, .801205]
|
| 651 |
+
|
| 652 |
+
# TODO: Should we remove the commented-out code below?
|
| 653 |
+
# Factor variables not allowed in below
|
| 654 |
+
# test raises
|
| 655 |
+
# obj.margeff_dummy_dydxzero
|
| 656 |
+
# obj.margeff_dummy_eydxmedian
|
| 657 |
+
# obj.margeff_dummy_eydxzero
|
| 658 |
+
# obj.margeff_dummy_dyex
|
| 659 |
+
# obj.margeff_dummy_dyexmean
|
| 660 |
+
# obj.margeff_dummy_dyexmedian
|
| 661 |
+
# obj.margeff_dummy_dyexzero
|
| 662 |
+
# obj.margeff_dummy_eyex
|
| 663 |
+
# obj.margeff_count_dummy_dydx_median
|
| 664 |
+
# obj.margeff_count_dummy_dydx_median_se
|
| 665 |
+
|
| 666 |
+
# NOTE: need old version of margeff for nodisc but at option is broken
|
| 667 |
+
# stata command is margeff, count nodisc
|
| 668 |
+
# this can be replicated with the new results by margeff
|
| 669 |
+
# and then using margins for the last value
|
| 670 |
+
obj.margeff_count_dydx = [.3625767598018, .0122068569914, .3051777]
|
| 671 |
+
obj.margeff_count_dydx_se = [.1094379569, .0177869773, .0923796]
|
| 672 |
+
|
| 673 |
+
# middle value taken from margeff rest from margins
|
| 674 |
+
obj.margeff_count_dydxmean = [
|
| 675 |
+
.5338588, 0.01797186545386, .4493393]
|
| 676 |
+
obj.margeff_count_dydxmean_se = [.237038, .0262211, .1967626]
|
| 677 |
+
|
| 678 |
+
# with new version of margeff this is just a call to
|
| 679 |
+
# margeff
|
| 680 |
+
# mat list e(margeff_b), nonames format(%17.16g)
|
| 681 |
+
obj.margeff_count_dummy_dydxoverall = [.362576759801767,
|
| 682 |
+
.012206856991439,
|
| 683 |
+
.357515163621704]
|
| 684 |
+
# AFAICT, an easy way to get se is
|
| 685 |
+
# mata
|
| 686 |
+
# V = st_matrix("e(margeff_V)")
|
| 687 |
+
# se = diagonal(cholesky(diag(V)))
|
| 688 |
+
# last SE taken from margins with i.psi, do not know how they
|
| 689 |
+
# do not know why margeff is different, but trust official results
|
| 690 |
+
obj.margeff_count_dummy_dydxoverall_se = [.1094379569, .0177869773,
|
| 691 |
+
.1420034]
|
| 692 |
+
|
| 693 |
+
# from new margeff
|
| 694 |
+
obj.margeff_count_dummy_dydxmean = [0.533849340033768,
|
| 695 |
+
0.017971865453858,
|
| 696 |
+
0.456498405282412]
|
| 697 |
+
obj.margeff_count_dummy_dydxmean_se = [.2370202503, .0262210796,
|
| 698 |
+
.1810536852]
|
| 699 |
+
|
| 700 |
+
# for below GPA = 2.0, psi = 1
|
| 701 |
+
obj.margeff_dummy_atexog1 = [
|
| 702 |
+
.1456333017086, .00490359933927, .0494715429937]
|
| 703 |
+
obj.margeff_dummy_atexog1_se = [.145633, .0111226, .0731368]
|
| 704 |
+
# for below GPA at mean, tuce = 21, psi = 0
|
| 705 |
+
obj.margeff_dummy_atexog2 = [.25105129214546,
|
| 706 |
+
.00845311433473,
|
| 707 |
+
.44265645632553]
|
| 708 |
+
obj.margeff_dummy_atexog2_se = [.1735778, .012017, .1811925]
|
| 709 |
+
# The test for the prediction table was taken from Gretl
|
| 710 |
+
# Gretl Output matched the Stata output here for params and SE
|
| 711 |
+
obj.pred_table = np.array([[18, 3], [3, 8]])
|
| 712 |
+
return obj
|
| 713 |
+
|
| 714 |
+
logit = logit()
|
| 715 |
+
|
| 716 |
+
def probit():
|
| 717 |
+
obj = Namespace()
|
| 718 |
+
obj.nobs = 32
|
| 719 |
+
obj.params = [
|
| 720 |
+
1.62581025407, .051728948442, 1.42633236818, -7.45232041607]
|
| 721 |
+
obj.cov_params = [
|
| 722 |
+
[.481472955383, -.01891350017, .105439226234, -1.1696681354],
|
| 723 |
+
[-.01891350017, .00703757594, .002471864882, -.101172838897],
|
| 724 |
+
[.105439226234, .002471864882, .354070126802, -.594791776765],
|
| 725 |
+
[-1.1696681354, -.101172838897, -.594791776765, 6.46416639958]]
|
| 726 |
+
obj.bse = [.693882522754, .083890261293, .595037920474, 2.54247249731]
|
| 727 |
+
obj.llf = -12.8188033249334
|
| 728 |
+
obj.llnull = -20.5917296966173
|
| 729 |
+
obj.df_model = 3
|
| 730 |
+
obj.df_resid = 32 - 4
|
| 731 |
+
obj.llr = 15.5458527433678
|
| 732 |
+
obj.prsquared = .377478069409622
|
| 733 |
+
obj.llr_pvalue = .00140489496775855
|
| 734 |
+
obj.aic = 33.637606649867
|
| 735 |
+
obj.bic = 39.500550261066
|
| 736 |
+
obj.z = [2.343062695, .6166263836, 2.397044489, -2.931131182]
|
| 737 |
+
obj.conf_int = [
|
| 738 |
+
[.2658255, 2.985795],
|
| 739 |
+
[-.1126929, .2161508],
|
| 740 |
+
[.2600795, 2.592585],
|
| 741 |
+
[-12.43547, -2.469166]]
|
| 742 |
+
obj.pvalues = [.0191261688, .537481188, .0165279168, .0033773013]
|
| 743 |
+
obj.phat = [
|
| 744 |
+
.0181707, .0530805, .1899263, .0185707, .5545748,
|
| 745 |
+
.0272331, .0185033, .0445714, .1088081, .6631207,
|
| 746 |
+
.0161024, .1935566, .3233282, .1951826, .3563406,
|
| 747 |
+
.0219654, .0456943, .0308513, .5934023, .6571863,
|
| 748 |
+
.0619288, .9045388, .2731908, .8474501, .8341947,
|
| 749 |
+
.488726, .6424073, .3286732, .8400168, .9522446,
|
| 750 |
+
.5399595, .123544]
|
| 751 |
+
obj.yhat = np.array([
|
| 752 |
+
-2.0930860042572,
|
| 753 |
+
-1.615691781044,
|
| 754 |
+
-.87816804647446,
|
| 755 |
+
-2.0842070579529,
|
| 756 |
+
.13722851872444,
|
| 757 |
+
-1.9231110811234,
|
| 758 |
+
-2.0856919288635,
|
| 759 |
+
-1.6999372243881,
|
| 760 |
+
-1.2328916788101,
|
| 761 |
+
.42099541425705,
|
| 762 |
+
-2.1418602466583,
|
| 763 |
+
-.86486464738846,
|
| 764 |
+
-.45841211080551,
|
| 765 |
+
-.85895526409149,
|
| 766 |
+
-.36825761198997,
|
| 767 |
+
-2.0147502422333,
|
| 768 |
+
-1.6881184577942,
|
| 769 |
+
-1.8684275150299,
|
| 770 |
+
.23630557954311,
|
| 771 |
+
.40479621291161,
|
| 772 |
+
-1.538782119751,
|
| 773 |
+
1.3078554868698,
|
| 774 |
+
-.60319095849991,
|
| 775 |
+
1.025558590889,
|
| 776 |
+
.97087496519089,
|
| 777 |
+
-.02826354466379,
|
| 778 |
+
.36490100622177,
|
| 779 |
+
-.44357979297638,
|
| 780 |
+
.99452745914459,
|
| 781 |
+
1.6670187711716,
|
| 782 |
+
.10033150017262,
|
| 783 |
+
-1.1574513912201])
|
| 784 |
+
obj.resid_dev = [
|
| 785 |
+
-.191509, -.3302762, -.6490455, -.1936247, 1.085867,
|
| 786 |
+
-.2349926, -.1932698, -.3019776, -.4799906, .9064196,
|
| 787 |
+
-.1801855, -.6559291, -.8838201, 1.807661, -.9387071,
|
| 788 |
+
-.2107617, -.3058469, -.2503485, -1.341589, .9162835,
|
| 789 |
+
-.3575735, .447951, -.7988633, -1.939208, .6021435,
|
| 790 |
+
1.196623, .9407793, -.8927477, .59048, .3128364,
|
| 791 |
+
-1.246147, 2.045071]
|
| 792 |
+
# Stata does not have it, but I think it's just oversight
|
| 793 |
+
obj.resid_pearson = None
|
| 794 |
+
# generalized residuals from gretl
|
| 795 |
+
obj.resid_generalized = [
|
| 796 |
+
-0.045452, -0.114220, -0.334908,
|
| 797 |
+
-0.046321, 0.712624, -0.064538,
|
| 798 |
+
-0.046175, -0.098447, -0.209349,
|
| 799 |
+
0.550593, -0.040906, -0.340339,
|
| 800 |
+
-0.530763, 1.413373, -0.579170,
|
| 801 |
+
-0.053593, -0.100556, -0.071855,
|
| 802 |
+
-0.954156, 0.559294, -0.130167,
|
| 803 |
+
0.187523, -0.457597, -1.545643,
|
| 804 |
+
0.298511, 0.815964, 0.581013,
|
| 805 |
+
-0.538579, 0.289631, 0.104405,
|
| 806 |
+
-0.862836, 1.652638]
|
| 807 |
+
obj.pred_table = np.array([[18, 3], [3, 8]])
|
| 808 |
+
return obj
|
| 809 |
+
|
| 810 |
+
probit = probit()
|
| 811 |
+
|
| 812 |
+
|
| 813 |
+
class RandHIE:
|
| 814 |
+
"""
|
| 815 |
+
Results obtained from Stata 11
|
| 816 |
+
"""
|
| 817 |
+
def __init__(self):
|
| 818 |
+
self.nobs = 20190
|
| 819 |
+
|
| 820 |
+
def poisson():
|
| 821 |
+
obj = Namespace()
|
| 822 |
+
obj.nobs = 20190
|
| 823 |
+
obj.params = [
|
| 824 |
+
-.052535114675, -.247086797633, .035290201794,
|
| 825 |
+
-.03457750643, .271713973711, .033941474461, -.012635035534,
|
| 826 |
+
.054056326828, .206115121809, .700352877227]
|
| 827 |
+
obj.cov_params = None
|
| 828 |
+
obj.bse = [
|
| 829 |
+
.00288398915279, .01061725196728, .00182833684966,
|
| 830 |
+
.00161284852954, .01223913844387, .00056476496963,
|
| 831 |
+
.00925061122826, .01530987068312, .02627928267502,
|
| 832 |
+
.01116266712362]
|
| 833 |
+
predict = np.loadtxt(os.path.join(cur_dir, 'yhat_poisson.csv'),
|
| 834 |
+
delimiter=",")
|
| 835 |
+
obj.phat = predict[:, 0]
|
| 836 |
+
obj.yhat = predict[:, 1]
|
| 837 |
+
obj.llf = -62419.588535018
|
| 838 |
+
obj.llnull = -66647.181687959
|
| 839 |
+
obj.df_model = 9
|
| 840 |
+
obj.df_resid = obj.nobs - obj.df_model - 1
|
| 841 |
+
obj.llr = 8455.186305881856
|
| 842 |
+
obj.prsquared = .0634324369893758
|
| 843 |
+
obj.llr_pvalue = 0
|
| 844 |
+
obj.aic = 124859.17707
|
| 845 |
+
obj.bic = 124938.306497
|
| 846 |
+
obj.z = [-18.21612769, -23.27219872, 19.30180524, -21.43878101,
|
| 847 |
+
22.20041672, 60.09840604, -1.36585953, 3.53081538, 7.84325525,
|
| 848 |
+
62.74063980]
|
| 849 |
+
obj.conf_int = [
|
| 850 |
+
[-.0581876, -.0468826],
|
| 851 |
+
[-0.2678962, -0.2262774],
|
| 852 |
+
[0.0317067, 0.0388737],
|
| 853 |
+
[-0.0377386, -0.0314164],
|
| 854 |
+
[0.2477257, 0.2957022],
|
| 855 |
+
[0.0328346, 0.0350484],
|
| 856 |
+
[-0.0307659, 0.0054958],
|
| 857 |
+
[0.0240495, 0.0840631],
|
| 858 |
+
[0.1546087, 0.2576216],
|
| 859 |
+
[0.6784745, 0.7222313]]
|
| 860 |
+
obj.pvalues = [
|
| 861 |
+
3.84415e-74, 8.4800e-120, 5.18652e-83, 5.8116e-102,
|
| 862 |
+
3.4028e-109, 0, .1719830562, .0004142808, 4.39014e-15, 0]
|
| 863 |
+
|
| 864 |
+
# from stata
|
| 865 |
+
# use margins and put i. in front of dummies
|
| 866 |
+
obj.margeff_dummy_overall = [
|
| 867 |
+
-0.15027280560599, -0.66568074771099,
|
| 868 |
+
0.10094500919706, -0.09890639687842,
|
| 869 |
+
0.77721770295360, 0.09708707452600,
|
| 870 |
+
-0.03608195237609, 0.15804581481115,
|
| 871 |
+
0.65104087597053]
|
| 872 |
+
obj.margeff_dummy_overall_se = [
|
| 873 |
+
.008273103, .0269856266,
|
| 874 |
+
.0052466639, .0046317555, .0351582169, .0016652181,
|
| 875 |
+
.0263736472, .0457480115, .0913901155]
|
| 876 |
+
|
| 877 |
+
# just use margins
|
| 878 |
+
obj.margeff_nodummy_overall = [
|
| 879 |
+
-0.15027280560599, -0.70677348928158,
|
| 880 |
+
0.10094500919705, -0.09890639687842,
|
| 881 |
+
0.77721770295359, 0.09708707452600,
|
| 882 |
+
-0.03614158359367, 0.15462412033340,
|
| 883 |
+
0.58957704430148]
|
| 884 |
+
obj.margeff_nodummy_overall_se = [
|
| 885 |
+
.008273103, .0305119343,
|
| 886 |
+
.0052466639, .0046317555,
|
| 887 |
+
.0351582168, .0016652181,
|
| 888 |
+
.0264611158, .0437974779,
|
| 889 |
+
.0752099666]
|
| 890 |
+
# taken from gretl
|
| 891 |
+
obj.resid = np.loadtxt(os.path.join(cur_dir, 'poisson_resid.csv'),
|
| 892 |
+
delimiter=",")
|
| 893 |
+
return obj
|
| 894 |
+
|
| 895 |
+
poisson = poisson()
|
| 896 |
+
|
| 897 |
+
def negativebinomial_nb2_bfgs():
|
| 898 |
+
# R 2.15.1 MASS 7.3-22 glm.nb()
|
| 899 |
+
obj = Namespace()
|
| 900 |
+
obj.nobs = 20190
|
| 901 |
+
obj.params = [
|
| 902 |
+
-0.0579469537244314,
|
| 903 |
+
-0.267787718814838, 0.0412060770911646, -0.0381376804392121,
|
| 904 |
+
0.268915772213171, 0.0381637446219235, -0.0441338846217674,
|
| 905 |
+
0.0172521803400544, 0.177960787443151, 0.663556087183864,
|
| 906 |
+
# lnalpha from stata
|
| 907 |
+
1.292953339909746]
|
| 908 |
+
# alpha and stderr from stata
|
| 909 |
+
obj.lnalpha_std_err = .0143932
|
| 910 |
+
obj.lnalpha = 0.256929012449
|
| 911 |
+
obj.bse = [
|
| 912 |
+
0.00607085853920512, 0.0226125368090765,
|
| 913 |
+
0.00405542008282773, 0.00344455937127785, 0.0298855063286547,
|
| 914 |
+
0.00142421904710063, 0.0199374393307107, 0.0358416931939136,
|
| 915 |
+
0.0741013728607101, 0.0250354082637892,
|
| 916 |
+
# from stata
|
| 917 |
+
.0186098]
|
| 918 |
+
obj.z = [
|
| 919 |
+
-9.54510030998327, -11.8424447940467,
|
| 920 |
+
10.1607419822296, -11.071860382846, 8.99820030672628,
|
| 921 |
+
26.7962605187844, -2.21361850384595, 0.481343898758222,
|
| 922 |
+
2.40158556546135, 26.5047040652267]
|
| 923 |
+
obj.pvalues = [
|
| 924 |
+
1.35975947860026e-21,
|
| 925 |
+
2.35486776488278e-32, 2.96808970292151e-24,
|
| 926 |
+
1.71796558863781e-28, 2.2944789508802e-19,
|
| 927 |
+
3.57231639404726e-158, 0.0268550333379416, 0.630272102021494,
|
| 928 |
+
0.0163241908407114, 8.55476622951356e-155]
|
| 929 |
+
obj.fittedvalues = [
|
| 930 |
+
0.892904166867786, 0.892904166867786, 0.892904166867786,
|
| 931 |
+
0.892904166867786, 0.892904166867786, 0.937038051489553,
|
| 932 |
+
0.937038051489553, 0.937038051489553, 0.937038051489553,
|
| 933 |
+
0.937038051489553]
|
| 934 |
+
# obj.aic = 86789.3241530713 # This is what R reports
|
| 935 |
+
obj.aic = 86789.32415307125484 # from Stata
|
| 936 |
+
obj.df_resid = 20180
|
| 937 |
+
obj.df_model = 9
|
| 938 |
+
# R conf_int: 1.96 * bse, not profile likelihood via R's confint()
|
| 939 |
+
obj.conf_int = [
|
| 940 |
+
# from Stata
|
| 941 |
+
[-.0698826, -.0460113],
|
| 942 |
+
[-.3122654, -.2233101],
|
| 943 |
+
[.0330781, .049334],
|
| 944 |
+
[-.0448006, -.0314748],
|
| 945 |
+
[.2102246, .3276069],
|
| 946 |
+
[.0352959, .0410316],
|
| 947 |
+
[-.0834356, -.0048321],
|
| 948 |
+
[-.0535908, .0880951],
|
| 949 |
+
[.0324115, .3235101],
|
| 950 |
+
[.6150055, .7121067],
|
| 951 |
+
# from Stata
|
| 952 |
+
[1.256989, 1.329947]
|
| 953 |
+
]
|
| 954 |
+
obj.bic = 86876.36652289562335 # stata
|
| 955 |
+
obj.llnull = -44199.27443563430279 # stata
|
| 956 |
+
obj.llr = 1631.224718197351 # stata
|
| 957 |
+
obj.llf = -43383.66207653563 # stata
|
| 958 |
+
obj.df_model = 9.0
|
| 959 |
+
obj.llr_pvalue = 0.0
|
| 960 |
+
return obj
|
| 961 |
+
|
| 962 |
+
negativebinomial_nb2_bfgs = negativebinomial_nb2_bfgs()
|
| 963 |
+
|
| 964 |
+
def negativebinomial_nb1_bfgs():
|
| 965 |
+
# Unpublished implementation intended for R's COUNT package. Sent by
|
| 966 |
+
# J.Hilbe (of Cambridge UP NBin book) and Andrew Robinson to Vincent
|
| 967 |
+
# Arel-Bundock on 2012-12-06.
|
| 968 |
+
|
| 969 |
+
# TODO: Does the from Stata comment below apply to the
|
| 970 |
+
# commented-out obj.params here or to everything below? If the
|
| 971 |
+
# latter, then where do the commented-out version come from?
|
| 972 |
+
# obj.params = [-0.065309744899923, -0.296016207412261,
|
| 973 |
+
# 0.0411724098925173, -0.0320460533573259, 0.19083354227553,
|
| 974 |
+
# 0.0318566232844115, -0.0331972813313092, -0.0484691550721231,
|
| 975 |
+
# 0.111971860837541, 0.757560143822609,
|
| 976 |
+
# 3.73086958562569]
|
| 977 |
+
# from Stata
|
| 978 |
+
obj = Namespace()
|
| 979 |
+
obj.nobs = 20190
|
| 980 |
+
obj.params = [-.065317260803762961, -.296023807893893376,
|
| 981 |
+
.041187021258044826, -.032028789543547605,
|
| 982 |
+
.19065933246421754, .031871625115758778,
|
| 983 |
+
-.033250849053302826, -.04850769174426571,
|
| 984 |
+
.111813637465757343, .757277086555503409,
|
| 985 |
+
3.731151380800305]
|
| 986 |
+
# lnalpha and lnalpha_std_err are from stata
|
| 987 |
+
obj.lnalpha = 1.316716867203
|
| 988 |
+
obj.lnalpha_std_err = .0168876692
|
| 989 |
+
obj.bse = [
|
| 990 |
+
0.00536019929563678,
|
| 991 |
+
0.0196998350459769, 0.00335779098766272, 0.00301145915122889,
|
| 992 |
+
0.0237984097096245, 0.00107360844112751, 0.0167174614755359,
|
| 993 |
+
0.0298037989274781, 0.0546838603596457, 0.0214703279904911,
|
| 994 |
+
0.0630011409376052]
|
| 995 |
+
obj.z = [
|
| 996 |
+
-12.1842008660173, -15.0263292419148,
|
| 997 |
+
12.2617548393554, -10.6413707601675, 8.0187518663633,
|
| 998 |
+
29.6724784046551, -1.98578482623631, -1.62627439508848,
|
| 999 |
+
2.04762173155154, 35.2840508145997,
|
| 1000 |
+
|
| 1001 |
+
# From R, this is alpha/bse(alpha)
|
| 1002 |
+
59.2190796881069
|
| 1003 |
+
|
| 1004 |
+
# taken from Stata even though they do not report it
|
| 1005 |
+
# lnalpha/bse(lnalpha)
|
| 1006 |
+
# 77.968995
|
| 1007 |
+
]
|
| 1008 |
+
|
| 1009 |
+
obj.conf_int = [
|
| 1010 |
+
[-0.075815736, -0.0548037543],
|
| 1011 |
+
[-0.334627884, -0.2574045307],
|
| 1012 |
+
[0.034591140, 0.0477536802],
|
| 1013 |
+
[-0.037948513, -0.0261435934],
|
| 1014 |
+
[0.144188659, 0.2374784253],
|
| 1015 |
+
[0.029752351, 0.0339608958],
|
| 1016 |
+
[-0.065963506, -0.0004310568],
|
| 1017 |
+
[-0.106884601, 0.0099462908],
|
| 1018 |
+
[0.004791495, 0.2191522271],
|
| 1019 |
+
[3.607387349, 3.8543518219],
|
| 1020 |
+
[0.715478301, 0.7996419867]]
|
| 1021 |
+
# from Stata
|
| 1022 |
+
obj.llf = -43278.75612911823
|
| 1023 |
+
obj.llnull = -44199.2744356343
|
| 1024 |
+
obj.llr = 1841.036613032149
|
| 1025 |
+
obj.aic = 86579.51225823645655
|
| 1026 |
+
obj.bic = 86666.55462806082505
|
| 1027 |
+
obj.llr_pvalue = 0.0
|
| 1028 |
+
obj.df_model = 9.0
|
| 1029 |
+
obj.df_resid = 20180.0
|
| 1030 |
+
# Smoke tests TODO: check against other stats package
|
| 1031 |
+
obj.pvalues = [
|
| 1032 |
+
3.65557865e-034, 5.24431864e-051,
|
| 1033 |
+
1.42921171e-034, 2.09797259e-026, 1.15949461e-015,
|
| 1034 |
+
1.56785415e-193, 4.71746349e-002, 1.04731854e-001,
|
| 1035 |
+
4.07534831e-002, 1.95504975e-272, 0.00000000e+000]
|
| 1036 |
+
obj.conf_int = [
|
| 1037 |
+
[-.0758236, -.054811],
|
| 1038 |
+
[-.3346363, -.2574113],
|
| 1039 |
+
[.0346053, .0477687],
|
| 1040 |
+
[-.0379314, -.0261261],
|
| 1041 |
+
[.1440119, .2373067],
|
| 1042 |
+
[.0297667, .0339766],
|
| 1043 |
+
[-.0660178, -.0004839],
|
| 1044 |
+
[-.1069241, .0099087],
|
| 1045 |
+
[.0046266, .2190007],
|
| 1046 |
+
[.7151889, .7993652],
|
| 1047 |
+
# from stata for alpha no lnalpha
|
| 1048 |
+
[3.609675, 3.856716]]
|
| 1049 |
+
# [1.28360034e+00, 1.34979803e+00]]
|
| 1050 |
+
obj.fittedvalues = [
|
| 1051 |
+
0.8487497, 0.8487497, 0.8487497, 0.8487497,
|
| 1052 |
+
0.8487497, 0.88201746, 0.88201746, 0.88201746, 0.88201746,
|
| 1053 |
+
0.88201746]
|
| 1054 |
+
return obj
|
| 1055 |
+
|
| 1056 |
+
negativebinomial_nb1_bfgs = negativebinomial_nb1_bfgs()
|
| 1057 |
+
|
| 1058 |
+
def negativebinomial_geometric_bfgs():
|
| 1059 |
+
# Smoke tests TODO: Cross check with other stats package
|
| 1060 |
+
obj = Namespace()
|
| 1061 |
+
obj.nobs = 20190
|
| 1062 |
+
obj.params = [
|
| 1063 |
+
-0.05768894, -0.26646696, 0.04088528, -0.03795503,
|
| 1064 |
+
0.26885821, 0.03802523, -0.04308456, 0.01931675, 0.18051684,
|
| 1065 |
+
0.66469896]
|
| 1066 |
+
obj.bse = [
|
| 1067 |
+
0.00553867, 0.02061988, 0.00375937, 0.0030924,
|
| 1068 |
+
0.02701658, 0.00132201, 0.01821646, 0.03271784, 0.06666231,
|
| 1069 |
+
0.02250053]
|
| 1070 |
+
obj.pvalues = [
|
| 1071 |
+
2.10310916e-025, 3.34666368e-038, 1.50697768e-027,
|
| 1072 |
+
1.25468406e-034, 2.48155744e-023, 6.18745348e-182,
|
| 1073 |
+
1.80230194e-002, 5.54919603e-001, 6.77044178e-003,
|
| 1074 |
+
8.44913440e-192]
|
| 1075 |
+
obj.z = [-10.41567024, -12.92281571, 10.8755779, -12.27364916,
|
| 1076 |
+
9.95160202, 28.76323587, -2.36514487, 0.59040434,
|
| 1077 |
+
2.70792943, 29.54148082]
|
| 1078 |
+
obj.aic = 87101.159433012392 # old value 87101.160011780419
|
| 1079 |
+
obj.bic = 87180.288860125467 # old value 87180.289438893495
|
| 1080 |
+
obj.df_model = 9.0
|
| 1081 |
+
obj.df_resid = 20180.0
|
| 1082 |
+
obj.llf = -43540.58000589021
|
| 1083 |
+
obj.llnull = -44586.650971362695 # old value -44199.27443567125
|
| 1084 |
+
obj.llr = 2092.1425097129977 # old value 1317.3888595620811
|
| 1085 |
+
obj.llr_pvalue = 0 # old value 5.4288002863296022e-278
|
| 1086 |
+
obj.fittedvalues = [
|
| 1087 |
+
0.89348994, 0.89348994, 0.89348994,
|
| 1088 |
+
0.89348994, 0.89348994, 0.9365745, 0.9365745, 0.9365745,
|
| 1089 |
+
0.9365745, 0.9365745]
|
| 1090 |
+
obj.conf_int = [
|
| 1091 |
+
[-0.06854453, -0.04683335],
|
| 1092 |
+
[-0.30688118, -0.22605273],
|
| 1093 |
+
[0.03351706, 0.04825351],
|
| 1094 |
+
[-0.04401602, -0.03189404],
|
| 1095 |
+
[0.21590669, 0.32180972],
|
| 1096 |
+
[0.03543415, 0.04061632],
|
| 1097 |
+
[-0.07878816, -0.00738096],
|
| 1098 |
+
[-0.04480903, 0.08344253],
|
| 1099 |
+
[0.04986111, 0.31117258],
|
| 1100 |
+
[0.62059873, 0.70879919]]
|
| 1101 |
+
return obj
|
| 1102 |
+
|
| 1103 |
+
negativebinomial_geometric_bfgs = negativebinomial_geometric_bfgs()
|
| 1104 |
+
|
| 1105 |
+
def generalizedpoisson_gp2():
|
| 1106 |
+
# Stata gnpoisson function
|
| 1107 |
+
obj = Namespace()
|
| 1108 |
+
obj.nobs = 20190
|
| 1109 |
+
obj.llf = -43326.42720093228
|
| 1110 |
+
obj.params = [-0.0604495342, -0.277717228, 0.0438136144,
|
| 1111 |
+
-0.0395811744, 0.273044906, 0.0399108677, -0.0552626543,
|
| 1112 |
+
-0.001227569488, 0.151980519, 0.651125316, 0.448085318]
|
| 1113 |
+
obj.lnalpha_std_err = 0.0125607
|
| 1114 |
+
obj.lnalpha = -0.8027716
|
| 1115 |
+
obj.bse = [0.00634704, 0.02381906, 0.00443871, 0.00355094,
|
| 1116 |
+
0.0334247, 0.00166303, 0.02102142, 0.0390845,
|
| 1117 |
+
0.087821, 0.02626823, 0.00562825]
|
| 1118 |
+
obj.df_model = 9
|
| 1119 |
+
obj.aic = 86674.854401865
|
| 1120 |
+
obj.conf_int = [
|
| 1121 |
+
[-0.07288951, -0.04800956],
|
| 1122 |
+
[-0.32440173, -0.23103272],
|
| 1123 |
+
[0.03511389, 0.05251333],
|
| 1124 |
+
[-0.04654088, -0.03262147],
|
| 1125 |
+
[0.20753371, 0.33855610],
|
| 1126 |
+
[0.03665139, 0.04317034],
|
| 1127 |
+
[-0.09646387, -0.01406144],
|
| 1128 |
+
[-0.07783191, 0.07537652],
|
| 1129 |
+
[-0.02014548, 0.32410651],
|
| 1130 |
+
[0.59964053, 0.70261011],
|
| 1131 |
+
[0.43718883, 0.45925338]
|
| 1132 |
+
]
|
| 1133 |
+
obj.bic = 86761.896771689
|
| 1134 |
+
obj.wald_pvalue = 4.8795019354e-254
|
| 1135 |
+
obj.wald_statistic = 1206.46339591254
|
| 1136 |
+
return obj
|
| 1137 |
+
|
| 1138 |
+
generalizedpoisson_gp2 = generalizedpoisson_gp2()
|
| 1139 |
+
|
| 1140 |
+
def zero_inflated_poisson_logit():
|
| 1141 |
+
obj = Namespace()
|
| 1142 |
+
obj.nobs = 20190
|
| 1143 |
+
obj.params = [.1033783, -1.045983, -.0821979, .0085692,
|
| 1144 |
+
-.0267957, 1.482363]
|
| 1145 |
+
obj.llf = -57005.72199826186
|
| 1146 |
+
obj.bse = [0.0079912, 0.02235510, .0107145, 0.0018697,
|
| 1147 |
+
0.0014121, 0.0085915]
|
| 1148 |
+
obj.conf_int = [
|
| 1149 |
+
[0.0877159, 0.1190408],
|
| 1150 |
+
[-1.089798, -1.002167],
|
| 1151 |
+
[-0.1031979, -0.061198],
|
| 1152 |
+
[0.0049045, 0.0122338],
|
| 1153 |
+
[-0.0295635, -0.024028],
|
| 1154 |
+
[1.465524, 1.499202]]
|
| 1155 |
+
obj.aic = 114023.444
|
| 1156 |
+
obj.bic = 114070.9
|
| 1157 |
+
return obj
|
| 1158 |
+
|
| 1159 |
+
zero_inflated_poisson_logit = zero_inflated_poisson_logit()
|
| 1160 |
+
|
| 1161 |
+
def zero_inflated_poisson_probit():
|
| 1162 |
+
obj = Namespace()
|
| 1163 |
+
obj.nobs = 20190
|
| 1164 |
+
obj.params = [.0622534, -.6429324, -.0821788, .0085673,
|
| 1165 |
+
-.0267952, 1.482369]
|
| 1166 |
+
obj.llf = -57006.05
|
| 1167 |
+
obj.bse = [.0048228, .0132516, .0107142, .0018697,
|
| 1168 |
+
.0014121, .0085913]
|
| 1169 |
+
obj.conf_int = [
|
| 1170 |
+
[0.0528009, .0717058],
|
| 1171 |
+
[-0.6689051, -.6169597],
|
| 1172 |
+
[-0.1031783, -.0611793],
|
| 1173 |
+
[0.0049027, .0122319],
|
| 1174 |
+
[-0.0295629, -.0240275],
|
| 1175 |
+
[1.46553, 1.499208]]
|
| 1176 |
+
obj.aic = 114024.1
|
| 1177 |
+
obj.bic = 114071.6
|
| 1178 |
+
return obj
|
| 1179 |
+
|
| 1180 |
+
zero_inflated_poisson_probit = zero_inflated_poisson_probit()
|
| 1181 |
+
|
| 1182 |
+
def zero_inflated_poisson_offset():
|
| 1183 |
+
obj = Namespace()
|
| 1184 |
+
obj.nobs = 20190
|
| 1185 |
+
obj.params = [.1052014, -1.082434, -.0922822, .0115868,
|
| 1186 |
+
-.0283842, 1.347514]
|
| 1187 |
+
obj.llf = -58207.67
|
| 1188 |
+
obj.bse = [.0081836, .0230043, .0107788, .0018687,
|
| 1189 |
+
.0014162, .0086309]
|
| 1190 |
+
obj.conf_int = [
|
| 1191 |
+
[.0891619, .1212409],
|
| 1192 |
+
[-1.127522, -1.037347],
|
| 1193 |
+
[-.1134082, -.0711561],
|
| 1194 |
+
[.0079242, .0152494],
|
| 1195 |
+
[-.0311599, -.0256085],
|
| 1196 |
+
[1.330598, 1.36443]]
|
| 1197 |
+
obj.aic = 116427.3
|
| 1198 |
+
obj.bic = 116474.8
|
| 1199 |
+
return obj
|
| 1200 |
+
|
| 1201 |
+
zero_inflated_poisson_offset = zero_inflated_poisson_offset()
|
| 1202 |
+
|
| 1203 |
+
def zero_inflated_generalized_poisson():
|
| 1204 |
+
obj = Namespace()
|
| 1205 |
+
obj.nobs = 20190
|
| 1206 |
+
obj.params = [3.57337, -17.95797, -0.21380, 0.03847,
|
| 1207 |
+
-0.05348, 1.15666, 1.36468]
|
| 1208 |
+
obj.llf = -43630.6
|
| 1209 |
+
obj.bse = [1.66109, 7.62052, 0.02066, 0.00339,
|
| 1210 |
+
0.00289, 0.01680, 0.01606]
|
| 1211 |
+
obj.aic = 87275
|
| 1212 |
+
return obj
|
| 1213 |
+
|
| 1214 |
+
zero_inflated_generalized_poisson = zero_inflated_generalized_poisson()
|
| 1215 |
+
|
| 1216 |
+
def zero_inflated_negative_binomial():
|
| 1217 |
+
obj = Namespace()
|
| 1218 |
+
obj.params = [1.883859, -10.280888, -0.204769, 1.137985, 1.344457]
|
| 1219 |
+
obj.llf = -44077.91
|
| 1220 |
+
obj.bse = [0.3653, 1.6694, 0.02178, 0.01163, 0.0217496]
|
| 1221 |
+
obj.aic = 88165.81
|
| 1222 |
+
return obj
|
| 1223 |
+
|
| 1224 |
+
zero_inflated_negative_binomial = zero_inflated_negative_binomial()
|
| 1225 |
+
|
| 1226 |
+
def truncated_poisson(self):
|
| 1227 |
+
self.params = [.000241, -.0002085, .0059419, .0016508, 2.289668]
|
| 1228 |
+
self.llf = -11091.36
|
| 1229 |
+
self.bse = [.0042718, .0157994, .002791, .0023491, .0123182]
|
| 1230 |
+
self.conf_int = [[-.0081316, .0086136],
|
| 1231 |
+
[-.0311747, .0307577],
|
| 1232 |
+
[0.0004716, .0114122],
|
| 1233 |
+
[-.0029532, .0062549],
|
| 1234 |
+
[2.265525, 2.313812]]
|
| 1235 |
+
self.aic = 22192.72
|
| 1236 |
+
self.bic = 22222.87
|
| 1237 |
+
|
| 1238 |
+
def zero_truncated_poisson(self):
|
| 1239 |
+
self.params = [-.0095444, -.07581, .0080299, -.022879, 1.486142]
|
| 1240 |
+
self.llf = -44570.853
|
| 1241 |
+
self.bse = [.0029817, .0109677, .0019165, .0016393, .0085697]
|
| 1242 |
+
self.conf_int = [[-.0153884, -0.0037005],
|
| 1243 |
+
[-.0973064, -0.0543137],
|
| 1244 |
+
[0.0042736, 0.0117861],
|
| 1245 |
+
[-.0260919, -0.019666],
|
| 1246 |
+
[1.469346, 1.502939]]
|
| 1247 |
+
self.aic = 89151.71
|
| 1248 |
+
self.bic = 89189.39
|
| 1249 |
+
|
| 1250 |
+
def zero_truncted_nbp(self):
|
| 1251 |
+
self.params = [-0.0397571554, -0.1269997715, 0.0002753126,
|
| 1252 |
+
0.9294720085, 2.246603]
|
| 1253 |
+
self.llf = -31565
|
| 1254 |
+
self.bse = [0.0074415, 0.0308599, 0.0053180, 0.0342113,
|
| 1255 |
+
0.1030674]
|
| 1256 |
+
self.aic = 63139.99
|
| 1257 |
+
self.bic = 63177.69
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_glm_logit_constrained.py
ADDED
|
@@ -0,0 +1,697 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
| 9 |
+
df=28,
|
| 10 |
+
df_m=3,
|
| 11 |
+
power=0,
|
| 12 |
+
canonical=1,
|
| 13 |
+
rank=4,
|
| 14 |
+
aic=1.055602138883215,
|
| 15 |
+
rc=0,
|
| 16 |
+
p=.0388431588742135,
|
| 17 |
+
chi2=8.376256383189103,
|
| 18 |
+
ll=-12.88963422213144,
|
| 19 |
+
k_autoCns=0,
|
| 20 |
+
converged=1,
|
| 21 |
+
k_dv=1,
|
| 22 |
+
k_eq=1,
|
| 23 |
+
k=4,
|
| 24 |
+
ic=3,
|
| 25 |
+
N=32,
|
| 26 |
+
nbml=0,
|
| 27 |
+
bic=-71.26133683412948,
|
| 28 |
+
dispers_ps=.9734684585933382,
|
| 29 |
+
deviance_ps=27.25711684061347,
|
| 30 |
+
dispers_p=.9734684585933382,
|
| 31 |
+
deviance_p=27.25711684061347,
|
| 32 |
+
dispers_s=.920688158723674,
|
| 33 |
+
deviance_s=25.77926844426287,
|
| 34 |
+
dispers=.920688158723674,
|
| 35 |
+
deviance=25.77926844426287,
|
| 36 |
+
cmdline="glm grade gpa tuce psi, family(binomial)",
|
| 37 |
+
cmd="glm",
|
| 38 |
+
predict="glim_p",
|
| 39 |
+
marginsnotok="stdp Anscombe Cooksd Deviance Hat Likelihood Pearson Response Score Working ADJusted STAndardized STUdentized MODified", # noqa:E501
|
| 40 |
+
marginsok="default",
|
| 41 |
+
hac_lag="30",
|
| 42 |
+
vcetype="OIM",
|
| 43 |
+
vce="oim",
|
| 44 |
+
linkt="Logit",
|
| 45 |
+
linkf="ln(u/(1-u))",
|
| 46 |
+
varfunct="Bernoulli",
|
| 47 |
+
varfuncf="u*(1-u)",
|
| 48 |
+
opt1="ML",
|
| 49 |
+
oim="oim",
|
| 50 |
+
a="1",
|
| 51 |
+
m="1",
|
| 52 |
+
varfunc="glim_v2",
|
| 53 |
+
link="glim_l02",
|
| 54 |
+
chi2type="Wald",
|
| 55 |
+
opt="moptimize",
|
| 56 |
+
title="Generalized linear models",
|
| 57 |
+
user="glim_lf",
|
| 58 |
+
crittype="log likelihood",
|
| 59 |
+
ml_method="e2",
|
| 60 |
+
singularHmethod="m-marquardt",
|
| 61 |
+
technique="nr",
|
| 62 |
+
which="max",
|
| 63 |
+
depvar="grade",
|
| 64 |
+
properties="b V",
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
params_table = np.array([
|
| 68 |
+
2.8261124216999, 1.2629410221647, 2.2377231969675, .02523911156938,
|
| 69 |
+
.35079350365878, 5.301431339741, np.nan, 1.9599639845401,
|
| 70 |
+
0, .09515765001172, .141554201358, .67223472774972,
|
| 71 |
+
.50143427587633, -.18228348651028, .37259878653373, np.nan,
|
| 72 |
+
1.9599639845401, 0, 2.3786875040587, 1.0645642078703,
|
| 73 |
+
2.2344237073472, .02545520725424, .29217999740245, 4.4651950107149,
|
| 74 |
+
np.nan, 1.9599639845401, 0, -13.021345912635,
|
| 75 |
+
4.931323890811, -2.6405375515688, .00827746189686, -22.686563134726,
|
| 76 |
+
-3.3561286905433, np.nan, 1.9599639845401, 0
|
| 77 |
+
]).reshape(4, 9)
|
| 78 |
+
|
| 79 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 80 |
+
|
| 81 |
+
params_table_rownames = 'gpa tuce psi _cons'.split()
|
| 82 |
+
|
| 83 |
+
cov = np.array([
|
| 84 |
+
1.5950200254665, -.03692058012179, .42761557297075, -4.5734780841711,
|
| 85 |
+
-.03692058012179, .0200375919221, .01491263753083, -.34625566662867,
|
| 86 |
+
.42761557297075, .01491263753083, 1.1332969526786, -2.3591604492672,
|
| 87 |
+
-4.5734780841711, -.34625566662867, -2.3591604492672, 24.317955316083
|
| 88 |
+
]).reshape(4, 4)
|
| 89 |
+
|
| 90 |
+
cov_colnames = 'gpa tuce psi _cons'.split()
|
| 91 |
+
|
| 92 |
+
cov_rownames = 'gpa tuce psi _cons'.split()
|
| 93 |
+
|
| 94 |
+
infocrit = np.array([
|
| 95 |
+
32, np.nan, -12.889634222131, 4,
|
| 96 |
+
33.779268444263, 39.642212055462])
|
| 97 |
+
|
| 98 |
+
infocrit_colnames = 'N ll0 ll df AIC BIC'.split()
|
| 99 |
+
|
| 100 |
+
infocrit_rownames = '.'.split()
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
results_noconstraint = ParamsTableTestBunch(
|
| 104 |
+
params_table=params_table,
|
| 105 |
+
params_table_colnames=params_table_colnames,
|
| 106 |
+
params_table_rownames=params_table_rownames,
|
| 107 |
+
cov=cov,
|
| 108 |
+
cov_colnames=cov_colnames,
|
| 109 |
+
cov_rownames=cov_rownames,
|
| 110 |
+
infocrit=infocrit,
|
| 111 |
+
infocrit_colnames=infocrit_colnames,
|
| 112 |
+
infocrit_rownames=infocrit_rownames,
|
| 113 |
+
**est
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
est = dict(
|
| 117 |
+
k_eq_model=0,
|
| 118 |
+
phi=1,
|
| 119 |
+
vf=1,
|
| 120 |
+
df=28,
|
| 121 |
+
df_m=3,
|
| 122 |
+
power=0,
|
| 123 |
+
canonical=1,
|
| 124 |
+
rank=4,
|
| 125 |
+
aic=1.055602138883215,
|
| 126 |
+
rc=0,
|
| 127 |
+
p=.0248623136764981,
|
| 128 |
+
chi2=9.360530997638559,
|
| 129 |
+
ll=-12.88963422213144,
|
| 130 |
+
k_autoCns=0,
|
| 131 |
+
converged=1,
|
| 132 |
+
k_dv=1,
|
| 133 |
+
k_eq=1,
|
| 134 |
+
k=4,
|
| 135 |
+
ic=3,
|
| 136 |
+
N=32,
|
| 137 |
+
nbml=0,
|
| 138 |
+
bic=-71.26133683412948,
|
| 139 |
+
dispers_ps=.9734684585933382,
|
| 140 |
+
deviance_ps=27.25711684061347,
|
| 141 |
+
dispers_p=.9734684585933382,
|
| 142 |
+
deviance_p=27.25711684061347,
|
| 143 |
+
dispers_s=.920688158723674,
|
| 144 |
+
deviance_s=25.77926844426287,
|
| 145 |
+
dispers=.920688158723674,
|
| 146 |
+
deviance=25.77926844426287,
|
| 147 |
+
cmdline="glm grade gpa tuce psi, family(binomial) vce(robust)",
|
| 148 |
+
cmd="glm",
|
| 149 |
+
predict="glim_p",
|
| 150 |
+
marginsnotok="stdp Anscombe Cooksd Deviance Hat Likelihood Pearson Response Score Working ADJusted STAndardized STUdentized MODified", # noqa:E501
|
| 151 |
+
marginsok="default",
|
| 152 |
+
hac_lag="30",
|
| 153 |
+
vcetype="Robust",
|
| 154 |
+
vce="robust",
|
| 155 |
+
linkt="Logit",
|
| 156 |
+
linkf="ln(u/(1-u))",
|
| 157 |
+
varfunct="Bernoulli",
|
| 158 |
+
varfuncf="u*(1-u)",
|
| 159 |
+
opt1="ML",
|
| 160 |
+
oim="oim",
|
| 161 |
+
a="1",
|
| 162 |
+
m="1",
|
| 163 |
+
varfunc="glim_v2",
|
| 164 |
+
link="glim_l02",
|
| 165 |
+
chi2type="Wald",
|
| 166 |
+
opt="moptimize",
|
| 167 |
+
title="Generalized linear models",
|
| 168 |
+
user="glim_lf",
|
| 169 |
+
crittype="log pseudolikelihood",
|
| 170 |
+
ml_method="e2",
|
| 171 |
+
singularHmethod="m-marquardt",
|
| 172 |
+
technique="nr",
|
| 173 |
+
which="max",
|
| 174 |
+
depvar="grade",
|
| 175 |
+
properties="b V",
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
params_table = np.array([
|
| 179 |
+
2.8261124216999, 1.287827879216, 2.1944799202672, .02820092594159,
|
| 180 |
+
.30201616014984, 5.3502086832499, np.nan, 1.9599639845401,
|
| 181 |
+
0, .09515765001172, .1198091371814, .79424367999287,
|
| 182 |
+
.42705358424294, -.13966394388263, .32997924390608, np.nan,
|
| 183 |
+
1.9599639845401, 0, 2.3786875040587, .97985082470462,
|
| 184 |
+
2.4276016757712, .01519902587997, .45821517741577, 4.2991598307016,
|
| 185 |
+
np.nan, 1.9599639845401, 0, -13.021345912635,
|
| 186 |
+
5.2807513766642, -2.4658130981467, .01367026437574, -23.371428422207,
|
| 187 |
+
-2.6712634030626, np.nan, 1.9599639845401, 0
|
| 188 |
+
]).reshape(4, 9)
|
| 189 |
+
|
| 190 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 191 |
+
|
| 192 |
+
params_table_rownames = 'gpa tuce psi _cons'.split()
|
| 193 |
+
|
| 194 |
+
cov = np.array([
|
| 195 |
+
1.6585006464861, .00630184631279, .20368998146717, -5.7738061195745,
|
| 196 |
+
.00630184631279, .01435422935215, .01997066738212, -.34768562593344,
|
| 197 |
+
.20368998146717, .01997066738212, .96010763867432, -1.5315997267117,
|
| 198 |
+
-5.7738061195745, -.34768562593344, -1.5315997267117, 27.886335102141
|
| 199 |
+
]).reshape(4, 4)
|
| 200 |
+
|
| 201 |
+
cov_colnames = 'gpa tuce psi _cons'.split()
|
| 202 |
+
|
| 203 |
+
cov_rownames = 'gpa tuce psi _cons'.split()
|
| 204 |
+
|
| 205 |
+
infocrit = np.array([
|
| 206 |
+
32, np.nan, -12.889634222131, 4,
|
| 207 |
+
33.779268444263, 39.642212055462])
|
| 208 |
+
|
| 209 |
+
infocrit_colnames = 'N ll0 ll df AIC BIC'.split()
|
| 210 |
+
|
| 211 |
+
infocrit_rownames = '.'.split()
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
results_noconstraint_robust = ParamsTableTestBunch(
|
| 215 |
+
params_table=params_table,
|
| 216 |
+
params_table_colnames=params_table_colnames,
|
| 217 |
+
params_table_rownames=params_table_rownames,
|
| 218 |
+
cov=cov,
|
| 219 |
+
cov_colnames=cov_colnames,
|
| 220 |
+
cov_rownames=cov_rownames,
|
| 221 |
+
infocrit=infocrit,
|
| 222 |
+
infocrit_colnames=infocrit_colnames,
|
| 223 |
+
infocrit_rownames=infocrit_rownames,
|
| 224 |
+
**est
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
est = dict(
|
| 228 |
+
k_eq_model=0,
|
| 229 |
+
phi=1,
|
| 230 |
+
vf=1,
|
| 231 |
+
df=29,
|
| 232 |
+
df_m=2,
|
| 233 |
+
power=0,
|
| 234 |
+
canonical=1,
|
| 235 |
+
rank=3,
|
| 236 |
+
aic=.993115540206396,
|
| 237 |
+
rc=0,
|
| 238 |
+
p=.0600760311411508,
|
| 239 |
+
chi2=5.624288666552698,
|
| 240 |
+
ll=-12.88984864330234,
|
| 241 |
+
k_autoCns=0,
|
| 242 |
+
converged=1,
|
| 243 |
+
k_dv=1,
|
| 244 |
+
k_eq=1,
|
| 245 |
+
k=4,
|
| 246 |
+
ic=3,
|
| 247 |
+
N=32,
|
| 248 |
+
nbml=0,
|
| 249 |
+
bic=-74.7266438945874,
|
| 250 |
+
dispers_ps=.9340711710496038,
|
| 251 |
+
deviance_ps=27.08806396043851,
|
| 252 |
+
dispers_p=.9340711710496038,
|
| 253 |
+
deviance_p=27.08806396043851,
|
| 254 |
+
dispers_s=.8889550788484368,
|
| 255 |
+
deviance_s=25.77969728660467,
|
| 256 |
+
dispers=.8889550788484368,
|
| 257 |
+
deviance=25.77969728660467,
|
| 258 |
+
cmdline="glm grade gpa tuce psi, family(binomial) constraints(1)",
|
| 259 |
+
cmd="glm",
|
| 260 |
+
predict="glim_p",
|
| 261 |
+
marginsnotok="stdp Anscombe Cooksd Deviance Hat Likelihood Pearson Response Score Working ADJusted STAndardized STUdentized MODified", # noqa:E501
|
| 262 |
+
marginsok="default",
|
| 263 |
+
hac_lag="30",
|
| 264 |
+
vcetype="OIM",
|
| 265 |
+
vce="oim",
|
| 266 |
+
linkt="Logit",
|
| 267 |
+
linkf="ln(u/(1-u))",
|
| 268 |
+
varfunct="Bernoulli",
|
| 269 |
+
varfuncf="u*(1-u)",
|
| 270 |
+
opt1="ML",
|
| 271 |
+
oim="oim",
|
| 272 |
+
a="1",
|
| 273 |
+
m="1",
|
| 274 |
+
varfunc="glim_v2",
|
| 275 |
+
link="glim_l02",
|
| 276 |
+
chi2type="Wald",
|
| 277 |
+
opt="moptimize",
|
| 278 |
+
title="Generalized linear models",
|
| 279 |
+
user="glim_lf",
|
| 280 |
+
crittype="log likelihood",
|
| 281 |
+
ml_method="e2",
|
| 282 |
+
singularHmethod="m-marquardt",
|
| 283 |
+
technique="nr",
|
| 284 |
+
which="max",
|
| 285 |
+
depvar="grade",
|
| 286 |
+
properties="b V",
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
params_table = np.array([
|
| 290 |
+
2.8, np.nan, np.nan, np.nan,
|
| 291 |
+
np.nan, np.nan, np.nan, 1.9599639845401,
|
| 292 |
+
0, .09576464077943, .13824841412912, .69269974185736,
|
| 293 |
+
.48849800113543, -.17519727183342, .36672655339228, np.nan,
|
| 294 |
+
1.9599639845401, 0, 2.3717067235827, 1.0071435928909,
|
| 295 |
+
2.3548843882081, .01852846934254, .39774155425619, 4.3456718929091,
|
| 296 |
+
np.nan, 1.9599639845401, 0, -12.946549758905,
|
| 297 |
+
3.3404275889275, -3.8757163309928, .00010631147941, -19.493667526167,
|
| 298 |
+
-6.3994319916434, np.nan, 1.9599639845401, 0
|
| 299 |
+
]).reshape(4, 9)
|
| 300 |
+
|
| 301 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 302 |
+
|
| 303 |
+
params_table_rownames = 'gpa tuce psi _cons'.split()
|
| 304 |
+
|
| 305 |
+
cov = np.array([
|
| 306 |
+
0, 0, 0, 0,
|
| 307 |
+
0, .01911262400922, .02461998233256, -.45036648979107,
|
| 308 |
+
0, .02461998233256, 1.0143382167012, -1.126241119498,
|
| 309 |
+
0, -.45036648979107, -1.126241119498, 11.158456476868
|
| 310 |
+
]).reshape(4, 4)
|
| 311 |
+
|
| 312 |
+
cov_colnames = 'gpa tuce psi _cons'.split()
|
| 313 |
+
|
| 314 |
+
cov_rownames = 'gpa tuce psi _cons'.split()
|
| 315 |
+
|
| 316 |
+
infocrit = np.array([
|
| 317 |
+
32, np.nan, -12.889848643302, 3,
|
| 318 |
+
31.779697286605, 36.176904995004])
|
| 319 |
+
|
| 320 |
+
infocrit_colnames = 'N ll0 ll df AIC BIC'.split()
|
| 321 |
+
|
| 322 |
+
infocrit_rownames = '.'.split()
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
results_constraint1 = ParamsTableTestBunch(
|
| 326 |
+
params_table=params_table,
|
| 327 |
+
params_table_colnames=params_table_colnames,
|
| 328 |
+
params_table_rownames=params_table_rownames,
|
| 329 |
+
cov=cov,
|
| 330 |
+
cov_colnames=cov_colnames,
|
| 331 |
+
cov_rownames=cov_rownames,
|
| 332 |
+
infocrit=infocrit,
|
| 333 |
+
infocrit_colnames=infocrit_colnames,
|
| 334 |
+
infocrit_rownames=infocrit_rownames,
|
| 335 |
+
**est
|
| 336 |
+
)
|
| 337 |
+
|
| 338 |
+
est = dict(
|
| 339 |
+
k_eq_model=0,
|
| 340 |
+
phi=1,
|
| 341 |
+
vf=1,
|
| 342 |
+
df=29,
|
| 343 |
+
df_m=2,
|
| 344 |
+
power=0,
|
| 345 |
+
canonical=1,
|
| 346 |
+
rank=3,
|
| 347 |
+
aic=.9965088127779717,
|
| 348 |
+
rc=0,
|
| 349 |
+
p=.0151376593316312,
|
| 350 |
+
chi2=8.381139289068923,
|
| 351 |
+
ll=-12.94414100444755,
|
| 352 |
+
k_autoCns=0,
|
| 353 |
+
converged=1,
|
| 354 |
+
k_dv=1,
|
| 355 |
+
k_eq=1,
|
| 356 |
+
k=4,
|
| 357 |
+
ic=3,
|
| 358 |
+
N=32,
|
| 359 |
+
nbml=0,
|
| 360 |
+
bic=-74.61805917229698,
|
| 361 |
+
dispers_ps=.9101961406899989,
|
| 362 |
+
deviance_ps=26.39568808000997,
|
| 363 |
+
dispers_p=.9101961406899989,
|
| 364 |
+
deviance_p=26.39568808000997,
|
| 365 |
+
dispers_s=.892699379617072,
|
| 366 |
+
deviance_s=25.88828200889509,
|
| 367 |
+
dispers=.892699379617072,
|
| 368 |
+
deviance=25.88828200889509,
|
| 369 |
+
cmdline="glm grade gpa tuce psi, family(binomial) constraints(2)",
|
| 370 |
+
cmd="glm",
|
| 371 |
+
predict="glim_p",
|
| 372 |
+
marginsnotok="stdp Anscombe Cooksd Deviance Hat Likelihood Pearson Response Score Working ADJusted STAndardized STUdentized MODified", # noqa:E501
|
| 373 |
+
marginsok="default",
|
| 374 |
+
hac_lag="30",
|
| 375 |
+
vcetype="OIM",
|
| 376 |
+
vce="oim",
|
| 377 |
+
linkt="Logit",
|
| 378 |
+
linkf="ln(u/(1-u))",
|
| 379 |
+
varfunct="Bernoulli",
|
| 380 |
+
varfuncf="u*(1-u)",
|
| 381 |
+
opt1="ML",
|
| 382 |
+
oim="oim",
|
| 383 |
+
a="1",
|
| 384 |
+
m="1",
|
| 385 |
+
varfunc="glim_v2",
|
| 386 |
+
link="glim_l02",
|
| 387 |
+
chi2type="Wald",
|
| 388 |
+
opt="moptimize",
|
| 389 |
+
title="Generalized linear models",
|
| 390 |
+
user="glim_lf",
|
| 391 |
+
crittype="log likelihood",
|
| 392 |
+
ml_method="e2",
|
| 393 |
+
singularHmethod="m-marquardt",
|
| 394 |
+
technique="nr",
|
| 395 |
+
which="max",
|
| 396 |
+
depvar="grade",
|
| 397 |
+
properties="b V",
|
| 398 |
+
)
|
| 399 |
+
|
| 400 |
+
params_table = np.array([
|
| 401 |
+
2.5537914524884, .92662050289421, 2.7560273537138, .00585081038138,
|
| 402 |
+
.73764863947939, 4.3699342654975, np.nan, 1.9599639845401,
|
| 403 |
+
0, .10791139824293, .13554656123081, .79612051580696,
|
| 404 |
+
.42596199070477, -.15775497999771, .37357777648357, np.nan,
|
| 405 |
+
1.9599639845401, 0, 2.5537914524884, .92662050289421,
|
| 406 |
+
2.7560273537138, .00585081038138, .73764863947939, 4.3699342654975,
|
| 407 |
+
np.nan, 1.9599639845401, 0, -12.527922070831,
|
| 408 |
+
4.6393777844052, -2.7003453163357, .00692675392223, -21.62093543894,
|
| 409 |
+
-3.4349087027211, np.nan, 1.9599639845401, 0
|
| 410 |
+
]).reshape(4, 9)
|
| 411 |
+
|
| 412 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 413 |
+
|
| 414 |
+
params_table_rownames = 'gpa tuce psi _cons'.split()
|
| 415 |
+
|
| 416 |
+
cov = np.array([
|
| 417 |
+
.85862555638391, -.00408642741742, .85862555638391, -3.1725052764862,
|
| 418 |
+
-.00408642741742, .0183728702615, -.00408642741742, -.40376368789892,
|
| 419 |
+
.85862555638391, -.00408642741742, .85862555638391, -3.1725052764862,
|
| 420 |
+
-3.1725052764862, -.40376368789892, -3.1725052764862, 21.523826226433
|
| 421 |
+
]).reshape(4, 4)
|
| 422 |
+
|
| 423 |
+
cov_colnames = 'gpa tuce psi _cons'.split()
|
| 424 |
+
|
| 425 |
+
cov_rownames = 'gpa tuce psi _cons'.split()
|
| 426 |
+
|
| 427 |
+
infocrit = np.array([
|
| 428 |
+
32, np.nan, -12.944141004448, 3,
|
| 429 |
+
31.888282008895, 36.285489717294])
|
| 430 |
+
|
| 431 |
+
infocrit_colnames = 'N ll0 ll df AIC BIC'.split()
|
| 432 |
+
|
| 433 |
+
infocrit_rownames = '.'.split()
|
| 434 |
+
|
| 435 |
+
predict_mu = np.array([
|
| 436 |
+
.02720933393726, .05877785527304, .17341537851768, .02240274574181,
|
| 437 |
+
.48834788561471, .03262255746648, .02545734725406, .05057489993471,
|
| 438 |
+
.10986224061161, .64848146294279, .02525325609066, .17259131542841,
|
| 439 |
+
.28314297612096, .18171413480391, .33018645131295, .02988039105483,
|
| 440 |
+
.05693576903037, .03731338966779, .61672273095571, .68861137241716,
|
| 441 |
+
.08792248035539, .90822178043053, .25295501355621, .85758484919326,
|
| 442 |
+
.83972248507748, .54158048311843, .62661357692624, .36224489285202,
|
| 443 |
+
.83387563062407, .93837010344092, .55200183830167, .13940358008872
|
| 444 |
+
])
|
| 445 |
+
|
| 446 |
+
predict_mu_colnames = 'predict_mu'.split()
|
| 447 |
+
|
| 448 |
+
predict_mu_rownames = ['r'+str(n) for n in range(1, 33)]
|
| 449 |
+
|
| 450 |
+
predict_linpred_std = np.array([
|
| 451 |
+
1.2186852972383, .98250143329647, .71300625338041, 1.7281112031272,
|
| 452 |
+
.58278126610648, 1.2588643933597, 1.323097466817, 1.0187451680624,
|
| 453 |
+
.92583226681839, .97445803529749, 1.2426520057509, .66674211884633,
|
| 454 |
+
.53877733839827, .77006015103931, .70670367147137, 1.2036701125873,
|
| 455 |
+
1.1407798755705, 1.1376397495763, .57331962577752, .65764380198652,
|
| 456 |
+
.85122884445037, 1.1282943138296, 1.2981327331615, .91561885084703,
|
| 457 |
+
.8524827403359, .75030433039358, 1.0902299962647, .53350768600347,
|
| 458 |
+
.96511132361274, 1.2127047415358, .61923877005984, .80300912367498
|
| 459 |
+
])
|
| 460 |
+
|
| 461 |
+
predict_linpred_std_colnames = 'predict_linpred_std'.split()
|
| 462 |
+
|
| 463 |
+
predict_linpred_std_rownames = ['r'+str(n) for n in range(1, 33)]
|
| 464 |
+
|
| 465 |
+
predict_hat = np.array([
|
| 466 |
+
.03931157544567, .05340381182541, .07287215399916, .06540404284993,
|
| 467 |
+
.0848623883214, .0500117280211, .04343078449564, .04983412818394,
|
| 468 |
+
.08382437063813, .21645722203914, .03801090644315, .06348261316195,
|
| 469 |
+
.05891921860299, .08817451110282, .11045563375857, .04199779738721,
|
| 470 |
+
.06987634275981, .04648995770552, .0776956378885, .09273814423054,
|
| 471 |
+
.05810645039404, .10611489289649, .31844046474321, .10239122636412,
|
| 472 |
+
.09780916971071, .13976583081559, .27809589396914, .06575633167064,
|
| 473 |
+
.12902962938834, .08505028097419, .09482722348113, .07735963673184
|
| 474 |
+
])
|
| 475 |
+
|
| 476 |
+
predict_hat_colnames = 'predict_hat'.split()
|
| 477 |
+
|
| 478 |
+
predict_hat_rownames = ['r'+str(n) for n in range(1, 33)]
|
| 479 |
+
|
| 480 |
+
|
| 481 |
+
results_constraint2 = ParamsTableTestBunch(
|
| 482 |
+
params_table=params_table,
|
| 483 |
+
params_table_colnames=params_table_colnames,
|
| 484 |
+
params_table_rownames=params_table_rownames,
|
| 485 |
+
cov=cov,
|
| 486 |
+
cov_colnames=cov_colnames,
|
| 487 |
+
cov_rownames=cov_rownames,
|
| 488 |
+
infocrit=infocrit,
|
| 489 |
+
infocrit_colnames=infocrit_colnames,
|
| 490 |
+
infocrit_rownames=infocrit_rownames,
|
| 491 |
+
predict_mu=predict_mu,
|
| 492 |
+
predict_mu_colnames=predict_mu_colnames,
|
| 493 |
+
predict_mu_rownames=predict_mu_rownames,
|
| 494 |
+
predict_linpred_std=predict_linpred_std,
|
| 495 |
+
predict_linpred_std_colnames=predict_linpred_std_colnames,
|
| 496 |
+
predict_linpred_std_rownames=predict_linpred_std_rownames,
|
| 497 |
+
predict_hat=predict_hat,
|
| 498 |
+
predict_hat_colnames=predict_hat_colnames,
|
| 499 |
+
predict_hat_rownames=predict_hat_rownames,
|
| 500 |
+
**est
|
| 501 |
+
)
|
| 502 |
+
|
| 503 |
+
est = dict(
|
| 504 |
+
k_eq_model=0,
|
| 505 |
+
phi=1,
|
| 506 |
+
vf=1,
|
| 507 |
+
df=29,
|
| 508 |
+
df_m=2,
|
| 509 |
+
power=0,
|
| 510 |
+
canonical=1,
|
| 511 |
+
rank=3,
|
| 512 |
+
aic=.9965088127779717,
|
| 513 |
+
rc=0,
|
| 514 |
+
p=.0085760854232441,
|
| 515 |
+
chi2=9.517555427941099,
|
| 516 |
+
ll=-12.94414100444755,
|
| 517 |
+
k_autoCns=0,
|
| 518 |
+
converged=1,
|
| 519 |
+
k_dv=1,
|
| 520 |
+
k_eq=1,
|
| 521 |
+
k=4,
|
| 522 |
+
ic=3,
|
| 523 |
+
N=32,
|
| 524 |
+
nbml=0,
|
| 525 |
+
bic=-74.61805917229698,
|
| 526 |
+
dispers_ps=.9101961406899989,
|
| 527 |
+
deviance_ps=26.39568808000997,
|
| 528 |
+
dispers_p=.9101961406899989,
|
| 529 |
+
deviance_p=26.39568808000997,
|
| 530 |
+
dispers_s=.892699379617072,
|
| 531 |
+
deviance_s=25.88828200889509,
|
| 532 |
+
dispers=.892699379617072,
|
| 533 |
+
deviance=25.88828200889509,
|
| 534 |
+
cmdline="glm grade gpa tuce psi, family(binomial) constraints(2) vce(robust)", # noqa:E501
|
| 535 |
+
cmd="glm",
|
| 536 |
+
predict="glim_p",
|
| 537 |
+
marginsnotok="stdp Anscombe Cooksd Deviance Hat Likelihood Pearson Response Score Working ADJusted STAndardized STUdentized MODified", # noqa:E501
|
| 538 |
+
marginsok="default",
|
| 539 |
+
hac_lag="30",
|
| 540 |
+
vcetype="Robust",
|
| 541 |
+
vce="robust",
|
| 542 |
+
linkt="Logit",
|
| 543 |
+
linkf="ln(u/(1-u))",
|
| 544 |
+
varfunct="Bernoulli",
|
| 545 |
+
varfuncf="u*(1-u)",
|
| 546 |
+
opt1="ML",
|
| 547 |
+
oim="oim",
|
| 548 |
+
a="1",
|
| 549 |
+
m="1",
|
| 550 |
+
varfunc="glim_v2",
|
| 551 |
+
link="glim_l02",
|
| 552 |
+
chi2type="Wald",
|
| 553 |
+
opt="moptimize",
|
| 554 |
+
title="Generalized linear models",
|
| 555 |
+
user="glim_lf",
|
| 556 |
+
crittype="log pseudolikelihood",
|
| 557 |
+
ml_method="e2",
|
| 558 |
+
singularHmethod="m-marquardt",
|
| 559 |
+
technique="nr",
|
| 560 |
+
which="max",
|
| 561 |
+
depvar="grade",
|
| 562 |
+
properties="b V",
|
| 563 |
+
)
|
| 564 |
+
|
| 565 |
+
params_table = np.array([
|
| 566 |
+
2.5537914524884, .83609404798719, 3.0544308485827, .00225487991353,
|
| 567 |
+
.91507723074524, 4.1925056742316, np.nan, 1.9599639845401,
|
| 568 |
+
0, .10791139824293, .12275592600281, .8790728216287,
|
| 569 |
+
.37936179287834, -.13268579561143, .3485085920973, np.nan,
|
| 570 |
+
1.9599639845401, 0, 2.5537914524884, .83609404798719,
|
| 571 |
+
3.0544308485827, .00225487991353, .91507723074524, 4.1925056742316,
|
| 572 |
+
np.nan, 1.9599639845401, 0, -12.527922070831,
|
| 573 |
+
4.510414281113, -2.7775546302454, .00547696322683, -21.368171617167,
|
| 574 |
+
-3.6876725244938, np.nan, 1.9599639845401, 0
|
| 575 |
+
]).reshape(4, 9)
|
| 576 |
+
|
| 577 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 578 |
+
|
| 579 |
+
params_table_rownames = 'gpa tuce psi _cons'.split()
|
| 580 |
+
|
| 581 |
+
cov = np.array([
|
| 582 |
+
.6990532570796, .01512804251258, .6990532570796, -2.9662622048441,
|
| 583 |
+
.01512804251258, .01506901736881, .01512804251258, -.3968065659911,
|
| 584 |
+
.6990532570796, .01512804251258, .6990532570796, -2.9662622048441,
|
| 585 |
+
-2.9662622048441, -.3968065659911, -2.9662622048441, 20.343836987269
|
| 586 |
+
]).reshape(4, 4)
|
| 587 |
+
|
| 588 |
+
cov_colnames = 'gpa tuce psi _cons'.split()
|
| 589 |
+
|
| 590 |
+
cov_rownames = 'gpa tuce psi _cons'.split()
|
| 591 |
+
|
| 592 |
+
infocrit = np.array([
|
| 593 |
+
32, np.nan, -12.944141004448, 3,
|
| 594 |
+
31.888282008895, 36.285489717294])
|
| 595 |
+
|
| 596 |
+
infocrit_colnames = 'N ll0 ll df AIC BIC'.split()
|
| 597 |
+
|
| 598 |
+
infocrit_rownames = '.'.split()
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
results_constraint2_robust = ParamsTableTestBunch(
|
| 602 |
+
params_table=params_table,
|
| 603 |
+
params_table_colnames=params_table_colnames,
|
| 604 |
+
params_table_rownames=params_table_rownames,
|
| 605 |
+
cov=cov,
|
| 606 |
+
cov_colnames=cov_colnames,
|
| 607 |
+
cov_rownames=cov_rownames,
|
| 608 |
+
infocrit=infocrit,
|
| 609 |
+
infocrit_colnames=infocrit_colnames,
|
| 610 |
+
infocrit_rownames=infocrit_rownames,
|
| 611 |
+
**est
|
| 612 |
+
)
|
| 613 |
+
|
| 614 |
+
est = dict(
|
| 615 |
+
N_cds=0,
|
| 616 |
+
N_cdf=0,
|
| 617 |
+
p=.0151376589433054,
|
| 618 |
+
chi2=8.381139340374848,
|
| 619 |
+
df_m=2,
|
| 620 |
+
k_eq_model=1,
|
| 621 |
+
ll=-12.94414100444751,
|
| 622 |
+
k_autoCns=0,
|
| 623 |
+
rc=0,
|
| 624 |
+
converged=1,
|
| 625 |
+
k_dv=1,
|
| 626 |
+
k_eq=1,
|
| 627 |
+
k=4,
|
| 628 |
+
ic=5,
|
| 629 |
+
N=32,
|
| 630 |
+
rank=3,
|
| 631 |
+
cmdline="logit grade gpa tuce psi, constraints(2)",
|
| 632 |
+
cmd="logit",
|
| 633 |
+
estat_cmd="logit_estat",
|
| 634 |
+
predict="logit_p",
|
| 635 |
+
marginsnotok="stdp DBeta DEviance DX2 DDeviance Hat Number Residuals RStandard SCore", # noqa:E501
|
| 636 |
+
title="Logistic regression",
|
| 637 |
+
chi2type="Wald",
|
| 638 |
+
opt="moptimize",
|
| 639 |
+
vce="oim",
|
| 640 |
+
user="mopt__logit_d2()",
|
| 641 |
+
crittype="log likelihood",
|
| 642 |
+
ml_method="d2",
|
| 643 |
+
singularHmethod="m-marquardt",
|
| 644 |
+
technique="nr",
|
| 645 |
+
which="max",
|
| 646 |
+
depvar="grade",
|
| 647 |
+
properties="b V",
|
| 648 |
+
)
|
| 649 |
+
|
| 650 |
+
params_table = np.array([
|
| 651 |
+
2.5537916456996, .92662056628814, 2.7560273736742, .00585081002433,
|
| 652 |
+
.73764870844071, 4.3699345829585, np.nan, 1.9599639845401,
|
| 653 |
+
0, .10791141442743, .13554656655573, .79612060393329,
|
| 654 |
+
.42596193948753, -.15775497424986, .37357780310472, np.nan,
|
| 655 |
+
1.9599639845401, 0, 2.5537916456996, .92662056628814,
|
| 656 |
+
2.7560273736742, .00585081002433, .73764870844071, 4.3699345829585,
|
| 657 |
+
np.nan, 1.9599639845401, 0, -12.527923225554,
|
| 658 |
+
4.6393781670436, -2.7003453425175, .00692675337706, -21.62093734362,
|
| 659 |
+
-3.4349091074867, np.nan, 1.9599639845401, 0
|
| 660 |
+
]).reshape(4, 9)
|
| 661 |
+
|
| 662 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 663 |
+
|
| 664 |
+
params_table_rownames = 'gpa tuce psi _cons'.split()
|
| 665 |
+
|
| 666 |
+
cov = np.array([
|
| 667 |
+
.85862567386816, -.00408642236043, .85862567386816, -3.172505858545,
|
| 668 |
+
-.00408642236043, .01837287170505, -.00408642236043, -.40376374127778,
|
| 669 |
+
.85862567386816, -.00408642236043, .85862567386816, -3.172505858545,
|
| 670 |
+
-3.172505858545, -.40376374127778, -3.172505858545, 21.523829776841
|
| 671 |
+
]).reshape(4, 4)
|
| 672 |
+
|
| 673 |
+
cov_colnames = 'gpa tuce psi _cons'.split()
|
| 674 |
+
|
| 675 |
+
cov_rownames = 'gpa tuce psi _cons'.split()
|
| 676 |
+
|
| 677 |
+
infocrit = np.array([
|
| 678 |
+
32, np.nan, -12.944141004448, 3,
|
| 679 |
+
31.888282008895, 36.285489717294])
|
| 680 |
+
|
| 681 |
+
infocrit_colnames = 'N ll0 ll df AIC BIC'.split()
|
| 682 |
+
|
| 683 |
+
infocrit_rownames = '.'.split()
|
| 684 |
+
|
| 685 |
+
|
| 686 |
+
results_logit_constraint2 = ParamsTableTestBunch(
|
| 687 |
+
params_table=params_table,
|
| 688 |
+
params_table_colnames=params_table_colnames,
|
| 689 |
+
params_table_rownames=params_table_rownames,
|
| 690 |
+
cov=cov,
|
| 691 |
+
cov_colnames=cov_colnames,
|
| 692 |
+
cov_rownames=cov_rownames,
|
| 693 |
+
infocrit=infocrit,
|
| 694 |
+
infocrit_colnames=infocrit_colnames,
|
| 695 |
+
infocrit_rownames=infocrit_rownames,
|
| 696 |
+
**est
|
| 697 |
+
)
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_poisson_constrained.py
ADDED
|
@@ -0,0 +1,665 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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10 |
+
k_eq=1,
|
| 11 |
+
k_dv=1,
|
| 12 |
+
converged=1,
|
| 13 |
+
rc=0,
|
| 14 |
+
k_autoCns=1,
|
| 15 |
+
ll=-33.45804471711131,
|
| 16 |
+
k_eq_model=1,
|
| 17 |
+
ll_0=-349.6684656479622,
|
| 18 |
+
df_m=6,
|
| 19 |
+
chi2=632.4208418617018,
|
| 20 |
+
p=2.3617193197e-133,
|
| 21 |
+
r2_p=.9043149497192691,
|
| 22 |
+
cmdline="poisson deaths lnpyears smokes i.agecat",
|
| 23 |
+
cmd="poisson",
|
| 24 |
+
predict="poisso_p",
|
| 25 |
+
estat_cmd="poisson_estat",
|
| 26 |
+
gof="poiss_g",
|
| 27 |
+
chi2type="LR",
|
| 28 |
+
opt="moptimize",
|
| 29 |
+
vce="oim",
|
| 30 |
+
title="Poisson regression",
|
| 31 |
+
user="poiss_lf",
|
| 32 |
+
crittype="log likelihood",
|
| 33 |
+
ml_method="e2",
|
| 34 |
+
singularHmethod="m-marquardt",
|
| 35 |
+
technique="nr",
|
| 36 |
+
which="max",
|
| 37 |
+
depvar="deaths",
|
| 38 |
+
properties="b V",
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
params_table = np.array([
|
| 42 |
+
.66308184237808, .63593388706566, 1.0426899019923, .29709193621918,
|
| 43 |
+
-.58332567281917, 1.9094893575753, np.nan, 1.9599639845401,
|
| 44 |
+
0, .84966723812924, .94279599903649, .90122066597395,
|
| 45 |
+
.36747100512904, -.99817896475073, 2.6975134410092, np.nan,
|
| 46 |
+
1.9599639845401, 0, 0, np.nan,
|
| 47 |
+
np.nan, np.nan, np.nan, np.nan,
|
| 48 |
+
np.nan, 1.9599639845401, 0, 1.3944392032504,
|
| 49 |
+
.25613243411925, 5.4442117338454, 5.203529593e-08, .8924288571041,
|
| 50 |
+
1.8964495493967, np.nan, 1.9599639845401, 0,
|
| 51 |
+
2.389284381366, .48305517266329, 4.9461935542328, 7.567871319e-07,
|
| 52 |
+
1.4425136404002, 3.3360551223318, np.nan, 1.9599639845401,
|
| 53 |
+
0, 2.8385093615484, .98099727008295, 2.8934936397003,
|
| 54 |
+
.00380982006764, .91579004325369, 4.7612286798431, np.nan,
|
| 55 |
+
1.9599639845401, 0, 2.9103531988515, 1.500316321385,
|
| 56 |
+
1.9398263935201, .05240079188831, -.03021275648066, 5.8509191541838,
|
| 57 |
+
np.nan, 1.9599639845401, 0, -4.724924181641,
|
| 58 |
+
6.0276019460727, -.78388125558284, .43310978942119, -16.538806909087,
|
| 59 |
+
7.088958545805, np.nan, 1.9599639845401, 0
|
| 60 |
+
]).reshape(8, 9)
|
| 61 |
+
|
| 62 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 63 |
+
|
| 64 |
+
params_table_rownames = ['lnpyears', 'smokes', '1b.agecat', '2.agecat',
|
| 65 |
+
'3.agecat', '4.agecat', '5.agecat', '_cons']
|
| 66 |
+
|
| 67 |
+
cov = np.array([
|
| 68 |
+
.40441190871844, -.59566294916097, 0, .1055698685775,
|
| 69 |
+
.28413388045122, .61269322798077, .94624135329227, -3.8311942353131,
|
| 70 |
+
-.59566294916097, .88886429579921, 0, -.15587944298625,
|
| 71 |
+
-.4190789999425, -.90299843943229, -1.3940094688194, 5.6335527795822,
|
| 72 |
+
0, 0, 0, 0,
|
| 73 |
+
0, 0, 0, 0,
|
| 74 |
+
.1055698685775, -.15587944298625, 0, .06560382380785,
|
| 75 |
+
.10360281461667, .18937107288073, .27643306166968, -1.029211453947,
|
| 76 |
+
.28413388045122, -.4190789999425, 0, .10360281461667,
|
| 77 |
+
.23334229983676, .45990880867889, .69424104947043, -2.7206801001387,
|
| 78 |
+
.61269322798077, -.90299843943229, 0, .18937107288073,
|
| 79 |
+
.45990880867889, .96235564391021, 1.4630024143274, -5.8333014154113,
|
| 80 |
+
.94624135329227, -1.3940094688194, 0, .27643306166968,
|
| 81 |
+
.69424104947043, 1.4630024143274, 2.2509490642142, -8.993394678922,
|
| 82 |
+
-3.8311942353131, 5.6335527795822, 0, -1.029211453947,
|
| 83 |
+
-2.7206801001387, -5.8333014154113, -8.993394678922, 36.331985220299
|
| 84 |
+
]).reshape(8, 8)
|
| 85 |
+
|
| 86 |
+
cov_colnames = ['lnpyears', 'smokes', '1b.agecat', '2.agecat',
|
| 87 |
+
'3.agecat', '4.agecat', '5.agecat', '_cons']
|
| 88 |
+
|
| 89 |
+
cov_rownames = ['lnpyears', 'smokes', '1b.agecat', '2.agecat',
|
| 90 |
+
'3.agecat', '4.agecat', '5.agecat', '_cons']
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
results_noexposure_noconstraint = ParamsTableTestBunch(
|
| 94 |
+
params_table=params_table,
|
| 95 |
+
params_table_colnames=params_table_colnames,
|
| 96 |
+
params_table_rownames=params_table_rownames,
|
| 97 |
+
cov=cov,
|
| 98 |
+
cov_colnames=cov_colnames,
|
| 99 |
+
cov_rownames=cov_rownames,
|
| 100 |
+
**est
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
est = dict(
|
| 104 |
+
rank=6,
|
| 105 |
+
N=10,
|
| 106 |
+
ic=3,
|
| 107 |
+
k=7,
|
| 108 |
+
k_eq=1,
|
| 109 |
+
k_dv=1,
|
| 110 |
+
converged=1,
|
| 111 |
+
rc=0,
|
| 112 |
+
k_autoCns=1,
|
| 113 |
+
ll=-33.6001534405213,
|
| 114 |
+
k_eq_model=1,
|
| 115 |
+
ll_0=-495.0676356770329,
|
| 116 |
+
df_m=5,
|
| 117 |
+
chi2=922.9349644730232,
|
| 118 |
+
p=2.8920463572e-197,
|
| 119 |
+
r2_p=.9321301757191799,
|
| 120 |
+
cmdline="poisson deaths smokes i.agecat, exposure(pyears)",
|
| 121 |
+
cmd="poisson",
|
| 122 |
+
predict="poisso_p",
|
| 123 |
+
estat_cmd="poisson_estat",
|
| 124 |
+
offset="ln(pyears)",
|
| 125 |
+
gof="poiss_g",
|
| 126 |
+
chi2type="LR",
|
| 127 |
+
opt="moptimize",
|
| 128 |
+
vce="oim",
|
| 129 |
+
title="Poisson regression",
|
| 130 |
+
user="poiss_lf",
|
| 131 |
+
crittype="log likelihood",
|
| 132 |
+
ml_method="e2",
|
| 133 |
+
singularHmethod="m-marquardt",
|
| 134 |
+
technique="nr",
|
| 135 |
+
which="max",
|
| 136 |
+
depvar="deaths",
|
| 137 |
+
properties="b V",
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
params_table = np.array([
|
| 141 |
+
.35453563725291, .10737411818853, 3.3018723993653, .00096041750265,
|
| 142 |
+
.14408623273163, .56498504177418, np.nan, 1.9599639845401,
|
| 143 |
+
0, 0, np.nan, np.nan,
|
| 144 |
+
np.nan, np.nan, np.nan, np.nan,
|
| 145 |
+
1.9599639845401, 0, 1.4840070063099, .19510337263434,
|
| 146 |
+
7.606260139291, 2.821411159e-14, 1.1016114226842, 1.8664025899355,
|
| 147 |
+
np.nan, 1.9599639845401, 0, 2.6275051184579,
|
| 148 |
+
.18372726944827, 14.301116684248, 2.153264398e-46, 2.2674062873614,
|
| 149 |
+
2.9876039495544, np.nan, 1.9599639845401, 0,
|
| 150 |
+
3.350492785161, .18479918093323, 18.130452571495, 1.832448146e-73,
|
| 151 |
+
2.9882930461593, 3.7126925241626, np.nan, 1.9599639845401,
|
| 152 |
+
0, 3.7000964518246, .19221951212105, 19.24932807807,
|
| 153 |
+
1.430055953e-82, 3.3233531309415, 4.0768397727077, np.nan,
|
| 154 |
+
1.9599639845401, 0, -7.919325711822, .19176181876223,
|
| 155 |
+
-41.297719029467, 0, -8.2951719702059, -7.5434794534381,
|
| 156 |
+
np.nan, 1.9599639845401, 0]).reshape(7, 9)
|
| 157 |
+
|
| 158 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 159 |
+
|
| 160 |
+
params_table_rownames = ['smokes', '1b.agecat', '2.agecat', '3.agecat',
|
| 161 |
+
'4.agecat', '5.agecat', '_cons']
|
| 162 |
+
|
| 163 |
+
cov = np.array([
|
| 164 |
+
.01152920125677, 0, -.00061561668833, -.00090117889461,
|
| 165 |
+
-.00087280941113, -.00045274641397, -.00921219275997, 0,
|
| 166 |
+
0, 0, 0, 0,
|
| 167 |
+
0, 0, -.00061561668833, 0,
|
| 168 |
+
.0380653260133, .02945988432334, .02945836949789, .0294359396881,
|
| 169 |
+
-.0289198676971, -.00090117889461, 0, .02945988432334,
|
| 170 |
+
.03375570953892, .0294799877675, .02944715358419, -.02869169455392,
|
| 171 |
+
-.00087280941113, 0, .02945836949789, .0294799877675,
|
| 172 |
+
.03415073727359, .02944603952766, -.02871436265941, -.00045274641397,
|
| 173 |
+
0, .0294359396881, .02944715358419, .02944603952766,
|
| 174 |
+
.03694834084006, -.02905000614546, -.00921219275997, 0,
|
| 175 |
+
-.0289198676971, -.02869169455392, -.02871436265941, -.02905000614546,
|
| 176 |
+
.036772595135]).reshape(7, 7)
|
| 177 |
+
|
| 178 |
+
cov_colnames = ['smokes', '1b.agecat', '2.agecat', '3.agecat',
|
| 179 |
+
'4.agecat', '5.agecat', '_cons']
|
| 180 |
+
|
| 181 |
+
cov_rownames = ['smokes', '1b.agecat', '2.agecat', '3.agecat',
|
| 182 |
+
'4.agecat', '5.agecat', '_cons']
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
results_exposure_noconstraint = ParamsTableTestBunch(
|
| 186 |
+
params_table=params_table,
|
| 187 |
+
params_table_colnames=params_table_colnames,
|
| 188 |
+
params_table_rownames=params_table_rownames,
|
| 189 |
+
cov=cov,
|
| 190 |
+
cov_colnames=cov_colnames,
|
| 191 |
+
cov_rownames=cov_rownames,
|
| 192 |
+
**est
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
est = dict(
|
| 196 |
+
rank=6,
|
| 197 |
+
N=10,
|
| 198 |
+
ic=4,
|
| 199 |
+
k=8,
|
| 200 |
+
k_eq=1,
|
| 201 |
+
k_dv=1,
|
| 202 |
+
converged=1,
|
| 203 |
+
rc=0,
|
| 204 |
+
k_autoCns=1,
|
| 205 |
+
ll=-33.46699798755848,
|
| 206 |
+
k_eq_model=1,
|
| 207 |
+
df_m=5,
|
| 208 |
+
chi2=452.5895246742914,
|
| 209 |
+
p=1.35732711092e-95,
|
| 210 |
+
r2_p=np.nan,
|
| 211 |
+
cmdline="poisson deaths lnpyears smokes i.agecat, constraints(1)",
|
| 212 |
+
cmd="poisson",
|
| 213 |
+
predict="poisso_p",
|
| 214 |
+
estat_cmd="poisson_estat",
|
| 215 |
+
gof="poiss_g",
|
| 216 |
+
chi2type="Wald",
|
| 217 |
+
opt="moptimize",
|
| 218 |
+
vce="oim",
|
| 219 |
+
title="Poisson regression",
|
| 220 |
+
user="poiss_lf",
|
| 221 |
+
crittype="log likelihood",
|
| 222 |
+
ml_method="e2",
|
| 223 |
+
singularHmethod="m-marquardt",
|
| 224 |
+
technique="nr",
|
| 225 |
+
which="max",
|
| 226 |
+
depvar="deaths",
|
| 227 |
+
properties="b V",
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
params_table = np.array([
|
| 231 |
+
.57966535352347, .13107152221057, 4.4225117992619, 9.756001957e-06,
|
| 232 |
+
.32276989059191, .83656081645503, np.nan, 1.9599639845401,
|
| 233 |
+
0, .97254074124891, .22289894431919, 4.3631464663029,
|
| 234 |
+
.00001282050472, .5356668381913, 1.4094146443065, np.nan,
|
| 235 |
+
1.9599639845401, 0, 0, np.nan,
|
| 236 |
+
np.nan, np.nan, np.nan, np.nan,
|
| 237 |
+
np.nan, 1.9599639845401, 0, 1.3727621378494,
|
| 238 |
+
.19798042377276, 6.9338276567436, 4.096036246e-12, .98472763761078,
|
| 239 |
+
1.760796638088, np.nan, 1.9599639845401, 0,
|
| 240 |
+
2.3307703209845, .20530981936838, 11.352454199, 7.210981748e-30,
|
| 241 |
+
1.92837046935, 2.7331701726189, np.nan, 1.9599639845401,
|
| 242 |
+
0, 2.71338890728, .29962471107816, 9.0559583604312,
|
| 243 |
+
1.353737255e-19, 2.1261352646886, 3.3006425498714, np.nan,
|
| 244 |
+
1.9599639845401, 0, 2.71338890728, .29962471107816,
|
| 245 |
+
9.0559583604312, 1.353737255e-19, 2.1261352646886, 3.3006425498714,
|
| 246 |
+
np.nan, 1.9599639845401, 0, -3.9347864312059,
|
| 247 |
+
1.2543868840549, -3.1368204508696, .00170790683415, -6.3933395466329,
|
| 248 |
+
-1.476233315779, np.nan, 1.9599639845401, 0
|
| 249 |
+
]).reshape(8, 9)
|
| 250 |
+
|
| 251 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 252 |
+
|
| 253 |
+
params_table_rownames = ['lnpyears', 'smokes', '1b.agecat', '2.agecat',
|
| 254 |
+
'3.agecat', '4.agecat', '5.agecat', '_cons']
|
| 255 |
+
|
| 256 |
+
cov = np.array([
|
| 257 |
+
.0171797439346, -.02561346650005, 0, .00445310785396,
|
| 258 |
+
.01204526460873, .03142116278001, .03142116278001, -.16245493266167,
|
| 259 |
+
-.02561346650005, .04968393937861, 0, -.0069699735991,
|
| 260 |
+
-.01845598801461, -.04723465558226, -.04723465558226, .2326939064726,
|
| 261 |
+
0, 0, 0, 0,
|
| 262 |
+
0, 0, 0, 0,
|
| 263 |
+
.00445310785396, -.0069699735991, 0, .03919624819724,
|
| 264 |
+
.03254829669461, .03756752462584, .03756752462584, -.07124751761252,
|
| 265 |
+
.01204526460873, -.01845598801461, 0, .03254829669461,
|
| 266 |
+
.04215212192908, .05145895528528, .05145895528528, -.14290240509701,
|
| 267 |
+
.03142116278001, -.04723465558226, 0, .03756752462584,
|
| 268 |
+
.05145895528528, .08977496748867, .08977496748867, -.32621483141938,
|
| 269 |
+
.03142116278001, -.04723465558226, 0, .03756752462584,
|
| 270 |
+
.05145895528528, .08977496748867, .08977496748867, -.32621483141938,
|
| 271 |
+
-.16245493266167, .2326939064726, 0, -.07124751761252,
|
| 272 |
+
-.14290240509701, -.32621483141938, -.32621483141938, 1.5734864548889
|
| 273 |
+
]).reshape(8, 8)
|
| 274 |
+
|
| 275 |
+
cov_colnames = ['lnpyears', 'smokes', '1b.agecat', '2.agecat',
|
| 276 |
+
'3.agecat', '4.agecat', '5.agecat', '_cons']
|
| 277 |
+
|
| 278 |
+
cov_rownames = ['lnpyears', 'smokes', '1b.agecat', '2.agecat',
|
| 279 |
+
'3.agecat', '4.agecat', '5.agecat', '_cons']
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
results_noexposure_constraint = ParamsTableTestBunch(
|
| 283 |
+
params_table=params_table,
|
| 284 |
+
params_table_colnames=params_table_colnames,
|
| 285 |
+
params_table_rownames=params_table_rownames,
|
| 286 |
+
cov=cov,
|
| 287 |
+
cov_colnames=cov_colnames,
|
| 288 |
+
cov_rownames=cov_rownames,
|
| 289 |
+
**est
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
est = dict(
|
| 293 |
+
rank=5,
|
| 294 |
+
N=10,
|
| 295 |
+
ic=3,
|
| 296 |
+
k=7,
|
| 297 |
+
k_eq=1,
|
| 298 |
+
k_dv=1,
|
| 299 |
+
converged=1,
|
| 300 |
+
rc=0,
|
| 301 |
+
k_autoCns=1,
|
| 302 |
+
ll=-38.45090497564205,
|
| 303 |
+
k_eq_model=1,
|
| 304 |
+
df_m=4,
|
| 305 |
+
chi2=641.6446542589836,
|
| 306 |
+
p=1.5005477751e-137,
|
| 307 |
+
r2_p=np.nan,
|
| 308 |
+
cmdline=("poisson deaths smokes i.agecat, "
|
| 309 |
+
"exposure(pyears) constraints(1)"),
|
| 310 |
+
cmd="poisson",
|
| 311 |
+
predict="poisso_p",
|
| 312 |
+
estat_cmd="poisson_estat",
|
| 313 |
+
offset="ln(pyears)",
|
| 314 |
+
gof="poiss_g",
|
| 315 |
+
chi2type="Wald",
|
| 316 |
+
opt="moptimize",
|
| 317 |
+
vce="oim",
|
| 318 |
+
title="Poisson regression",
|
| 319 |
+
user="poiss_lf",
|
| 320 |
+
crittype="log likelihood",
|
| 321 |
+
ml_method="e2",
|
| 322 |
+
singularHmethod="m-marquardt",
|
| 323 |
+
technique="nr",
|
| 324 |
+
which="max",
|
| 325 |
+
depvar="deaths",
|
| 326 |
+
properties="b V",
|
| 327 |
+
)
|
| 328 |
+
|
| 329 |
+
params_table = np.array([
|
| 330 |
+
.34304077058284, .1073083520206, 3.196776058186, .00138972774083,
|
| 331 |
+
.13272026538212, .55336127578356, np.nan, 1.9599639845401,
|
| 332 |
+
0, 0, np.nan, np.nan,
|
| 333 |
+
np.nan, np.nan, np.nan, np.nan,
|
| 334 |
+
1.9599639845401, 0, 1.4846230896448, .19510453584194,
|
| 335 |
+
7.6093724999174, 2.754298692e-14, 1.1022252261742, 1.8670209531154,
|
| 336 |
+
np.nan, 1.9599639845401, 0, 2.6284071093765,
|
| 337 |
+
.18373002757074, 14.305811326156, 2.012766793e-46, 2.2683028724593,
|
| 338 |
+
2.9885113462937, np.nan, 1.9599639845401, 0,
|
| 339 |
+
3.4712405808805, .17983994458502, 19.301833020969, 5.183735658e-83,
|
| 340 |
+
3.1187607665121, 3.8237203952488, np.nan, 1.9599639845401,
|
| 341 |
+
0, 3.4712405808805, .17983994458502, 19.301833020969,
|
| 342 |
+
5.183735658e-83, 3.1187607665121, 3.8237203952488, np.nan,
|
| 343 |
+
1.9599639845401, 0, -7.9101515866812, .19164951521841,
|
| 344 |
+
-41.274049546467, 0, -8.2857777341639, -7.5345254391986,
|
| 345 |
+
np.nan, 1.9599639845401, 0]).reshape(7, 9)
|
| 346 |
+
|
| 347 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 348 |
+
|
| 349 |
+
params_table_rownames = ['smokes', '1b.agecat', '2.agecat', '3.agecat',
|
| 350 |
+
'4.agecat', '5.agecat', '_cons']
|
| 351 |
+
|
| 352 |
+
cov = np.array([
|
| 353 |
+
.01151508241338, 0, -.00061947268694, -.00090708285562,
|
| 354 |
+
-.00074959767622, -.00074959767622, -.00917958318314, 0,
|
| 355 |
+
0, 0, 0, 0,
|
| 356 |
+
0, 0, -.00061947268694, 0,
|
| 357 |
+
.0380657799061, .02946056271023, .0294520905375, .0294520905375,
|
| 358 |
+
-.02891793401778, -.00090708285562, 0, .02946056271023,
|
| 359 |
+
.03375672303114, .02947081310555, .02947081310555, -.02868865719866,
|
| 360 |
+
-.00074959767622, 0, .0294520905375, .02947081310555,
|
| 361 |
+
.03234240566834, .03234240566834, -.02881420109427, -.00074959767622,
|
| 362 |
+
0, .0294520905375, .02947081310555, .03234240566834,
|
| 363 |
+
.03234240566834, -.02881420109427, -.00917958318314, 0,
|
| 364 |
+
-.02891793401778, -.02868865719866, -.02881420109427, -.02881420109427,
|
| 365 |
+
.03672953668345]).reshape(7, 7)
|
| 366 |
+
|
| 367 |
+
cov_colnames = ['smokes', '1b.agecat', '2.agecat', '3.agecat',
|
| 368 |
+
'4.agecat', '5.agecat', '_cons']
|
| 369 |
+
|
| 370 |
+
cov_rownames = ['smokes', '1b.agecat', '2.agecat', '3.agecat',
|
| 371 |
+
'4.agecat', '5.agecat', '_cons']
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
results_exposure_constraint = ParamsTableTestBunch(
|
| 375 |
+
params_table=params_table,
|
| 376 |
+
params_table_colnames=params_table_colnames,
|
| 377 |
+
params_table_rownames=params_table_rownames,
|
| 378 |
+
cov=cov,
|
| 379 |
+
cov_colnames=cov_colnames,
|
| 380 |
+
cov_rownames=cov_rownames,
|
| 381 |
+
**est
|
| 382 |
+
)
|
| 383 |
+
|
| 384 |
+
est = dict(
|
| 385 |
+
rank=6,
|
| 386 |
+
N=10,
|
| 387 |
+
ic=3,
|
| 388 |
+
k=8,
|
| 389 |
+
k_eq=1,
|
| 390 |
+
k_dv=1,
|
| 391 |
+
converged=1,
|
| 392 |
+
rc=0,
|
| 393 |
+
k_autoCns=1,
|
| 394 |
+
ll=-33.78306559091298,
|
| 395 |
+
k_eq_model=1,
|
| 396 |
+
df_m=5,
|
| 397 |
+
chi2=526.719430888018,
|
| 398 |
+
p=1.3614066522e-111,
|
| 399 |
+
r2_p=np.nan,
|
| 400 |
+
cmdline="poisson deaths lnpyears smokes i.agecat, constraints(2)",
|
| 401 |
+
cmd="poisson",
|
| 402 |
+
predict="poisso_p",
|
| 403 |
+
estat_cmd="poisson_estat",
|
| 404 |
+
gof="poiss_g",
|
| 405 |
+
chi2type="Wald",
|
| 406 |
+
opt="moptimize",
|
| 407 |
+
vce="oim",
|
| 408 |
+
title="Poisson regression",
|
| 409 |
+
user="poiss_lf",
|
| 410 |
+
crittype="log likelihood",
|
| 411 |
+
ml_method="e2",
|
| 412 |
+
singularHmethod="m-marquardt",
|
| 413 |
+
technique="nr",
|
| 414 |
+
which="max",
|
| 415 |
+
depvar="deaths",
|
| 416 |
+
properties="b V",
|
| 417 |
+
)
|
| 418 |
+
|
| 419 |
+
params_table = np.array([
|
| 420 |
+
1.1598786864273, .13082965708054, 8.8655639119598, 7.611783820e-19,
|
| 421 |
+
.90345727043975, 1.4163001024149, np.nan, 1.9599639845401,
|
| 422 |
+
0, .12111539473831, .22317899375276, .54268277090847,
|
| 423 |
+
.58734823873758, -.31630739512299, .55853818459962, np.nan,
|
| 424 |
+
1.9599639845401, 0, 0, np.nan,
|
| 425 |
+
np.nan, np.nan, np.nan, np.nan,
|
| 426 |
+
np.nan, 1.9599639845401, 0, 1.5276244194375,
|
| 427 |
+
.19848759770871, 7.6963217705896, 1.400389019e-14, 1.1385958765506,
|
| 428 |
+
1.9166529623245, np.nan, 1.9599639845401, 0,
|
| 429 |
+
2.7415571106656, .20647039325801, 13.278209371354, 3.097119459e-40,
|
| 430 |
+
2.3368825760061, 3.1462316453252, np.nan, 1.9599639845401,
|
| 431 |
+
0, 3.587300073596, .30160673316211, 11.893965482753,
|
| 432 |
+
1.272196529e-32, 2.9961617391034, 4.1784384080885, np.nan,
|
| 433 |
+
1.9599639845401, 0, 4.087300073596, .30160673316211,
|
| 434 |
+
13.551753406643, 7.735990122e-42, 3.4961617391034, 4.6784384080885,
|
| 435 |
+
np.nan, 1.9599639845401, 0, -9.4376201542802,
|
| 436 |
+
1.2537557101599, -7.5274792990385, 5.172920628e-14, -11.894936191605,
|
| 437 |
+
-6.9803041169553, np.nan, 1.9599639845401, 0
|
| 438 |
+
]).reshape(8, 9)
|
| 439 |
+
|
| 440 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 441 |
+
|
| 442 |
+
params_table_rownames = ['lnpyears', 'smokes', '1b.agecat', '2.agecat',
|
| 443 |
+
'3.agecat', '4.agecat', '5.agecat', '_cons']
|
| 444 |
+
|
| 445 |
+
cov = np.array([
|
| 446 |
+
.01711639917181, -.02559852137367, 0, .00475026273828,
|
| 447 |
+
.012305588195, .03167368550108, .03167368550108, -.16210959536359,
|
| 448 |
+
-.02559852137367, .0498088632525, 0, -.00783669874902,
|
| 449 |
+
-.01946551099054, -.0482099128044, -.0482099128044, .23336630265161,
|
| 450 |
+
0, 0, 0, 0,
|
| 451 |
+
0, 0, 0, 0,
|
| 452 |
+
.00475026273828, -.00783669874902, 0, .03939732644417,
|
| 453 |
+
.0328943776068, .0382554606876, .0382554606876, -.07382466315002,
|
| 454 |
+
.012305588195, -.01946551099054, 0, .0328943776068,
|
| 455 |
+
.04263002329212, .05226051095238, .05226051095238, -.14512177326509,
|
| 456 |
+
.03167368550108, -.0482099128044, 0, .0382554606876,
|
| 457 |
+
.05226051095238, .09096662148872, .09096662148872, -.32873181469848,
|
| 458 |
+
.03167368550108, -.0482099128044, 0, .0382554606876,
|
| 459 |
+
.05226051095238, .09096662148872, .09096662148872, -.32873181469848,
|
| 460 |
+
-.16210959536359, .23336630265161, 0, -.07382466315002,
|
| 461 |
+
-.14512177326509, -.32873181469848, -.32873181469848, 1.5719033807586
|
| 462 |
+
]).reshape(8, 8)
|
| 463 |
+
|
| 464 |
+
cov_colnames = ['lnpyears', 'smokes', '1b.agecat', '2.agecat',
|
| 465 |
+
'3.agecat', '4.agecat', '5.agecat', '_cons']
|
| 466 |
+
|
| 467 |
+
cov_rownames = ['lnpyears', 'smokes', '1b.agecat', '2.agecat',
|
| 468 |
+
'3.agecat', '4.agecat', '5.agecat', '_cons']
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
results_noexposure_constraint2 = ParamsTableTestBunch(
|
| 472 |
+
params_table=params_table,
|
| 473 |
+
params_table_colnames=params_table_colnames,
|
| 474 |
+
params_table_rownames=params_table_rownames,
|
| 475 |
+
cov=cov,
|
| 476 |
+
cov_colnames=cov_colnames,
|
| 477 |
+
cov_rownames=cov_rownames,
|
| 478 |
+
**est
|
| 479 |
+
)
|
| 480 |
+
|
| 481 |
+
est = dict(
|
| 482 |
+
rank=5,
|
| 483 |
+
N=10,
|
| 484 |
+
ic=3,
|
| 485 |
+
k=7,
|
| 486 |
+
k_eq=1,
|
| 487 |
+
k_dv=1,
|
| 488 |
+
converged=1,
|
| 489 |
+
rc=0,
|
| 490 |
+
k_autoCns=1,
|
| 491 |
+
ll=-34.5367006700131,
|
| 492 |
+
k_eq_model=1,
|
| 493 |
+
df_m=4,
|
| 494 |
+
chi2=554.4168921897579,
|
| 495 |
+
p=1.1331093797e-118,
|
| 496 |
+
r2_p=np.nan,
|
| 497 |
+
cmdline=("poisson deaths smokes i.agecat, "
|
| 498 |
+
"exposure(pyears) constraints(2)"),
|
| 499 |
+
cmd="poisson",
|
| 500 |
+
predict="poisso_p",
|
| 501 |
+
estat_cmd="poisson_estat",
|
| 502 |
+
offset="ln(pyears)",
|
| 503 |
+
gof="poiss_g",
|
| 504 |
+
chi2type="Wald",
|
| 505 |
+
opt="moptimize",
|
| 506 |
+
vce="oim",
|
| 507 |
+
title="Poisson regression",
|
| 508 |
+
user="poiss_lf",
|
| 509 |
+
crittype="log likelihood",
|
| 510 |
+
ml_method="e2",
|
| 511 |
+
singularHmethod="m-marquardt",
|
| 512 |
+
technique="nr",
|
| 513 |
+
which="max",
|
| 514 |
+
depvar="deaths",
|
| 515 |
+
properties="b V",
|
| 516 |
+
)
|
| 517 |
+
|
| 518 |
+
params_table = np.array([
|
| 519 |
+
.35978347114582, .10730668667519, 3.3528522992687, .00079983377167,
|
| 520 |
+
.14946622996212, .57010071232952, np.nan, 1.9599639845401,
|
| 521 |
+
0, 0, np.nan, np.nan,
|
| 522 |
+
np.nan, np.nan, np.nan, np.nan,
|
| 523 |
+
1.9599639845401, 0, 1.4837272702102, .19510269288329,
|
| 524 |
+
7.6048528509946, 2.852282383e-14, 1.1013330188722, 1.8661215215483,
|
| 525 |
+
np.nan, 1.9599639845401, 0, 2.6270956495127,
|
| 526 |
+
.18372567328363, 14.299012231442, 2.219372691e-46, 2.2669999468414,
|
| 527 |
+
2.987191352184, np.nan, 1.9599639845401, 0,
|
| 528 |
+
3.2898291023835, .17982035319735, 18.295087535352, 9.055555257e-75,
|
| 529 |
+
2.9373876864294, 3.6422705183376, np.nan, 1.9599639845401,
|
| 530 |
+
0, 3.7898291023835, .17982035319735, 21.075640409983,
|
| 531 |
+
1.330935038e-98, 3.4373876864294, 4.1422705183376, np.nan,
|
| 532 |
+
1.9599639845401, 0, -7.9235211042587, .19177810950798,
|
| 533 |
+
-41.316087245761, 0, -8.2993992919175, -7.5476429165999,
|
| 534 |
+
np.nan, 1.9599639845401, 0]).reshape(7, 9)
|
| 535 |
+
|
| 536 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 537 |
+
|
| 538 |
+
params_table_rownames = ['smokes', '1b.agecat', '2.agecat', '3.agecat',
|
| 539 |
+
'4.agecat', '5.agecat', '_cons']
|
| 540 |
+
|
| 541 |
+
cov = np.array([
|
| 542 |
+
.01151472500521, 0, -.00061274288972, -.00089685568608,
|
| 543 |
+
-.00069335681347, -.00069335681347, -.00921031399899, 0,
|
| 544 |
+
0, 0, 0, 0,
|
| 545 |
+
0, 0, -.00061274288972, 0,
|
| 546 |
+
.03806506077031, .02945948985187, .02944866089267, .02944866089267,
|
| 547 |
+
-.02892164840477, -.00089685568608, 0, .02945948985187,
|
| 548 |
+
.03375512302352, .02946576868665, .02946576868665, -.0286943943397,
|
| 549 |
+
-.00069335681347, 0, .02944866089267, .02946576868665,
|
| 550 |
+
.03233535942402, .03233535942402, -.02885716752919, -.00069335681347,
|
| 551 |
+
0, .02944866089267, .02946576868665, .03233535942402,
|
| 552 |
+
.03233535942402, -.02885716752919, -.00921031399899, 0,
|
| 553 |
+
-.02892164840477, -.0286943943397, -.02885716752919, -.02885716752919,
|
| 554 |
+
.03677884328645]).reshape(7, 7)
|
| 555 |
+
|
| 556 |
+
cov_colnames = ['smokes', '1b.agecat', '2.agecat', '3.agecat',
|
| 557 |
+
'4.agecat', '5.agecat', '_cons']
|
| 558 |
+
|
| 559 |
+
cov_rownames = ['smokes', '1b.agecat', '2.agecat', '3.agecat',
|
| 560 |
+
'4.agecat', '5.agecat', '_cons']
|
| 561 |
+
|
| 562 |
+
|
| 563 |
+
results_exposure_constraint2 = ParamsTableTestBunch(
|
| 564 |
+
params_table=params_table,
|
| 565 |
+
params_table_colnames=params_table_colnames,
|
| 566 |
+
params_table_rownames=params_table_rownames,
|
| 567 |
+
cov=cov,
|
| 568 |
+
cov_colnames=cov_colnames,
|
| 569 |
+
cov_rownames=cov_rownames,
|
| 570 |
+
**est
|
| 571 |
+
)
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
est = dict(
|
| 575 |
+
rank=5,
|
| 576 |
+
N=10,
|
| 577 |
+
ic=3,
|
| 578 |
+
k=7,
|
| 579 |
+
k_eq=1,
|
| 580 |
+
k_dv=1,
|
| 581 |
+
converged=1,
|
| 582 |
+
rc=0,
|
| 583 |
+
k_autoCns=1,
|
| 584 |
+
ll=-34.5367006700131,
|
| 585 |
+
k_eq_model=1,
|
| 586 |
+
df_m=4,
|
| 587 |
+
chi2=582.5215805315736,
|
| 588 |
+
p=9.3932644024e-125,
|
| 589 |
+
r2_p=np.nan,
|
| 590 |
+
cmdline=("poisson deaths smokes i.agecat,"
|
| 591 |
+
"exposure(pyears) constraints(2) vce(robust)"),
|
| 592 |
+
cmd="poisson",
|
| 593 |
+
predict="poisso_p",
|
| 594 |
+
estat_cmd="poisson_estat",
|
| 595 |
+
offset="ln(pyears)",
|
| 596 |
+
gof="poiss_g",
|
| 597 |
+
chi2type="Wald",
|
| 598 |
+
opt="moptimize",
|
| 599 |
+
vcetype="Robust",
|
| 600 |
+
vce="robust",
|
| 601 |
+
title="Poisson regression",
|
| 602 |
+
user="poiss_lf",
|
| 603 |
+
crittype="log pseudolikelihood",
|
| 604 |
+
ml_method="e2",
|
| 605 |
+
singularHmethod="m-marquardt",
|
| 606 |
+
technique="nr",
|
| 607 |
+
which="max",
|
| 608 |
+
depvar="deaths",
|
| 609 |
+
properties="b V",
|
| 610 |
+
)
|
| 611 |
+
|
| 612 |
+
params_table = np.array([
|
| 613 |
+
.35978347114582, .1172393358046, 3.0687948603312, .00214924117257,
|
| 614 |
+
.1299985953974, .58956834689424, np.nan, 1.9599639845401,
|
| 615 |
+
0, 0, np.nan, np.nan,
|
| 616 |
+
np.nan, np.nan, np.nan, np.nan,
|
| 617 |
+
1.9599639845401, 0, 1.4837272702102, .21969092615175,
|
| 618 |
+
6.7537030145039, 1.441186055e-11, 1.0531409672225, 1.9143135731979,
|
| 619 |
+
np.nan, 1.9599639845401, 0, 2.6270956495127,
|
| 620 |
+
.20894895542061, 12.572906355164, 2.975796525e-36, 2.217563222281,
|
| 621 |
+
3.0366280767443, np.nan, 1.9599639845401, 0,
|
| 622 |
+
3.2898291023835, .2211846822073, 14.873675109654, 4.885611722e-50,
|
| 623 |
+
2.8563150913252, 3.7233431134417, np.nan, 1.9599639845401,
|
| 624 |
+
0, 3.7898291023835, .2211846822073, 17.134229479922,
|
| 625 |
+
8.243780087e-66, 3.3563150913252, 4.2233431134417, np.nan,
|
| 626 |
+
1.9599639845401, 0, -7.9235211042587, .2479876721169,
|
| 627 |
+
-31.951270144281, 5.18748229e-224, -8.4095680102177, -7.4374741982996,
|
| 628 |
+
np.nan, 1.9599639845401, 0]).reshape(7, 9)
|
| 629 |
+
|
| 630 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 631 |
+
|
| 632 |
+
params_table_rownames = ['smokes', '1b.agecat', '2.agecat', '3.agecat',
|
| 633 |
+
'4.agecat', '5.agecat', '_cons']
|
| 634 |
+
|
| 635 |
+
cov = np.array([
|
| 636 |
+
.0137450618599, 0, .00249770233028, .00412347653263,
|
| 637 |
+
.00486142402447, .00486142402447, -.01620342093134, 0,
|
| 638 |
+
0, 0, 0, 0,
|
| 639 |
+
0, 0, .00249770233028, 0,
|
| 640 |
+
.04826410303341, .04389964215014, .04391744129373, .04391744129373,
|
| 641 |
+
-.04609122424924, .00412347653263, 0, .04389964215014,
|
| 642 |
+
.04365966597136, .04367917402468, .04367917402468, -.04726310745444,
|
| 643 |
+
.00486142402447, 0, .04391744129373, .04367917402468,
|
| 644 |
+
.04892266364314, .04892266364314, -.04794543190806, .00486142402447,
|
| 645 |
+
0, .04391744129373, .04367917402468, .04892266364314,
|
| 646 |
+
.04892266364314, -.04794543190806, -.01620342093134, 0,
|
| 647 |
+
-.04609122424924, -.04726310745444, -.04794543190806, -.04794543190806,
|
| 648 |
+
.06149788552196]).reshape(7, 7)
|
| 649 |
+
|
| 650 |
+
cov_colnames = ['smokes', '1b.agecat', '2.agecat', '3.agecat',
|
| 651 |
+
'4.agecat', '5.agecat', '_cons']
|
| 652 |
+
|
| 653 |
+
cov_rownames = ['smokes', '1b.agecat', '2.agecat', '3.agecat',
|
| 654 |
+
'4.agecat', '5.agecat', '_cons']
|
| 655 |
+
|
| 656 |
+
|
| 657 |
+
results_exposure_constraint2_robust = ParamsTableTestBunch(
|
| 658 |
+
params_table=params_table,
|
| 659 |
+
params_table_colnames=params_table_colnames,
|
| 660 |
+
params_table_rownames=params_table_rownames,
|
| 661 |
+
cov=cov,
|
| 662 |
+
cov_colnames=cov_colnames,
|
| 663 |
+
cov_rownames=cov_rownames,
|
| 664 |
+
**est
|
| 665 |
+
)
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_predict.py
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""This file has been manually edited based on the generated results
|
| 2 |
+
|
| 3 |
+
edits
|
| 4 |
+
- rearrange Bunch
|
| 5 |
+
- use DataFrame
|
| 6 |
+
|
| 7 |
+
note seond `_cons` in params_table rownames is lnalpha
|
| 8 |
+
|
| 9 |
+
"""
|
| 10 |
+
# flake8: noqa
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
import pandas as pd
|
| 14 |
+
|
| 15 |
+
from statsmodels.tools.testing import ParamsTableTestBunch
|
| 16 |
+
|
| 17 |
+
est = dict(
|
| 18 |
+
rank = 9,
|
| 19 |
+
N = 3629,
|
| 20 |
+
ic = 4,
|
| 21 |
+
k = 9,
|
| 22 |
+
k_eq = 2,
|
| 23 |
+
k_dv = 1,
|
| 24 |
+
converged = 1,
|
| 25 |
+
rc = 0,
|
| 26 |
+
k_autoCns = 0,
|
| 27 |
+
ll = -10404.95565541838,
|
| 28 |
+
k_eq_model = 1,
|
| 29 |
+
ll_0 = -10786.68925314471,
|
| 30 |
+
rank0 = 2,
|
| 31 |
+
df_m = 7,
|
| 32 |
+
chi2 = 763.467195452653,
|
| 33 |
+
p = 1.4153888670e-160,
|
| 34 |
+
ll_c = -14287.94887436967,
|
| 35 |
+
chi2_c = 7765.986437902575,
|
| 36 |
+
r2_p = .0353893200005773,
|
| 37 |
+
k_aux = 1,
|
| 38 |
+
alpha = .6166738507905131,
|
| 39 |
+
cmdline = "nbreg docvis private medicaid aget aget2 educyr actlim totchr",
|
| 40 |
+
cmd = "nbreg",
|
| 41 |
+
predict = "nbreg_p",
|
| 42 |
+
dispers = "mean",
|
| 43 |
+
diparm_opt2 = "noprob",
|
| 44 |
+
chi2_ct = "LR",
|
| 45 |
+
chi2type = "LR",
|
| 46 |
+
opt = "moptimize",
|
| 47 |
+
vce = "oim",
|
| 48 |
+
title = "Negative binomial regression",
|
| 49 |
+
diparm1 = "lnalpha, exp label(",
|
| 50 |
+
user = "nbreg_lf",
|
| 51 |
+
crittype = "log likelihood",
|
| 52 |
+
ml_method = "e2",
|
| 53 |
+
singularHmethod = "m-marquardt",
|
| 54 |
+
technique = "nr",
|
| 55 |
+
which = "max",
|
| 56 |
+
depvar = "docvis",
|
| 57 |
+
properties = "b V",
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
params_table = np.array([
|
| 61 |
+
.18528179233626, .03348067897193, 5.5339914848088, 3.130241768e-08,
|
| 62 |
+
.11966086737334, .25090271729919, np.nan, 1.9599639845401,
|
| 63 |
+
0, .08475784499449, .04718372808048, 1.7963363312438,
|
| 64 |
+
.07244104305261, -.00772056269958, .17723625268856, np.nan,
|
| 65 |
+
1.9599639845401, 0, .22409326577213, .04170620298531,
|
| 66 |
+
5.3731399583668, 7.737722210e-08, .14235060998901, .30583592155526,
|
| 67 |
+
np.nan, 1.9599639845401, 0, -.04817183015548,
|
| 68 |
+
.00992361535076, -4.8542621265318, 1.208358166e-06, -.06762175883941,
|
| 69 |
+
-.02872190147156, np.nan, 1.9599639845401, 0,
|
| 70 |
+
.02692548760568, .00419162167105, 6.4236445267994, 1.330497007e-10,
|
| 71 |
+
.01871006009359, .03514091511776, np.nan, 1.9599639845401,
|
| 72 |
+
0, .17048038202011, .03448967943245, 4.9429390132204,
|
| 73 |
+
7.695356233e-07, .10288185249418, .23807891154605, np.nan,
|
| 74 |
+
1.9599639845401, 0, .27516170294682, .01205852749453,
|
| 75 |
+
22.818847746673, 2.98049648e-115, .25152742335095, .29879598254269,
|
| 76 |
+
np.nan, 1.9599639845401, 0, .67840343342789,
|
| 77 |
+
.0664120899438, 10.21505924602, 1.697754022e-24, .54823812900001,
|
| 78 |
+
.80856873785576, np.nan, 1.9599639845401, 0,
|
| 79 |
+
-.48341499971517, .03134835693943, -15.420744399751, 1.187278967e-53,
|
| 80 |
+
-.54485665029097, -.42197334913938, np.nan, 1.9599639845401,
|
| 81 |
+
0]).reshape(9,9)
|
| 82 |
+
|
| 83 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 84 |
+
params_table_rownames = 'private medicaid aget aget2 educyr actlim totchr _cons _cons'.split()
|
| 85 |
+
|
| 86 |
+
# results for
|
| 87 |
+
# margins , predict(n) predict(pr(0)) predict(pr(1)) predict(pr(0, 1)) predict(pr(2, .)) atmeans
|
| 88 |
+
table = np.array([
|
| 89 |
+
6.1604164491362, .09102737953925, 67.676521946673, 0,
|
| 90 |
+
5.9820060636322, 6.3388268346402, np.nan, 1.9599639845401,
|
| 91 |
+
0, .07860475517176, .00344783069748, 22.798322211469,
|
| 92 |
+
4.76427218e-115, .07184713117991, .08536237916362, np.nan,
|
| 93 |
+
1.9599639845401, 0, .10090462231979, .00218578691875,
|
| 94 |
+
46.16397941361, 0, .09662055868115, .10518868595842,
|
| 95 |
+
np.nan, 1.9599639845401, 0, .17950937749155,
|
| 96 |
+
.00553924697666, 32.406819599838, 2.20005624e-230, .16865265291582,
|
| 97 |
+
.19036610206727, np.nan, 1.9599639845401, 0,
|
| 98 |
+
.82049062250845, .00553924699078, 148.12313368113, 0,
|
| 99 |
+
.80963389790505, .83134734711186, np.nan, 1.9599639845401,
|
| 100 |
+
0]).reshape(5,9)
|
| 101 |
+
|
| 102 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 103 |
+
table_rownames = '1bn._predict 2._predict 3._predict 4._predict 5._predict'.split()
|
| 104 |
+
dframe_atmeans = pd.DataFrame(table, index=table_rownames, columns=table_colnames)
|
| 105 |
+
|
| 106 |
+
# result for
|
| 107 |
+
# margins, predict(n) predict(pr(0)) predict(pr(1)) predict(pr(0, 1)) predict(pr(2, .))
|
| 108 |
+
table = np.array([
|
| 109 |
+
6.8071952338104, .10838829819462, 62.803783685096, 0,
|
| 110 |
+
6.5947580730033, 7.0196323946174, np.nan, 1.9599639845401,
|
| 111 |
+
0, .08826646029161, .00350687276409, 25.169564517851,
|
| 112 |
+
8.63155623e-140, .08139311597563, .09513980460758, np.nan,
|
| 113 |
+
1.9599639845401, 0, .10719978561286, .00205026104517,
|
| 114 |
+
52.285920305334, 0, .10318134780543, .1112182234203,
|
| 115 |
+
np.nan, 1.9599639845401, 0, .19546624590447,
|
| 116 |
+
.0054522133947, 35.850806223874, 1.78661674e-281, .18478010401484,
|
| 117 |
+
.2061523877941, np.nan, 1.9599639845401, 0,
|
| 118 |
+
.80453375409553, .00545221340471, 147.56094348787, 0,
|
| 119 |
+
.79384761218628, .81521989600478, np.nan, 1.9599639845401,
|
| 120 |
+
0]).reshape(5,9)
|
| 121 |
+
|
| 122 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 123 |
+
table_rownames = '1bn._predict 2._predict 3._predict 4._predict 5._predict'.split()
|
| 124 |
+
dframe_mean = pd.DataFrame(table, index=table_rownames, columns=table_colnames)
|
| 125 |
+
|
| 126 |
+
results_nb_docvis = ParamsTableTestBunch(
|
| 127 |
+
params_table=params_table,
|
| 128 |
+
params_table_colnames=params_table_colnames,
|
| 129 |
+
params_table_rownames=params_table_rownames,
|
| 130 |
+
results_margins_atmeans=dframe_atmeans,
|
| 131 |
+
results_margins_mean=dframe_mean,
|
| 132 |
+
**est,
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
# ############################# ZINBP
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
est = dict(
|
| 139 |
+
rank = 11,
|
| 140 |
+
N = 3629,
|
| 141 |
+
ic = 8,
|
| 142 |
+
k = 11,
|
| 143 |
+
k_eq = 3,
|
| 144 |
+
k_dv = 1,
|
| 145 |
+
converged = 1,
|
| 146 |
+
rc = 0,
|
| 147 |
+
k_autoCns = 0,
|
| 148 |
+
ll = -10404.95308201019,
|
| 149 |
+
k_eq_model = 1,
|
| 150 |
+
ll_0 = -10775.51516555833,
|
| 151 |
+
chi2 = 741.1241670962918,
|
| 152 |
+
p = 9.2654212845e-153,
|
| 153 |
+
N_zero = 392,
|
| 154 |
+
df_m = 7,
|
| 155 |
+
df_c = 2,
|
| 156 |
+
k_aux = 1,
|
| 157 |
+
cmdline = "zinb docvis private medicaid aget aget2 educyr actlim totchr, inflate(aget)",
|
| 158 |
+
cmd = "zinb",
|
| 159 |
+
predict = "zip_p",
|
| 160 |
+
inflate = "logit",
|
| 161 |
+
chi2type = "LR",
|
| 162 |
+
opt = "moptimize",
|
| 163 |
+
vce = "oim",
|
| 164 |
+
title = "Zero-inflated negative binomial regression",
|
| 165 |
+
diparm1 = "lnalpha, exp label(",
|
| 166 |
+
user = "zinb_llf",
|
| 167 |
+
crittype = "log likelihood",
|
| 168 |
+
ml_method = "e2",
|
| 169 |
+
singularHmethod = "m-marquardt",
|
| 170 |
+
technique = "nr",
|
| 171 |
+
which = "max",
|
| 172 |
+
depvar = "docvis",
|
| 173 |
+
properties = "b V",
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
params_table = np.array([
|
| 177 |
+
.18517571292817, .03350948180038, 5.5260691296648, 3.274851365e-08,
|
| 178 |
+
.11949833545881, .25085309039752, np.nan, 1.9599639845401,
|
| 179 |
+
0, .08473133853831, .04717665613525, 1.7960437529823,
|
| 180 |
+
.07248755882811, -.00773320839781, .17719588547443, np.nan,
|
| 181 |
+
1.9599639845401, 0, .22335574980273, .04293022169984,
|
| 182 |
+
5.2027625518539, 1.963476761e-07, .13921406142272, .30749743818274,
|
| 183 |
+
np.nan, 1.9599639845401, 0, -.04804896097964,
|
| 184 |
+
.01006690700638, -4.7729616404713, 1.815363776e-06, -.06777973614785,
|
| 185 |
+
-.02831818581142, np.nan, 1.9599639845401, 0,
|
| 186 |
+
.0269244937276, .00419096037609, 6.4244209707123, 1.323724094e-10,
|
| 187 |
+
.01871036232982, .03513862512538, np.nan, 1.9599639845401,
|
| 188 |
+
0, .17042579343453, .03449014549225, 4.9412894901473,
|
| 189 |
+
7.760757819e-07, .10282635044816, .23802523642089, np.nan,
|
| 190 |
+
1.9599639845401, 0, .27500074932161, .01226558007071,
|
| 191 |
+
22.420525383741, 2.48238139e-111, .25096065413353, .29904084450969,
|
| 192 |
+
np.nan, 1.9599639845401, 0, .67986743798706,
|
| 193 |
+
.06944204778986, 9.7904289925953, 1.237696321e-22, .54376352530622,
|
| 194 |
+
.81597135066789, np.nan, 1.9599639845401, 0,
|
| 195 |
+
-1.2833474076485, 3.692336844421, -.34757051204241, .72816275506989,
|
| 196 |
+
-8.520194641504, 5.9534998262071, np.nan, 1.9599639845401,
|
| 197 |
+
0, -6.5587800419911, 13.305282477745, -.49294556902205,
|
| 198 |
+
.62205104781253, -32.636654502503, 19.519094418521, np.nan,
|
| 199 |
+
1.9599639845401, 0, -.4845756474516, .03531398529193,
|
| 200 |
+
-13.721919048382, 7.505227546e-43, -.55378978677435, -.41536150812884,
|
| 201 |
+
np.nan, 1.9599639845401, 0]).reshape(11,9)
|
| 202 |
+
|
| 203 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 204 |
+
params_table_rownames = 'private medicaid aget aget2 educyr actlim totchr _cons aget _cons _cons'.split()
|
| 205 |
+
|
| 206 |
+
# results for
|
| 207 |
+
# margins , predict(n) predict(pr(0)) predict(pr(1)) predict(pr(0, 1)) predict(pr(2, .)) atmeans
|
| 208 |
+
table = np.array([
|
| 209 |
+
6.1616899436815, .09285785618544, 66.356151184199, 0,
|
| 210 |
+
5.9796918898764, 6.3436879974865, np.nan, 1.9599639845401,
|
| 211 |
+
0, .07857785668717, .00351221423708, 22.372740209725,
|
| 212 |
+
7.25412664e-111, .0716940432765, .08546167009785, np.nan,
|
| 213 |
+
1.9599639845401, 0, .10079961393875, .00263347068017,
|
| 214 |
+
38.276338027191, 0, .09563810625128, .10596112162622,
|
| 215 |
+
np.nan, 1.9599639845401, 0, .17937747062593,
|
| 216 |
+
.00586287199331, 30.595494977635, 1.40505722e-205, .16788645267307,
|
| 217 |
+
.19086848857879, np.nan, 1.9599639845401, 0,
|
| 218 |
+
.82062252937407, .00586287199668, 139.96937505016, 0,
|
| 219 |
+
.80913151141461, .83211354733353, np.nan, 1.9599639845401,
|
| 220 |
+
0]).reshape(5,9)
|
| 221 |
+
|
| 222 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 223 |
+
table_rownames = '1bn._predict 2._predict 3._predict 4._predict 5._predict'.split()
|
| 224 |
+
dframe_atmeans = pd.DataFrame(table, index=table_rownames, columns=table_colnames)
|
| 225 |
+
|
| 226 |
+
# result for
|
| 227 |
+
# margins, predict(n) predict(pr(0)) predict(pr(1)) predict(pr(0, 1)) predict(pr(2, .))
|
| 228 |
+
table = np.array([
|
| 229 |
+
6.8063733751586, .10879833124057, 62.559538345387, 0,
|
| 230 |
+
6.593132564349, 7.0196141859682, np.nan, 1.9599639845401,
|
| 231 |
+
0, .08842743693234, .00405939469823, 21.7834045482,
|
| 232 |
+
3.33356305e-105, .08047116952478, .0963837043399, np.nan,
|
| 233 |
+
1.9599639845401, 0, .10706809868425, .00273617889716,
|
| 234 |
+
39.130518401155, 0, .10170528659055, .11243091077794,
|
| 235 |
+
np.nan, 1.9599639845401, 0, .19549553561658,
|
| 236 |
+
.00545764150876, 35.820516115406, 5.29431574e-281, .18479875481889,
|
| 237 |
+
.20619231641428, np.nan, 1.9599639845401, 0,
|
| 238 |
+
.80450446438342, .0054576415014, 147.40881462742, 0,
|
| 239 |
+
.79380768360013, .8152012451667, np.nan, 1.9599639845401,
|
| 240 |
+
0]).reshape(5,9)
|
| 241 |
+
|
| 242 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 243 |
+
table_rownames = '1bn._predict 2._predict 3._predict 4._predict 5._predict'.split()
|
| 244 |
+
dframe_mean = pd.DataFrame(table, index=table_rownames, columns=table_colnames)
|
| 245 |
+
|
| 246 |
+
results_zinb_docvis = ParamsTableTestBunch(
|
| 247 |
+
params_table=params_table,
|
| 248 |
+
params_table_colnames=params_table_colnames,
|
| 249 |
+
params_table_rownames=params_table_rownames,
|
| 250 |
+
results_margins_atmeans=dframe_atmeans,
|
| 251 |
+
results_margins_mean=dframe_mean,
|
| 252 |
+
**est,
|
| 253 |
+
)
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_truncated.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Created on Thu Jan 6 13:55:50 2022
|
| 3 |
+
|
| 4 |
+
Author: Josef Perktod
|
| 5 |
+
License: BSD-3
|
| 6 |
+
"""
|
| 7 |
+
# flake8: noqa
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
|
| 11 |
+
from statsmodels.tools.testing import Holder
|
| 12 |
+
|
| 13 |
+
hurdle_poisson = Holder()
|
| 14 |
+
# r library pscl, docvis data
|
| 15 |
+
# > mod = hurdle( docvis ~ aget + totchr, data=dt, zero.dist = "poisson")
|
| 16 |
+
hurdle_poisson.method = 'BFGS'
|
| 17 |
+
hurdle_poisson.n = 3629
|
| 18 |
+
hurdle_poisson.df_null = 3627
|
| 19 |
+
hurdle_poisson.df_residual = 3623
|
| 20 |
+
hurdle_poisson.loglik = -13612.9091771797
|
| 21 |
+
hurdle_poisson.aic = 27237.81835436
|
| 22 |
+
hurdle_poisson.bic = 27274.9986288
|
| 23 |
+
hurdle_poisson.vcov = np.array([
|
| 24 |
+
0.000239404800324688, -4.59559682721834e-05, -4.59865258972631e-05, 0, 0,
|
| 25 |
+
0, -4.59559682721834e-05, 2.54346275490526e-05, -1.20164687288645e-06, 0,
|
| 26 |
+
0, 0, -4.59865258972631e-05, -1.20164687288644e-06, 2.01936456643824e-05,
|
| 27 |
+
0, 0, 0, 0, 0, 0, 0.00241829560973498, -0.000548499729173446,
|
| 28 |
+
-0.000636055275016966, 0, 0, 0, -0.000548499729173446,
|
| 29 |
+
0.000351548196602719, -6.30088654100178e-05, 0, 0, 0,
|
| 30 |
+
-0.000636055275016966, -6.30088654100178e-05, 0.000562508220544602
|
| 31 |
+
]).reshape(6, 6, order='F')
|
| 32 |
+
|
| 33 |
+
hurdle_poisson.count = np.array([
|
| 34 |
+
1.54175599063303, 0.0122763123129474, 0.209943725275436,
|
| 35 |
+
0.0154727114729348, 0.00504327547820388, 0.00449373404468738,
|
| 36 |
+
99.6435559035596, 2.43419427830254, 46.719214619218, 0,
|
| 37 |
+
0.0149249819228085, 0
|
| 38 |
+
]).reshape(3, 4, order='F')
|
| 39 |
+
|
| 40 |
+
hurdle_poisson.zero = np.array([
|
| 41 |
+
0.216740121452838, 0.0189277243223132, 0.386748883124962,
|
| 42 |
+
0.0491761691242311, 0.0187496185721929, 0.0237172557549267,
|
| 43 |
+
4.40742183282514, 1.00949916657955, 16.3066455546664,
|
| 44 |
+
1.04608334100715e-05, 0.312735301122465, 8.85224303880408e-60
|
| 45 |
+
]).reshape(3, 4, order='F')
|
| 46 |
+
|
| 47 |
+
hurdle_poisson.params_table = np.concatenate((hurdle_poisson.zero,
|
| 48 |
+
hurdle_poisson.count), axis=0)
|
| 49 |
+
|
| 50 |
+
# > dfm = data.frame(t(as.matrix(dtm))) #at means
|
| 51 |
+
# > predict(mod, dfm)
|
| 52 |
+
hurdle_poisson.predict_mean = 6.530525236464
|
| 53 |
+
# > predict(mod, dfm, type="prob", at=c(0, 1, 2, 3))
|
| 54 |
+
hurdle_poisson.predict_prob = np.array([
|
| 55 |
+
0.07266312350019, 0.005744258908698, 0.02020842274659, 0.04739576870239,
|
| 56 |
+
])
|
| 57 |
+
# > predict(mod, dfm, type="count")
|
| 58 |
+
hurdle_poisson.predict_mean_main = 7.036041748046
|
| 59 |
+
# > predict(mod, dfm, type="zero")
|
| 60 |
+
hurdle_poisson.predict_zero = 0.9281532813926
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/results_truncated_st.py
ADDED
|
@@ -0,0 +1,746 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# flake8: noqa
|
| 2 |
+
# file is autogenerated
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
est = dict(
|
| 7 |
+
r2_p = .0777591927880298,
|
| 8 |
+
p = 0,
|
| 9 |
+
chi2 = 2117.638300165287,
|
| 10 |
+
df_m = 2,
|
| 11 |
+
ll_0 = -13616.64276748558,
|
| 12 |
+
k_eq_model = 1,
|
| 13 |
+
ll = -12557.82361740294,
|
| 14 |
+
k_autoCns = 0,
|
| 15 |
+
rc = 0,
|
| 16 |
+
converged = 1,
|
| 17 |
+
k_dv = 1,
|
| 18 |
+
k_eq = 1,
|
| 19 |
+
k = 3,
|
| 20 |
+
ic = 2,
|
| 21 |
+
N = 3237,
|
| 22 |
+
rank = 3,
|
| 23 |
+
cmdline = "tpoisson docvis aget totchr if docvis > 0",
|
| 24 |
+
title = "Truncated Poisson regression",
|
| 25 |
+
title2 = "Truncation points: 0",
|
| 26 |
+
llopt = "0",
|
| 27 |
+
cmd = "tpoisson",
|
| 28 |
+
predict = "tpoisson_p",
|
| 29 |
+
chi2type = "LR",
|
| 30 |
+
opt = "moptimize",
|
| 31 |
+
vce = "oim",
|
| 32 |
+
user = "tpoiss_d2",
|
| 33 |
+
crittype = "log likelihood",
|
| 34 |
+
ml_method = "e2",
|
| 35 |
+
singularHmethod = "m-marquardt",
|
| 36 |
+
technique = "nr",
|
| 37 |
+
which = "max",
|
| 38 |
+
depvar = "docvis",
|
| 39 |
+
properties = "b V",
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
params_table = np.array([
|
| 43 |
+
.01227632422998, .00504328169164, 2.4341936422712, .01492500815025,
|
| 44 |
+
.00239167375047, .02216097470949, np.nan, 1.9599639845401,
|
| 45 |
+
0, .20994371600381, .00449374445996, 46.71910427362,
|
| 46 |
+
0, .20113613870656, .21875129330105, np.nan,
|
| 47 |
+
1.9599639845401, 0, 1.5417559978312, .01547272444235,
|
| 48 |
+
99.643472846381, 0, 1.5114300151815, 1.572081980481,
|
| 49 |
+
np.nan, 1.9599639845401, 0]).reshape(3,9)
|
| 50 |
+
|
| 51 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 52 |
+
|
| 53 |
+
params_table_rownames = 'aget totchr _cons'.split()
|
| 54 |
+
|
| 55 |
+
cov = np.array([
|
| 56 |
+
.00002543469022, -1.201653007e-06, -.00004595604713, -1.201653007e-06,
|
| 57 |
+
.00002019373927, -.00004598669366, -.00004595604713, -.00004598669366,
|
| 58 |
+
.00023940520167]).reshape(3,3)
|
| 59 |
+
|
| 60 |
+
cov_colnames = 'aget totchr _cons'.split()
|
| 61 |
+
|
| 62 |
+
cov_rownames = 'aget totchr _cons'.split()
|
| 63 |
+
|
| 64 |
+
icr = np.array([
|
| 65 |
+
3237, -13616.642767486, -12557.823617403, 3,
|
| 66 |
+
25121.647234806, 25139.894441568])
|
| 67 |
+
|
| 68 |
+
icr_colnames = 'N ll0 ll df AIC BIC'.split()
|
| 69 |
+
|
| 70 |
+
icr_rownames = '.'.split()
|
| 71 |
+
|
| 72 |
+
class Bunch(dict):
|
| 73 |
+
def __init__(self, **kw):
|
| 74 |
+
dict.__init__(self, kw)
|
| 75 |
+
self.__dict__ = self
|
| 76 |
+
|
| 77 |
+
if hasattr(self, 'params_table'):
|
| 78 |
+
for i,att in enumerate(['params', 'bse', 'tvalues', 'pvalues']):
|
| 79 |
+
self[att] = self.params_table[:,i]
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
results_trunc_poisson = Bunch(
|
| 83 |
+
params_table=params_table,
|
| 84 |
+
params_table_colnames=params_table_colnames,
|
| 85 |
+
params_table_rownames=params_table_rownames,
|
| 86 |
+
cov=cov,
|
| 87 |
+
cov_colnames=cov_colnames,
|
| 88 |
+
cov_rownames=cov_rownames,
|
| 89 |
+
icr=icr,
|
| 90 |
+
icr_colnames=icr_colnames,
|
| 91 |
+
icr_rownames=icr_rownames,
|
| 92 |
+
**est
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
table = np.array([
|
| 96 |
+
7.5616311400077, .04812900313217, 157.11173404616, 0,
|
| 97 |
+
7.4673000272568, 7.6559622527585, np.nan, 1.9599639845401,
|
| 98 |
+
0])
|
| 99 |
+
|
| 100 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 101 |
+
|
| 102 |
+
table_rownames = '_cons'.split()
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
results_trunc_poisson.margins_cm = Bunch(
|
| 106 |
+
table=table,
|
| 107 |
+
table_colnames=table_colnames,
|
| 108 |
+
table_rownames=table_rownames,
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
table = np.array([
|
| 112 |
+
7.5503819076573, .04846533862271, 155.78931504916, 0,
|
| 113 |
+
7.4553915894583, 7.6453722258564, np.nan, 1.9599639845401,
|
| 114 |
+
0])
|
| 115 |
+
|
| 116 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 117 |
+
|
| 118 |
+
table_rownames = '_cons'.split()
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
results_trunc_poisson.margins_means = Bunch(
|
| 122 |
+
table=table,
|
| 123 |
+
table_colnames=table_colnames,
|
| 124 |
+
table_rownames=table_rownames,
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
table = np.array([
|
| 128 |
+
7.2430661225168, .04840412009716, 149.63738846977, 0,
|
| 129 |
+
7.148195790423, 7.3379364546105, np.nan, 1.9599639845401,
|
| 130 |
+
0])
|
| 131 |
+
|
| 132 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 133 |
+
|
| 134 |
+
table_rownames = '_cons'.split()
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
results_trunc_poisson.margins_atmeans = Bunch(
|
| 138 |
+
table=table,
|
| 139 |
+
table_colnames=table_colnames,
|
| 140 |
+
table_rownames=table_rownames,
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
table = np.array([
|
| 144 |
+
.01124923235036, .00049084317554, 22.918180207056, 3.06106238e-116,
|
| 145 |
+
.01028719740425, .01221126729646, np.nan, 1.9599639845401,
|
| 146 |
+
0, .03157461406623, .00105301458741, 29.984973089368,
|
| 147 |
+
1.54089108e-197, .02951074339971, .03363848473275, np.nan,
|
| 148 |
+
1.9599639845401, 0, .06090587962511, .00146586027013,
|
| 149 |
+
41.549580724723, 0, .05803284628928, .06377891296095,
|
| 150 |
+
np.nan, 1.9599639845401, 0, .8962702739583,
|
| 151 |
+
.00300215903947, 298.54190340135, 0, .89038615036507,
|
| 152 |
+
.90215439755153, np.nan, 1.9599639845401, 0
|
| 153 |
+
]).reshape(4,9)
|
| 154 |
+
|
| 155 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 156 |
+
|
| 157 |
+
table_rownames = '1bn._predict 2._predict 3._predict 4._predict'.split()
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
results_trunc_poisson.margins_cpr = Bunch(
|
| 161 |
+
table=table,
|
| 162 |
+
table_colnames=table_colnames,
|
| 163 |
+
table_rownames=table_rownames,
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
table = np.array([
|
| 167 |
+
.00204639655178, .00011129186954, 18.387655453284, 1.649609265e-75,
|
| 168 |
+
.00182826849572, .00226452460784, np.nan, 1.9599639845401,
|
| 169 |
+
0, .0111917391283, .00048491494502, 23.079798309369,
|
| 170 |
+
7.38815718e-118, .01024132330049, .01214215495611, np.nan,
|
| 171 |
+
1.9599639845401, 0, .03142959767164, .00103996422108,
|
| 172 |
+
30.221806707029, 1.22479233e-200, .02939130525312, .03346789009016,
|
| 173 |
+
np.nan, 1.9599639845401, 0, .06065903309159,
|
| 174 |
+
.00144697985213, 41.921131799076, 0, .05782300469507,
|
| 175 |
+
.06349506148811, np.nan, 1.9599639845401, 0,
|
| 176 |
+
.89467323355669, .0030739863865, 291.04658286247, 0,
|
| 177 |
+
.88864833095018, .9006981361632, np.nan, 1.9599639845401,
|
| 178 |
+
0]).reshape(5,9)
|
| 179 |
+
|
| 180 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 181 |
+
|
| 182 |
+
table_rownames = '1bn._predict 2._predict 3._predict 4._predict 5._predict'.split()
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
results_trunc_poisson.margins_pr = Bunch(
|
| 186 |
+
table=table,
|
| 187 |
+
table_colnames=table_colnames,
|
| 188 |
+
table_rownames=table_rownames,
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
est = dict(
|
| 192 |
+
k_aux = 1,
|
| 193 |
+
r2_p = .0215428784838031,
|
| 194 |
+
chi2_c = 6444.56377006125,
|
| 195 |
+
ll_c = -12557.82361740294,
|
| 196 |
+
p = 5.42079209773e-90,
|
| 197 |
+
chi2 = 411.0848328423963,
|
| 198 |
+
df_m = 2,
|
| 199 |
+
rank0 = 2,
|
| 200 |
+
ll_0 = -9541.08414879351,
|
| 201 |
+
k_eq_model = 1,
|
| 202 |
+
ll = -9335.541732372312,
|
| 203 |
+
k_autoCns = 0,
|
| 204 |
+
rc = 0,
|
| 205 |
+
converged = 1,
|
| 206 |
+
k_dv = 1,
|
| 207 |
+
k_eq = 2,
|
| 208 |
+
k = 4,
|
| 209 |
+
ic = 3,
|
| 210 |
+
N = 3237,
|
| 211 |
+
rank = 4,
|
| 212 |
+
alpha = .5883738271406221,
|
| 213 |
+
cmdline = "tnbreg docvis aget totchr if docvis > 0",
|
| 214 |
+
title = "Truncated negative binomial regression",
|
| 215 |
+
title2 = "Truncation points: 0",
|
| 216 |
+
llopt = "0",
|
| 217 |
+
cmd = "tnbreg",
|
| 218 |
+
predict = "tnbreg_p",
|
| 219 |
+
dispers = "mean",
|
| 220 |
+
diparm_opt2 = "noprob",
|
| 221 |
+
chi2_ct = "LR",
|
| 222 |
+
chi2type = "LR",
|
| 223 |
+
opt = "moptimize",
|
| 224 |
+
vce = "oim",
|
| 225 |
+
diparm1 = "lnalpha, exp label(",
|
| 226 |
+
user = "tnbreg_mean",
|
| 227 |
+
crittype = "log likelihood",
|
| 228 |
+
ml_method = "e2",
|
| 229 |
+
singularHmethod = "m-marquardt",
|
| 230 |
+
technique = "nr",
|
| 231 |
+
which = "max",
|
| 232 |
+
depvar = "docvis",
|
| 233 |
+
properties = "b V",
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
params_table = np.array([
|
| 237 |
+
.01798960271895, .01237555909354, 1.4536395958332, .14604625306297,
|
| 238 |
+
-.00626604739294, .04224525283084, np.nan, 1.9599639845401,
|
| 239 |
+
0, .23731215078822, .01166878414467, 20.337350305391,
|
| 240 |
+
6.009046369e-92, .21444175412129, .26018254745516, np.nan,
|
| 241 |
+
1.9599639845401, 0, 1.4035619564653, .0366296524502,
|
| 242 |
+
38.317643291146, 0, 1.3317691568967, 1.4753547560339,
|
| 243 |
+
np.nan, 1.9599639845401, 0, -.53039277265033,
|
| 244 |
+
.04237842368148, -12.515632403809, 6.131755594e-36, -.61345295678762,
|
| 245 |
+
-.44733258851304, np.nan, 1.9599639845401, 0
|
| 246 |
+
]).reshape(4,9)
|
| 247 |
+
|
| 248 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 249 |
+
|
| 250 |
+
params_table_rownames = 'aget totchr _cons _cons'.split()
|
| 251 |
+
|
| 252 |
+
cov = np.array([
|
| 253 |
+
.00015315446288, -8.133778629e-06, -.0002727009794, 4.768991952e-06,
|
| 254 |
+
-8.133778629e-06, .00013616052341, -.00027073391794, .00003663514391,
|
| 255 |
+
-.0002727009794, -.00027073391794, .00134173143862, -.00027563132595,
|
| 256 |
+
4.768991952e-06, .00003663514391, -.00027563132595, .00179593079373
|
| 257 |
+
]).reshape(4,4)
|
| 258 |
+
|
| 259 |
+
cov_colnames = 'aget totchr _cons _cons'.split()
|
| 260 |
+
|
| 261 |
+
cov_rownames = 'aget totchr _cons _cons'.split()
|
| 262 |
+
|
| 263 |
+
icr = np.array([
|
| 264 |
+
3237, -9541.0841487935, -9335.5417323723, 4,
|
| 265 |
+
18679.083464745, 18703.41307376])
|
| 266 |
+
|
| 267 |
+
icr_colnames = 'N ll0 ll df AIC BIC'.split()
|
| 268 |
+
|
| 269 |
+
icr_rownames = '.'.split()
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
results_trunc_negbin = Bunch(
|
| 273 |
+
params_table=params_table,
|
| 274 |
+
params_table_colnames=params_table_colnames,
|
| 275 |
+
params_table_rownames=params_table_rownames,
|
| 276 |
+
cov=cov,
|
| 277 |
+
cov_colnames=cov_colnames,
|
| 278 |
+
cov_rownames=cov_rownames,
|
| 279 |
+
icr=icr,
|
| 280 |
+
icr_colnames=icr_colnames,
|
| 281 |
+
icr_rownames=icr_rownames,
|
| 282 |
+
**est
|
| 283 |
+
)
|
| 284 |
+
|
| 285 |
+
table = np.array([
|
| 286 |
+
7.5768532635168, .11034667559901, 68.664082740929, 0,
|
| 287 |
+
7.360577753529, 7.7931287735046, np.nan, 1.9599639845401,
|
| 288 |
+
0])
|
| 289 |
+
|
| 290 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 291 |
+
|
| 292 |
+
table_rownames = '_cons'.split()
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
results_trunc_negbin.margins_cm = Bunch(
|
| 296 |
+
table=table,
|
| 297 |
+
table_colnames=table_colnames,
|
| 298 |
+
table_rownames=table_rownames,
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
+
table = np.array([
|
| 302 |
+
7.1017589207455, .11718653140646, 60.602177020781, 0,
|
| 303 |
+
6.8720775397156, 7.3314403017753, np.nan, 1.9599639845401,
|
| 304 |
+
0])
|
| 305 |
+
|
| 306 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 307 |
+
|
| 308 |
+
table_rownames = '_cons'.split()
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
results_trunc_negbin.margins_means = Bunch(
|
| 312 |
+
table=table,
|
| 313 |
+
table_colnames=table_colnames,
|
| 314 |
+
table_rownames=table_rownames,
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
table = np.array([
|
| 318 |
+
6.7307995444045, .10830267362473, 62.148046018945, 0,
|
| 319 |
+
6.5185302046706, 6.9430688841384, np.nan, 1.9599639845401,
|
| 320 |
+
0])
|
| 321 |
+
|
| 322 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 323 |
+
|
| 324 |
+
table_rownames = '_cons'.split()
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
results_trunc_negbin.margins_atmeans = Bunch(
|
| 328 |
+
table=table,
|
| 329 |
+
table_colnames=table_colnames,
|
| 330 |
+
table_rownames=table_rownames,
|
| 331 |
+
)
|
| 332 |
+
|
| 333 |
+
table = np.array([
|
| 334 |
+
.10130558155035, .00372164932482, 27.220614493326, 3.70370053e-163,
|
| 335 |
+
.09401128291061, .10859988019009, np.nan, 1.9599639845401,
|
| 336 |
+
0, .10609694010369, .00217062159601, 48.878597862821,
|
| 337 |
+
0, .10184259995145, .11035128025594, np.nan,
|
| 338 |
+
1.9599639845401, 0, .10187507062355, .00125382749214,
|
| 339 |
+
81.251265634444, 0, .09941761389613, .10433252735097,
|
| 340 |
+
np.nan, 1.9599639845401, 0, .69072240772241,
|
| 341 |
+
.00681119370137, 101.40989054297, 0, .67737271337601,
|
| 342 |
+
.70407210206881, np.nan, 1.9599639845401, 0
|
| 343 |
+
]).reshape(4,9)
|
| 344 |
+
|
| 345 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 346 |
+
|
| 347 |
+
table_rownames = '1bn._predict 2._predict 3._predict 4._predict'.split()
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
results_trunc_negbin.margins_cpr = Bunch(
|
| 351 |
+
table=table,
|
| 352 |
+
table_colnames=table_colnames,
|
| 353 |
+
table_rownames=table_rownames,
|
| 354 |
+
)
|
| 355 |
+
|
| 356 |
+
table = np.array([
|
| 357 |
+
.07074667643427, .00449635579252, 15.734225603755, 8.812829317e-56,
|
| 358 |
+
.06193398101925, .07955937184929, np.nan, 1.9599639845401,
|
| 359 |
+
0, .09312895729354, .0029475364353, 31.595523698388,
|
| 360 |
+
4.25362024e-219, .08735189203722, .09890602254985, np.nan,
|
| 361 |
+
1.9599639845401, 0, .09770317477771, .00158068603995,
|
| 362 |
+
61.810614067951, 0, .09460508706855, .10080126248687,
|
| 363 |
+
np.nan, 1.9599639845401, 0, .09397857365281,
|
| 364 |
+
.00100790260574, 93.241721092808, 0, .09200312084564,
|
| 365 |
+
.09595402645998, np.nan, 1.9599639845401, 0,
|
| 366 |
+
.64444261784167, .00909052984414, 70.891645359594, 0,
|
| 367 |
+
.62662550674676, .66225972893657, np.nan, 1.9599639845401,
|
| 368 |
+
0]).reshape(5,9)
|
| 369 |
+
|
| 370 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 371 |
+
|
| 372 |
+
table_rownames = '1bn._predict 2._predict 3._predict 4._predict 5._predict'.split()
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
results_trunc_negbin.margins_pr = Bunch(
|
| 376 |
+
table=table,
|
| 377 |
+
table_colnames=table_colnames,
|
| 378 |
+
table_rownames=table_rownames,
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
est = dict(
|
| 382 |
+
r2_p = .0631714878006528,
|
| 383 |
+
p = 4.9406564584e-324,
|
| 384 |
+
chi2 = 1489.753609191444,
|
| 385 |
+
df_m = 2,
|
| 386 |
+
ll_0 = -11791.34496477735,
|
| 387 |
+
k_eq_model = 1,
|
| 388 |
+
ll = -11046.46816018163,
|
| 389 |
+
k_autoCns = 0,
|
| 390 |
+
rc = 0,
|
| 391 |
+
converged = 1,
|
| 392 |
+
k_dv = 1,
|
| 393 |
+
k_eq = 1,
|
| 394 |
+
k = 3,
|
| 395 |
+
ic = 2,
|
| 396 |
+
N = 2925,
|
| 397 |
+
rank = 3,
|
| 398 |
+
cmdline = "tpoisson docvis aget totchr if docvis > 1, ll(1)",
|
| 399 |
+
title = "Truncated Poisson regression",
|
| 400 |
+
title2 = "Truncation points: 1",
|
| 401 |
+
llopt = "1",
|
| 402 |
+
cmd = "tpoisson",
|
| 403 |
+
predict = "tpoisson_p",
|
| 404 |
+
chi2type = "LR",
|
| 405 |
+
opt = "moptimize",
|
| 406 |
+
vce = "oim",
|
| 407 |
+
user = "tpoiss_d2",
|
| 408 |
+
crittype = "log likelihood",
|
| 409 |
+
ml_method = "e2",
|
| 410 |
+
singularHmethod = "m-marquardt",
|
| 411 |
+
technique = "nr",
|
| 412 |
+
which = "max",
|
| 413 |
+
depvar = "docvis",
|
| 414 |
+
properties = "b V",
|
| 415 |
+
)
|
| 416 |
+
|
| 417 |
+
params_table = np.array([
|
| 418 |
+
.00741559993424, .00511787438189, 1.4489609124605, .14734849869339,
|
| 419 |
+
-.00261524953166, .01744644940014, np.nan, 1.9599639845401,
|
| 420 |
+
0, .18069681610939, .00462967674542, 39.030115069715,
|
| 421 |
+
0, .1716228164283, .18977081579048, np.nan,
|
| 422 |
+
1.9599639845401, 0, 1.6905464469665, .01602194453256,
|
| 423 |
+
105.51443637387, 0, 1.6591440127204, 1.7219488812126,
|
| 424 |
+
np.nan, 1.9599639845401, 0]).reshape(3,9)
|
| 425 |
+
|
| 426 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 427 |
+
|
| 428 |
+
params_table_rownames = 'aget totchr _cons'.split()
|
| 429 |
+
|
| 430 |
+
cov = np.array([
|
| 431 |
+
.00002619263819, -9.943128998e-07, -.00004800030105, -9.943128998e-07,
|
| 432 |
+
.00002143390677, -.00005015292878, -.00004800030105, -.00005015292878,
|
| 433 |
+
.0002567027066]).reshape(3,3)
|
| 434 |
+
|
| 435 |
+
cov_colnames = 'aget totchr _cons'.split()
|
| 436 |
+
|
| 437 |
+
cov_rownames = 'aget totchr _cons'.split()
|
| 438 |
+
|
| 439 |
+
icr = np.array([
|
| 440 |
+
2925, -11791.344964777, -11046.468160182, 3,
|
| 441 |
+
22098.936320363, 22116.879469642])
|
| 442 |
+
|
| 443 |
+
icr_colnames = 'N ll0 ll df AIC BIC'.split()
|
| 444 |
+
|
| 445 |
+
icr_rownames = '.'.split()
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
results_trunc_poisson1 = Bunch(
|
| 449 |
+
params_table=params_table,
|
| 450 |
+
params_table_colnames=params_table_colnames,
|
| 451 |
+
params_table_rownames=params_table_rownames,
|
| 452 |
+
cov=cov,
|
| 453 |
+
cov_colnames=cov_colnames,
|
| 454 |
+
cov_rownames=cov_rownames,
|
| 455 |
+
icr=icr,
|
| 456 |
+
icr_colnames=icr_colnames,
|
| 457 |
+
icr_rownames=icr_rownames,
|
| 458 |
+
**est
|
| 459 |
+
)
|
| 460 |
+
|
| 461 |
+
table = np.array([
|
| 462 |
+
8.2615384672996, .05245366864144, 157.50163298917, 0,
|
| 463 |
+
8.1587311659054, 8.3643457686938, np.nan, 1.9599639845401,
|
| 464 |
+
0])
|
| 465 |
+
|
| 466 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 467 |
+
|
| 468 |
+
table_rownames = '_cons'.split()
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
results_trunc_poisson1.margins_cm = Bunch(
|
| 472 |
+
table=table,
|
| 473 |
+
table_colnames=table_colnames,
|
| 474 |
+
table_rownames=table_rownames,
|
| 475 |
+
)
|
| 476 |
+
|
| 477 |
+
table = np.array([
|
| 478 |
+
8.2234692879205, .05360982028302, 153.39483035955, 0,
|
| 479 |
+
8.1183959709481, 8.3285426048929, np.nan, 1.9599639845401,
|
| 480 |
+
0])
|
| 481 |
+
|
| 482 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 483 |
+
|
| 484 |
+
table_rownames = '_cons'.split()
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
results_trunc_poisson1.margins_means = Bunch(
|
| 488 |
+
table=table,
|
| 489 |
+
table_colnames=table_colnames,
|
| 490 |
+
table_rownames=table_rownames,
|
| 491 |
+
)
|
| 492 |
+
|
| 493 |
+
table = np.array([
|
| 494 |
+
7.9777789306415, .05376558351155, 148.38077464422, 0,
|
| 495 |
+
7.8724003233511, 8.0831575379319, np.nan, 1.9599639845401,
|
| 496 |
+
0])
|
| 497 |
+
|
| 498 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 499 |
+
|
| 500 |
+
table_rownames = '_cons'.split()
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
results_trunc_poisson1.margins_atmeans = Bunch(
|
| 504 |
+
table=table,
|
| 505 |
+
table_colnames=table_colnames,
|
| 506 |
+
table_rownames=table_rownames,
|
| 507 |
+
)
|
| 508 |
+
|
| 509 |
+
table = np.array([
|
| 510 |
+
.01903458968954, .00079296931232, 24.004194606123, 2.51401100e-127,
|
| 511 |
+
.01748039839655, .02058878098252, np.nan, 1.9599639845401,
|
| 512 |
+
0, .04148049972971, .00131417109881, 31.564002409827,
|
| 513 |
+
1.15213452e-218, .03890477170652, .04405622775289, np.nan,
|
| 514 |
+
1.9599639845401, 0, .0696144656319, .00158464648625,
|
| 515 |
+
43.930596657447, 0, .06650861559064, .07272031567317,
|
| 516 |
+
np.nan, 1.9599639845401, 0, .86987044494885,
|
| 517 |
+
.00367826110927, 236.48958546081, 0, .86266118564894,
|
| 518 |
+
.87707970424876, np.nan, 1.9599639845401, 0
|
| 519 |
+
]).reshape(4,9)
|
| 520 |
+
|
| 521 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 522 |
+
|
| 523 |
+
table_rownames = '1bn._predict 2._predict 3._predict 4._predict'.split()
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
results_trunc_poisson1.margins_cpr = Bunch(
|
| 527 |
+
table=table,
|
| 528 |
+
table_colnames=table_colnames,
|
| 529 |
+
table_rownames=table_rownames,
|
| 530 |
+
)
|
| 531 |
+
|
| 532 |
+
table = np.array([
|
| 533 |
+
.00093735269068, .00005905857331, 15.871576946126, 9.970398969e-57,
|
| 534 |
+
.00082160001401, .00105310536736, np.nan, 1.9599639845401,
|
| 535 |
+
0, .00586646311539, .00030222083986, 19.411179977019,
|
| 536 |
+
6.208483313e-84, .00527412115388, .0064588050769, np.nan,
|
| 537 |
+
1.9599639845401, 0, .01875199435581, .00076464697042,
|
| 538 |
+
24.5237280485, 8.24915097e-133, .01725331383289, .02025067487873,
|
| 539 |
+
np.nan, 1.9599639845401, 0, .04092373966247,
|
| 540 |
+
.00126585942523, 32.328818545641, 2.75392481e-229, .03844270077953,
|
| 541 |
+
.04340477854541, np.nan, 1.9599639845401, 0,
|
| 542 |
+
.93352045017566, .00238739224619, 391.02097766504, 0,
|
| 543 |
+
.92884124735615, .93819965299516, np.nan, 1.9599639845401,
|
| 544 |
+
0]).reshape(5,9)
|
| 545 |
+
|
| 546 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 547 |
+
|
| 548 |
+
table_rownames = '1bn._predict 2._predict 3._predict 4._predict 5._predict'.split()
|
| 549 |
+
|
| 550 |
+
|
| 551 |
+
results_trunc_poisson1.margins_pr = Bunch(
|
| 552 |
+
table=table,
|
| 553 |
+
table_colnames=table_colnames,
|
| 554 |
+
table_rownames=table_rownames,
|
| 555 |
+
)
|
| 556 |
+
|
| 557 |
+
est = dict(
|
| 558 |
+
k_aux = 1,
|
| 559 |
+
r2_p = .0176349216287439,
|
| 560 |
+
chi2_c = 5373.418644637513,
|
| 561 |
+
ll_c = -11046.46816018163,
|
| 562 |
+
p = 6.68889408978e-66,
|
| 563 |
+
chi2 = 300.1403351701738,
|
| 564 |
+
df_m = 2,
|
| 565 |
+
rank0 = 2,
|
| 566 |
+
ll_0 = -8509.829005447959,
|
| 567 |
+
k_eq_model = 1,
|
| 568 |
+
ll = -8359.758837862872,
|
| 569 |
+
k_autoCns = 0,
|
| 570 |
+
rc = 0,
|
| 571 |
+
converged = 1,
|
| 572 |
+
k_dv = 1,
|
| 573 |
+
k_eq = 2,
|
| 574 |
+
k = 4,
|
| 575 |
+
ic = 4,
|
| 576 |
+
N = 2925,
|
| 577 |
+
rank = 4,
|
| 578 |
+
alpha = .6463397153671251,
|
| 579 |
+
cmdline = "tnbreg docvis aget totchr if docvis > 1, ll(1)",
|
| 580 |
+
title = "Truncated negative binomial regression",
|
| 581 |
+
title2 = "Truncation points: 1",
|
| 582 |
+
llopt = "1",
|
| 583 |
+
cmd = "tnbreg",
|
| 584 |
+
predict = "tnbreg_p",
|
| 585 |
+
dispers = "mean",
|
| 586 |
+
diparm_opt2 = "noprob",
|
| 587 |
+
chi2_ct = "LR",
|
| 588 |
+
chi2type = "LR",
|
| 589 |
+
opt = "moptimize",
|
| 590 |
+
vce = "oim",
|
| 591 |
+
diparm1 = "lnalpha, exp label(",
|
| 592 |
+
user = "tnbreg_mean",
|
| 593 |
+
crittype = "log likelihood",
|
| 594 |
+
ml_method = "e1",
|
| 595 |
+
singularHmethod = "m-marquardt",
|
| 596 |
+
technique = "nr",
|
| 597 |
+
which = "max",
|
| 598 |
+
depvar = "docvis",
|
| 599 |
+
properties = "b V",
|
| 600 |
+
)
|
| 601 |
+
|
| 602 |
+
params_table = np.array([
|
| 603 |
+
.01248138313122, .01373594189048, .90866598233607, .36352646578614,
|
| 604 |
+
-.01444056826785, .03940333453029, np.nan, 1.9599639845401,
|
| 605 |
+
0, .22357307664024, .01291927204045, 17.30539274506,
|
| 606 |
+
4.283502186e-67, .19825176873449, .248894384546, np.nan,
|
| 607 |
+
1.9599639845401, 0, 1.4174570100091, .0439841469348,
|
| 608 |
+
32.226543170437, 7.49935100e-228, 1.3312496661262, 1.503664353892,
|
| 609 |
+
np.nan, 1.9599639845401, 0, -.43643003824212,
|
| 610 |
+
.05825731989132, -7.4914197744811, 6.813252519e-14, -.55061228706494,
|
| 611 |
+
-.3222477894193, np.nan, 1.9599639845401, 0
|
| 612 |
+
]).reshape(4,9)
|
| 613 |
+
|
| 614 |
+
params_table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 615 |
+
|
| 616 |
+
params_table_rownames = 'aget totchr _cons _cons'.split()
|
| 617 |
+
|
| 618 |
+
cov = np.array([
|
| 619 |
+
.00018867609962, -8.418931354e-06, -.00034269534637, 8.523991115e-06,
|
| 620 |
+
-8.418931354e-06, .00016690759006, -.0003648589293, .00010167740775,
|
| 621 |
+
-.00034269534637, -.0003648589293, .00193460518158, -.00096544368473,
|
| 622 |
+
8.523991115e-06, .00010167740775, -.00096544368473, .00339391532092
|
| 623 |
+
]).reshape(4,4)
|
| 624 |
+
|
| 625 |
+
cov_colnames = 'aget totchr _cons _cons'.split()
|
| 626 |
+
|
| 627 |
+
cov_rownames = 'aget totchr _cons _cons'.split()
|
| 628 |
+
|
| 629 |
+
icr = np.array([
|
| 630 |
+
2925, -8509.829005448, -8359.7588378629, 4,
|
| 631 |
+
16727.517675726, 16751.441874764])
|
| 632 |
+
|
| 633 |
+
icr_colnames = 'N ll0 ll df AIC BIC'.split()
|
| 634 |
+
|
| 635 |
+
icr_rownames = '.'.split()
|
| 636 |
+
|
| 637 |
+
|
| 638 |
+
results_trunc_negbin1 = Bunch(
|
| 639 |
+
params_table=params_table,
|
| 640 |
+
params_table_colnames=params_table_colnames,
|
| 641 |
+
params_table_rownames=params_table_rownames,
|
| 642 |
+
cov=cov,
|
| 643 |
+
cov_colnames=cov_colnames,
|
| 644 |
+
cov_rownames=cov_rownames,
|
| 645 |
+
icr=icr,
|
| 646 |
+
icr_colnames=icr_colnames,
|
| 647 |
+
icr_rownames=icr_rownames,
|
| 648 |
+
**est
|
| 649 |
+
)
|
| 650 |
+
|
| 651 |
+
table = np.array([
|
| 652 |
+
8.2699639050783, .11716249080665, 70.58542241754, 0,
|
| 653 |
+
8.0403296427583, 8.4995981673984, np.nan, 1.9599639845401,
|
| 654 |
+
0])
|
| 655 |
+
|
| 656 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 657 |
+
|
| 658 |
+
table_rownames = '_cons'.split()
|
| 659 |
+
|
| 660 |
+
|
| 661 |
+
results_trunc_negbin1.margins_cm = Bunch(
|
| 662 |
+
table=table,
|
| 663 |
+
table_colnames=table_colnames,
|
| 664 |
+
table_rownames=table_rownames,
|
| 665 |
+
)
|
| 666 |
+
|
| 667 |
+
table = np.array([
|
| 668 |
+
7.017795994882, .1490968794197, 47.06869803175, 0,
|
| 669 |
+
6.7255714810121, 7.3100205087519, np.nan, 1.9599639845401,
|
| 670 |
+
0])
|
| 671 |
+
|
| 672 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 673 |
+
|
| 674 |
+
table_rownames = '_cons'.split()
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
results_trunc_negbin1.margins_means = Bunch(
|
| 678 |
+
table=table,
|
| 679 |
+
table_colnames=table_colnames,
|
| 680 |
+
table_rownames=table_rownames,
|
| 681 |
+
)
|
| 682 |
+
|
| 683 |
+
table = np.array([
|
| 684 |
+
6.6955630594846, .14246748862917, 46.997129828773, 0,
|
| 685 |
+
6.4163319128035, 6.9747942061656, np.nan, 1.9599639845401,
|
| 686 |
+
0])
|
| 687 |
+
|
| 688 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 689 |
+
|
| 690 |
+
table_rownames = '_cons'.split()
|
| 691 |
+
|
| 692 |
+
|
| 693 |
+
results_trunc_negbin1.margins_atmeans = Bunch(
|
| 694 |
+
table=table,
|
| 695 |
+
table_colnames=table_colnames,
|
| 696 |
+
table_rownames=table_rownames,
|
| 697 |
+
)
|
| 698 |
+
|
| 699 |
+
table = np.array([
|
| 700 |
+
.12259218620014, .00421507068546, 29.084253942174, 5.67883794e-186,
|
| 701 |
+
.11433079946434, .13085357293593, np.nan, 1.9599639845401,
|
| 702 |
+
0, .11517369272078, .00228641261466, 50.373100630412,
|
| 703 |
+
0, .11069240634225, .11965497909931, np.nan,
|
| 704 |
+
1.9599639845401, 0, .10432064271736, .00125159955387,
|
| 705 |
+
83.349856106274, 0, .10186755266872, .10677373276601,
|
| 706 |
+
np.nan, 1.9599639845401, 0, .65791347836172,
|
| 707 |
+
.00742267145141, 88.635672839381, 0, .64336530964788,
|
| 708 |
+
.67246164707557, np.nan, 1.9599639845401, 0
|
| 709 |
+
]).reshape(4,9)
|
| 710 |
+
|
| 711 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 712 |
+
|
| 713 |
+
table_rownames = '1bn._predict 2._predict 3._predict 4._predict'.split()
|
| 714 |
+
|
| 715 |
+
|
| 716 |
+
results_trunc_negbin1.margins_cpr = Bunch(
|
| 717 |
+
table=table,
|
| 718 |
+
table_colnames=table_colnames,
|
| 719 |
+
table_rownames=table_rownames,
|
| 720 |
+
)
|
| 721 |
+
|
| 722 |
+
table = np.array([
|
| 723 |
+
.07948896451521, .00728414519354, 10.912600230113, 1.003444098e-27,
|
| 724 |
+
.06521230227771, .09376562675271, np.nan, 1.9599639845401,
|
| 725 |
+
0, .09752506791268, .00432307282658, 22.559200787217,
|
| 726 |
+
1.09075552e-112, .08905200087003, .10599813495533, np.nan,
|
| 727 |
+
1.9599639845401, 0, .09876742202689, .00202841049952,
|
| 728 |
+
48.692028586009, 0, .09479181050196, .10274303355181,
|
| 729 |
+
np.nan, 1.9599639845401, 0, .0931207168728,
|
| 730 |
+
.00101384753518, 91.848836872758, 0, .09113361221802,
|
| 731 |
+
.09510782152757, np.nan, 1.9599639845401, 0,
|
| 732 |
+
.63109782867243, .01370605085442, 46.045198239483, 0,
|
| 733 |
+
.60423446262748, .65796119471738, np.nan, 1.9599639845401,
|
| 734 |
+
0]).reshape(5,9)
|
| 735 |
+
|
| 736 |
+
table_colnames = 'b se z pvalue ll ul df crit eform'.split()
|
| 737 |
+
|
| 738 |
+
table_rownames = '1bn._predict 2._predict 3._predict 4._predict 5._predict'.split()
|
| 739 |
+
|
| 740 |
+
|
| 741 |
+
results_trunc_negbin1.margins_pr = Bunch(
|
| 742 |
+
table=table,
|
| 743 |
+
table_colnames=table_colnames,
|
| 744 |
+
table_rownames=table_rownames,
|
| 745 |
+
)
|
| 746 |
+
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/statsmodels/discrete/tests/results/ships.csv
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ship,yr_con,yr_op,service,accident,op_75_79,co_65_69,co_70_74,co_75_79
|
| 2 |
+
1,1,1,127,0,0,0,0,0
|
| 3 |
+
1,1,2,63,0,1,0,0,0
|
| 4 |
+
1,2,1,1095,3,0,1,0,0
|
| 5 |
+
1,2,2,1095,4,1,1,0,0
|
| 6 |
+
1,3,1,1512,6,0,0,1,0
|
| 7 |
+
1,3,2,3353,18,1,0,1,0
|
| 8 |
+
1,4,1,,,0,0,0,1
|
| 9 |
+
1,4,2,2244,11,1,0,0,1
|
| 10 |
+
2,1,1,44882,39,0,0,0,0
|
| 11 |
+
2,1,2,17176,29,1,0,0,0
|
| 12 |
+
2,2,1,28609,58,0,1,0,0
|
| 13 |
+
2,2,2,20370,53,1,1,0,0
|
| 14 |
+
2,3,1,7064,12,0,0,1,0
|
| 15 |
+
2,3,2,13099,44,1,0,1,0
|
| 16 |
+
2,4,1,,,0,0,0,1
|
| 17 |
+
2,4,2,7117,18,1,0,0,1
|
| 18 |
+
3,1,1,1179,1,0,0,0,0
|
| 19 |
+
3,1,2,552,1,1,0,0,0
|
| 20 |
+
3,2,1,781,0,0,1,0,0
|
| 21 |
+
3,2,2,676,1,1,1,0,0
|
| 22 |
+
3,3,1,783,6,0,0,1,0
|
| 23 |
+
3,3,2,1948,2,1,0,1,0
|
| 24 |
+
3,4,1,,,0,0,0,1
|
| 25 |
+
3,4,2,274,1,1,0,0,1
|
| 26 |
+
4,1,1,251,0,0,0,0,0
|
| 27 |
+
4,1,2,105,0,1,0,0,0
|
| 28 |
+
4,2,1,288,0,0,1,0,0
|
| 29 |
+
4,2,2,192,0,1,1,0,0
|
| 30 |
+
4,3,1,349,2,0,0,1,0
|
| 31 |
+
4,3,2,1208,11,1,0,1,0
|
| 32 |
+
4,4,1,,,0,0,0,1
|
| 33 |
+
4,4,2,2051,4,1,0,0,1
|
| 34 |
+
5,1,1,45,0,0,0,0,0
|
| 35 |
+
5,1,2,,,1,0,0,0
|
| 36 |
+
5,2,1,789,7,0,1,0,0
|
| 37 |
+
5,2,2,437,7,1,1,0,0
|
| 38 |
+
5,3,1,1157,5,0,0,1,0
|
| 39 |
+
5,3,2,2161,12,1,0,1,0
|
| 40 |
+
5,4,1,,,0,0,0,1
|
| 41 |
+
5,4,2,542,1,1,0,0,1
|