statsmodels.gam.generalized_additive_model.GLMGamResults.score_test#

GLMGamResults.score_test(exog_extra=None, params_constrained=None, hypothesis='joint', cov_type=None, cov_kwds=None, k_constraints=None, observed=True, *, return_object=None)#

score test for restrictions or for omitted variables

Null Hypothesis : constraints are satisfied

Alternative Hypothesis : at least one of the constraints does not hold

This allows to specify restricted and unrestricted model properties in three different ways

  • fit_constrained result: model contains score and hessian function for the full, unrestricted model, but the parameter estimate in the results instance is for the restricted model. This is the case if the model was estimated with fit_constrained.

  • restricted model with variable addition: If exog_extra is not None, then it is assumed that the current model is a model with zero restrictions and the unrestricted model is given by adding exog_extra as additional explanatory variables.

  • unrestricted model with restricted parameters explicitly provided. If params_constrained is not None, then the model is assumed to be for the unrestricted model, but the provided parameters are for the restricted model. TODO: This case will currently only work for nonrobust cov_type, otherwise we will also need the restriction matrix provided by the user.

Parameters:
exog_extraarray_like, tuple of array_like, or None, optional

Explanatory variables that are jointly tested for inclusion in the model, i.e., omitted variables. A 2-tuple of array_like can be given to jointly test the addition of exogenous regressors to both the mean and a second (e.g., precision or scale) model component. Columns that are linear combinations of other columns of exog_extra or of the exog of the model, for example the linear term in a spline basis, do not add a constraint. The number of constraints is the rank of exog_extra after projecting out exog, and the joint test statistic is computed from a basis of that space, see Notes. This is not implemented for the 2-tuple.

params_constrainedarray_like, optional

estimated parameter of the restricted model. This can be the parameter estimate for the current when testing for omitted variables.

hypothesis{‘joint’, ‘separate’}, optional

If hypothesis is ‘joint’, then the chisquare test results for the joint hypothesis that all constraints hold is returned. If hypothesis is ‘separate’, then z-test results for each constraint is returned. This is currently only implemented for cov_type=”nonrobust”.

cov_typestr, optional

Warning: only partially implemented so far, currently only “nonrobust” and “HC0” are supported. If cov_type is None, then the cov_type specified in fit for the Wald tests is used. If the cov_type argument is not None, then it will be used instead of the Wald cov_type given in fit.

cov_kwdsdict, optional

Keyword arguments for the specified cov_type.

k_constraintsint or None, optional

Number of constraints that were used in the estimation of params restricted relative to the number of exog in the model. This must be provided if no exog_extra are given. If exog_extra is not None, then k_constraints is assumed to be zero if it is None.

r_matrixarray_like or None, optional

Restriction matrix for the constraints. If not provided, it is constructed from self.constraints or from exog_extra.

scalefloat or None, optional

Optional scale to use in the score and Hessian calculation, for example for the results of a fit_constrained estimation with fixed scale.

observedbool, optional

If True, then the observed Hessian is used in calculating the covariance matrix of the score. If false then the expected information matrix is used. This currently only applies to GLM where EIM is available. Warning: This option might still change.

return_objectbool, optional

No longer used. score_test always returns a ScoreTestResult, which unpacks as the (statistic, pvalue) tuple this function has always returned, with k_constraint (and distribution) available as attributes.

Deprecated since version 0.15.0: This parameter has no effect and will be removed in a future release.

Returns:
ScoreTestResult

See ScoreTestResult for a description of the attributes. For hypothesis="joint", statistic and pvalue are the chisquare test and k_constraint is the number of constraints. For hypothesis="separate", statistic and pvalue are arrays with one z-test per constraint, and k_constraint is None.

Notes

Status: experimental, several options are not implemented yet or are not verified yet. Currently available options might also still change.

cov_type is ‘nonrobust’:

The covariance matrix for the score is based on the Hessian, i.e. observed information matrix or optionally on the expected information matrix.

cov_type is ‘HC0’

The covariance matrix of the score is the simple empirical covariance of score_obs without degrees of freedom correction.

Redundant columns in exog_extra

The number of constraints is the rank of exog_extra after projecting out the exog of the model. The rank is the number of singular values larger than 1e-7 of the matrix of the residuals of this projection, with each column divided by the norm of the corresponding column of exog_extra. For a single column this is the tolerance of R’s lm: the column is redundant if the norm of its residual is less than 1e-7 times its norm. For several columns this is not the sequential rule of lm, so a column can be dropped here that lm keeps and the other way round. R’s glm, and so anova(..., test="Rao"), uses the tighter tolerance min(1e-7, epsilon / 1000), which is 1e-11 with the default epsilon. It keeps columns that are linearly dependent on other columns up to noise of relative size 1e-9 or 1e-8, which are dropped here.

If exog_extra has redundant columns and hypothesis is “joint”, then it is replaced by an orthonormal basis of its columns after projecting out exog. The test statistic is invariant to this change of basis, and the number of constraints and the degrees of freedom of the p-value are the rank of the basis. Without this, the number of columns is used as the number of constraints and the p-value is too large, or the covariance of the score is singular. If all columns of exog_extra are in the span of exog, then there is no constraint to test and a ValueError is raised.

The projection is not weighted. For a GLM with freq_weights or var_weights, a column that differs from the span of exog only on observations with weights close to zero, for example 1e-12, adds no information to the statistic but is not redundant here, so it is counted in the degrees of freedom.

Changed in version 0.15.1: With exog_extra and hypothesis="joint", the number of constraints is the rank of exog_extra after projecting out exog instead of its number of columns, and the statistic is computed from a basis of the independent part, so both change if columns of exog_extra are redundant. A ValueError is raised if all columns are redundant, if exog_extra has nan or infinite values or if it does not have as many rows as exog.