statsmodels.regression.linear_model.OLSResults.el_test#
- OLSResults.el_test(b0_vals, param_nums, return_weights=0, ret_params=0, method='nm', stochastic_exog=1, *, result_object=None)[source]#
Test single or joint hypotheses using Empirical Likelihood.
- Parameters:
- b0_vals1darray
The hypothesized value of the parameter to be tested.
- param_nums1darray
The parameter number to be tested.
- return_weightsbool
If true, returns the weights that optimize the likelihood ratio at b0_vals. The default is False.
- ret_paramsbool
If true, returns the parameter vector that maximizes the likelihood ratio at b0_vals. Also returns the weights. The default is False. Has no effect when
len(param_nums) == len(params), since there are then no nuisance parameters to report.- method
str Can either be ‘nm’ for Nelder-Mead or ‘powell’ for Powell. The optimization method that optimizes over nuisance parameters. The default is ‘nm’.
- stochastic_exogbool
When True, the exogenous variables are assumed to be stochastic. When the regressors are nonstochastic, moment conditions are placed on the exogenous variables. Confidence intervals for stochastic regressors are at least as large as non-stochastic regressors. The default is True.
- result_objectbool,
optional Flag indicating whether to return the results as an
ELTestResultNamedTuple instead of a plain tuple. When the nuisance parameters are produced –ret_paramsis True andlen(param_nums) < len(params)– the NamedTuple holds the same four elements as the legacy tuple, so it unpacks identically and is always returned, with no warning. Every other combination returns the shorter legacy tuple by default and issues aFutureWarning.Deprecated since version 0.15.0: In release 0.16.0 or after July 2027, whichever is later, the default will change to returning an
ELTestResult. Setresult_object=Trueto opt in now, orresult_object=Falseto silence the warning and keep the current return type.ELTestResultwill become mandatory in release 0.17.0 or after July 2028, whichever is later.
- Returns:
ELTestResultA NamedTuple with fields
statistic,pvalue,weightsandnuisance_params(weightsisNoneunlessreturn_weightsorret_paramsis True;nuisance_paramsisNoneunlessret_paramsis True andlen(param_nums) < len(params)). SeeELTestResult.This is returned whenever
result_object=True. It is also returned by default when the nuisance parameters were produced – that is, whenret_paramsis True andlen(param_nums) < len(params)– because the NamedTuple then has exactly the same four elements as the legacy tuple and so unpacks identically; that case is adopted silently.Otherwise(thedeprecateddefault),aplaintuplewhoselengthdependsonreturn_weightsandret_params,madeupofasubset- of:
- llr
float -2 times the log-likelihood ratio for the hypothesized values.
- pval
float The p-value of the test.
- weights
ndarray,optional The weights that optimize the likelihood ratio at b0_vals.
- nuisance_params
ndarray,optional The parameter vector that maximizes the likelihood ratio at b0_vals.
Examples
>>> import statsmodels.api as sm >>> data = sm.datasets.stackloss.load() >>> endog = data.endog >>> exog = sm.add_constant(data.exog) >>> model = sm.OLS(endog, exog) >>> fitted = model.fit() >>> fitted.params >>> array([-39.91967442, 0.7156402 , 1.29528612, -0.15212252]) >>> fitted.rsquared >>> 0.91357690446068196 >>> # Test that the slope on the first variable is 0 >>> fitted.el_test([0], [1]) >>> (27.248146353888796, 1.7894660442330235e-07)