Docstrings
Страница в процессе перевода. |
#
StatsAPI.HypothesisTest
— Type
HypothesisTest
Abstract supertype for all statistical hypothesis tests. Subtypes must implement pvalue
at a minimum and may also implement functions such as confint
, nobs
, and dof
as appropriate.
#
StatsAPI.RegressionModel
— Type
RegressionModel <: StatisticalModel
Abstract supertype for all regression models.
#
StatsAPI.StatisticalModel
— Type
StatisticalModel
Abstract supertype for all statistical models.
#
StatsAPI.adjr2
— Method
adjr2(model::StatisticalModel, variant::Symbol)
adjr²(model::StatisticalModel, variant::Symbol)
Adjusted pseudo-coefficient of determination (adjusted pseudo R-squared). For nonlinear models, one of the several pseudo R² definitions must be chosen via variant
. The only currently supported variants are :MacFadden
, defined as and :devianceratio
, defined as . In these formulas, is the likelihood of the model, that of the null model (the model including only the intercept), is the deviance of the model, is the deviance of the null model, is the number of observations (given by nobs
) and is the number of consumed degrees of freedom of the model (as returned by dof
).
#
StatsAPI.adjr2
— Method
adjr2(model::StatisticalModel)
adjr²(model::StatisticalModel)
Adjusted coefficient of determination (adjusted R-squared).
For linear models, the adjusted R² is defined as , with the coefficient of determination, the number of observations, and the number of coefficients (including the intercept). This definition is generally known as the Wherry Formula I.
#
StatsAPI.aic
— Method
aic(model::StatisticalModel)
Akaike’s Information Criterion, defined as , with the likelihood of the model, and k
its number of consumed degrees of freedom (as returned by dof
).
#
StatsAPI.aicc
— Method
aicc(model::StatisticalModel)
Corrected Akaike’s Information Criterion for small sample sizes (Hurvich and Tsai 1989), defined as , with the likelihood of the model, its number of consumed degrees of freedom (as returned by dof
), and the number of observations (as returned by nobs
).
#
StatsAPI.bic
— Method
bic(model::StatisticalModel)
Bayesian Information Criterion, defined as , with the likelihood of the model, its number of consumed degrees of freedom (as returned by dof
), and the number of observations (as returned by nobs
).
#
StatsAPI.coef
— Function
coef(model::StatisticalModel)
Return the coefficients of the model.
#
StatsAPI.coefnames
— Function
coefnames(model::StatisticalModel)
Return the names of the coefficients.
#
StatsAPI.coeftable
— Function
coeftable(model::StatisticalModel; level::Real=0.95)
Return a table with coefficients and related statistics of the model. level
determines the level for confidence intervals (by default, 95%).
The returned CoefTable
object implements the Tables.jl interface, and can be converted e.g. to a DataFrame
via using DataFrames; DataFrame(coeftable(model))
.
#
StatsAPI.confint
— Function
confint(model::StatisticalModel; level::Real=0.95)
Compute confidence intervals for coefficients, with confidence level level
(by default 95%).
#
StatsAPI.cooksdistance
— Function
cooksdistance(model::RegressionModel)
Compute Cook’s distance for each observation in linear model model
, giving an estimate of the influence of each data point.
#
StatsAPI.crossmodelmatrix
— Method
crossmodelmatrix(model::RegressionModel)
Return X’X
where X
is the model matrix of model
. This function will return a pre-computed matrix stored in model
if possible.
#
StatsAPI.deviance
— Function
deviance(model::StatisticalModel)
Return the deviance of the model relative to a reference, which is usually when applicable the saturated model. It is equal, up to a constant, to , with the likelihood of the model.
#
StatsAPI.dof
— Function
dof(model::StatisticalModel)
Return the number of degrees of freedom consumed in the model, including when applicable the intercept and the distribution’s dispersion parameter.
#
StatsAPI.dof_residual
— Function
dof_residual(model::RegressionModel)
Return the residual degrees of freedom of the model.
#
StatsAPI.fit
— Function
Fit a statistical model.
#
StatsAPI.fit!
— Function
Fit a statistical model in-place.
#
StatsAPI.fitted
— Function
fitted(model::RegressionModel)
Return the fitted values of the model.
#
StatsAPI.gvif
— Function
gvif(m::RegressionModel; scale=false)
Compute the generalized variance inflation factor (GVIF).
If scale=true
, then each GVIF is scaled by the degrees of freedom for (number of coefficients associated with) the predictor: .
The GVIF measures the increase in the variance of a (group of) parameter’s estimate in a model with multiple parameters relative to the variance of a parameter’s estimate in a model containing only that parameter. For continuous, numerical predictors, the GVIF is the same as the VIF, but for categorical predictors, the GVIF provides a single number for the entire group of contrast-coded coefficients associated with a categorical predictor.
See also vif
.
References
Fox, J., & Monette, G. (1992). Generalized Collinearity Diagnostics. Journal of the American Statistical Association, 87(417), 178. doi:10.2307/2290467
#
StatsAPI.informationmatrix
— Function
informationmatrix(model::StatisticalModel; expected::Bool = true)
Return the information matrix of the model. By default the Fisher information matrix is returned, while the observed information matrix can be requested with expected = false
.
#
StatsAPI.isfitted
— Function
isfitted(model::StatisticalModel)
Indicate whether the model has been fitted.
#
StatsAPI.islinear
— Function
islinear(model::StatisticalModel)
Indicate whether the model is linear.
#
StatsAPI.leverage
— Function
leverage(model::RegressionModel)
Return the diagonal of the projection matrix of the model.
#
StatsAPI.linearpredictor
— Function
linearpredictor(model::RegressionModel)
Return the model’s linear predictor, Xβ
where X
is the model matrix and β
is the vector of coefficients, or Xβ + offset
if the model was fit with an offset.
#
StatsAPI.linearpredictor!
— Function
linearpredictor!(storage, model::RegressionModel)
In-place version of linearpredictor
, storing the result in storage
.
#
StatsAPI.loglikelihood
— Function
loglikelihood(model::StatisticalModel)
loglikelihood(model::StatisticalModel, observation)
Return the log-likelihood of the model.
With an observation
argument, return the contribution of observation
to the log-likelihood of model
.
If observation
is a Colon
, return a vector of each observation’s contribution to the log-likelihood of the model. In other words, this is the vector of the pointwise log-likelihood contributions.
In general, sum(loglikehood(model, :)) == loglikelihood(model)
.
#
StatsAPI.meanresponse
— Function
meanresponse(model::RegressionModel)
Return the mean of the response.
#
StatsAPI.modelmatrix
— Function
modelmatrix(model::RegressionModel)
Return the model matrix (a.k.a. the design matrix).
#
StatsAPI.mss
— Function
mss(model::StatisticalModel)
Return the model sum of squares.
#
StatsAPI.nobs
— Function
nobs(model::StatisticalModel)
Return the number of independent observations on which the model was fitted. Be careful when using this information, as the definition of an independent observation may vary depending on the model, on the format used to pass the data, on the sampling plan (if specified), etc.
#
StatsAPI.nulldeviance
— Function
nulldeviance(model::StatisticalModel)
Return the deviance of the null model, obtained by dropping all independent variables present in model
.
If model
includes an intercept, the null model is the one with only the intercept; otherwise, it is the one without any predictor (not even the intercept).
#
StatsAPI.nullloglikelihood
— Function
nullloglikelihood(model::StatisticalModel)
Return the log-likelihood of the null model, obtained by dropping all independent variables present in model
.
If model
includes an intercept, the null model is the one with only the intercept; otherwise, it is the one without any predictor (not even the intercept).
#
StatsAPI.offset
— Function
offset(model::RegressionModel)
Return the offset used in the model, i.e. the term added to the linear predictor with known coefficient 1, or nothing
if the model was not fit with an offset.
#
StatsAPI.params
— Function
params(model)
Return all parameters of a model.
#
StatsAPI.predict
— Function
predict(model::RegressionModel, [newX])
Form the predicted response of model
. An object with new covariate values newX
can be supplied, which should have the same type and structure as that used to fit model
; e.g. for a GLM it would generally be a DataFrame
with the same variable names as the original predictors.
#
StatsAPI.predict!
— Function
predict!
In-place version of predict
.
#
StatsAPI.pvalue
— Function
pvalue(test)
Compute the p-value for a given significance test.
#
StatsAPI.r2
— Method
r2(model::StatisticalModel, variant::Symbol)
r²(model::StatisticalModel, variant::Symbol)
Pseudo-coefficient of determination (pseudo R-squared).
For nonlinear models, one of several pseudo R² definitions must be chosen via variant
. Supported variants are:
-
:MacFadden
(a.k.a. likelihood ratio index), defined as ; -
:CoxSnell
, defined as ; -
:Nagelkerke
, defined as . -
:devianceratio
, defined as .
In the above formulas, is the likelihood of the model, is the likelihood of the null model (the model with only an intercept), is the deviance of the model (from the saturated model), is the deviance of the null model, is the number of observations (given by nobs
).
The Cox-Snell and the deviance ratio variants both match the classical definition of R² for linear models.
#
StatsAPI.r2
— Method
r2(model::StatisticalModel)
r²(model::StatisticalModel)
Coefficient of determination (R-squared).
For a linear model, the R² is defined as , with the explained sum of squares and the total sum of squares.
#
StatsAPI.reconstruct
— Function
reconstruct(model::RegressionModel[, newY])
Reconstruct explanatory variables from model
. An object with new response values newX
can be supplied, which should have the same type and structure as the output of predict(model)
.
#
StatsAPI.reconstruct!
— Function
reconstruct!
In-place version of reconstruct
.
#
StatsAPI.residuals
— Function
residuals(model::RegressionModel)
Return the residuals of the model.
#
StatsAPI.response
— Function
response(model::RegressionModel)
Return the model response (a.k.a. the dependent variable).
#
StatsAPI.responsename
— Function
responsename(model::RegressionModel)
Return the name of the model response (a.k.a. the dependent variable).
#
StatsAPI.rss
— Function
rss(model::StatisticalModel)
Return the residual sum of squares of the model.
#
StatsAPI.score
— Function
score(model::StatisticalModel)
Return the score of the model, that is the gradient of the log-likelihood with respect to the coefficients.
#
StatsAPI.stderror
— Method
stderror(model::StatisticalModel)
Return the standard errors for the coefficients of the model.
#
StatsAPI.vcov
— Function
vcov(model::StatisticalModel)
Return the variance-covariance matrix for the coefficients of the model.
#
StatsAPI.vif
— Function
vif(m::RegressionModel)
Compute the variance inflation factor (VIF).
The VIF measures the increase in the variance of a parameter’s estimate in a model with multiple parameters relative to the variance of a parameter’s estimate in a model containing only that parameter.
See also gvif
.
This method will fail if there is (numerically) perfect multicollinearity, i.e. rank deficiency. In that case though, the VIF is not particularly informative anyway. |
#
StatsAPI.weights
— Function
weights(model::StatisticalModel)
Return the weights used in the model.