Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d7a3217
ENH: robust skew, kurtosis, replicate Kim,White examples
josef-pkt Jun 1, 2013
077c07f
ENH: Brown-Forsythe Anova, plus test for variance comparison
josef-pkt Jun 12, 2013
2b5aeaa
ENH: add TrimmedMean class, Welch's Anova with and without trimming
josef-pkt Jun 14, 2013
16885ad
DOC: improve docstrings, internal: switch misnamed df_num, df_denom
josef-pkt Jun 14, 2013
9f12663
ENH: add trimming option to anova_bfm
josef-pkt Jun 15, 2013
3023ca2
ENH: add uncommitted changes, anova_oneway, anova_scale
josef-pkt Jan 22, 2020
037d1c8
MAINT: get it to run again
josef-pkt Feb 19, 2020
4358610
STY: some pep-8 cleaning
josef-pkt Feb 19, 2020
35089f7
BUG/TST: fix results, unit tests against R packages
josef-pkt Feb 20, 2020
41ea64c
BUG/ENH: fix trim var for anova, add anova_generic (from_stats)
josef-pkt Feb 22, 2020
bcbe285
BUG/TST: fix keyword names, unit tests for anovas
josef-pkt Mar 17, 2020
9c9a056
ENH: add effect size for oneway anova
josef-pkt Mar 18, 2020
a5a478c
REF: move anova_generic function to stats.oneway
josef-pkt Mar 19, 2020
24ccdbf
BUG/TST: unit tests effect size
josef-pkt Mar 19, 2020
4108fea
ENH: add oneway_equivalence_generic with Wellek effect size
josef-pkt Mar 19, 2020
b4e1fca
ENH/DOC: add _fstat2effectsize, improve docstrings
josef-pkt Apr 7, 2020
7baa84c
ENH/REF: add anova for data, enh and fix anova_generic
josef-pkt May 13, 2020
a298cbd
ENH: add "bf" option to effectsize_oneway, add example to docstring
josef-pkt May 15, 2020
da907be
ENH/REF: add power_equivalence_oneway and simulate, refactor api, ren…
josef-pkt May 18, 2020
558b2cd
ENH/REF: improve handling of effectsize types, more consistent
josef-pkt May 21, 2020
9fbbcdf
ENH: add anova for equal dispersion (levene, brown-forsythe variance …
josef-pkt May 23, 2020
7f127f0
ENH: add equivalence_scale_oneway, changes to scale_transform options
josef-pkt May 25, 2020
2e5f7f2
ENH: add noncentrality for OLS wald_test
josef-pkt May 29, 2020
68a6d27
TST/DOC/CLN: test_simulate_equivalence, some docstring, code cleanup
josef-pkt Jun 2, 2020
0e09510
BUG/REF/TST: wrong computation in _fstat2effectsize, various cleanups…
josef-pkt Jun 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions statsmodels/stats/contrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,3 +670,128 @@ def t_test_pairwise(result, term_name, method='hs', alpha=0.05,
contrast_labels=labels,
term_encoding_matrix=cm)
return res


def _offset_constraint(r_matrix, params_est, params_alt):
"""offset to the value of a linear constraint for new params

usage:
(cm, v) is original constraint

vo = offset_constraint(cm, res2.params, params_alt)
fs = res2.wald_test((cm, v + vo))
nc = fs.statistic * fs.df_num

"""
diff_est = r_matrix @ params_est
diff_alt = r_matrix @ params_alt
return diff_est - diff_alt


def wald_test_noncent(params, r_matrix, value, results, diff=None, joint=True):
"""Moncentrality parameter for a wald test in model results

The null hypothesis is ``diff = r_matrix @ params - value = 0``

Parameters
----------
params : ndarray
parameters of the model at which to evaluate noncentrality. This can
be estimated parameters or parameters under an alternative.
r_matrix : ndarray
Restriction matrix or contrasts for the Null hypothesis

value : None or ndarray
Value of the linear combination of parameters under the null
hypothesis. If value is None, then it will be replace by zero.
results : Results instance of a model
The results instance is used to compute the covariance matrix of the
linear constraints using `cov_params.
diff : None or ndarray
If diff is not None, then it will be used instead of
``diff = r_matrix @ params - value``
joint : bool
If joint is True, then the noncentrality parameter for the joint
hypothesis will be returned.
If joint is True, then an array of noncentrality parameters will be
returned, where elements correspond to rows of the restriction matrix.
This correspond to the `t_test` in models and is not a quadratic form.

Returns
-------
nc : float or ndarray
Noncentrality parameter for Wald tests, correspondig to `wald_test`
or `t_test` depending on whether `joint` is true or not.
It needs to be divided by nobs to obtain effect size.


Notes
-----
Status : experimental, API will likely change

"""
if diff is None:
diff = r_matrix @ params - value # at parameter under alternative

cov_c = results.cov_params(r_matrix=r_matrix)
if joint:
nc = diff @ np.linalg.solve(cov_c, diff)
else:
nc = diff / np.sqrt(np.diag(cov_c))
return nc


def wald_test_noncent_generic(params, r_matrix, value, cov_params, diff=None,
joint=True):
"""noncentrality parameter for a wald test

The null hypothesis is ``diff = r_matrix @ params - value = 0``

Parameters
----------
params : ndarray
parameters of the model at which to evaluate noncentrality. This can
be estimated parameters or parameters under an alternative.
r_matrix : ndarray
Restriction matrix or contrasts for the Null hypothesis

value : None or ndarray
Value of the linear combination of parameters under the null
hypothesis. If value is None, then it will be replace by zero.
cov_params : ndarray
covariance matrix of the parameter estimates
diff : None or ndarray
If diff is not None, then it will be used instead of
``diff = r_matrix @ params - value``
joint : bool
If joint is True, then the noncentrality parameter for the joint
hypothesis will be returned.
If joint is True, then an array of noncentrality parameters will be
returned, where elements correspond to rows of the restriction matrix.
This correspond to the `t_test` in models and is not a quadratic form.

Returns
-------
nc : float or ndarray
Noncentrality parameter for Wald tests, correspondig to `wald_test`
or `t_test` depending on whether `joint` is true or not.
It needs to be divided by nobs to obtain effect size.


Notes
-----
Status : experimental, API will likely change
"""
if value is None:
value = 0
if diff is None:
# at parameter under alternative
diff = r_matrix @ params - value

c = r_matrix
cov_c = c.dot(cov_params).dot(c.T)
if joint:
nc = diff @ np.linalg.solve(cov_c, diff)
else:
nc = diff / np.sqrt(np.diag(cov_c))
return nc
Loading