Struct ndarray_glm::Fit

source ·
pub struct Fit<'a, M, F>where
    M: Glm,
    F: Float,{
    pub result: Array1<F>,
    pub options: FitOptions<F>,
    pub model_like: F,
    pub n_iter: usize,
    /* private fields */
}
Expand description

the result of a successful GLM fit

Fields§

§result: Array1<F>

The parameter values that maximize the likelihood as given by the IRLS regression.

§options: FitOptions<F>

The options used for this fit.

§model_like: F

The value of the likelihood function for the fit result.

§n_iter: usize

The number of overall iterations taken in the IRLS.

Implementations§

source§

impl<'a, M, F> Fit<'a, M, F>where M: Glm, F: 'static + Float,

source

pub fn aic(&self) -> F

Returns the Akaike information criterion for the model fit.

source

pub fn bic(&self) -> F

Returns the Bayesian information criterion for the model fit.

source

pub fn covariance(&self) -> RegressionResult<Ref<'_, Array2<F>>>

The covariance matrix estimated by the Fisher information and the dispersion parameter (for families with a free scale). The matrix is cached to avoid repeating the potentially expensive matrix inversion.

source

pub fn deviance(&self) -> F

Returns the deviance of the fit: twice the difference between the saturated likelihood and the model likelihood. Asymptotically this fits a chi-squared distribution with self.ndf() degrees of freedom. Note that the regularized likelihood is used here.

source

pub fn dispersion(&self) -> F

The dispersion parameter(typically denoted phi) which relates the variance of the y values with the variance of the response distribution: Var[y] = phi * Var[mu]. Identically one for logistic, binomial, and Poisson regression. For others (linear, gamma) the dispersion parameter is estimated from the data. This is equal to the total deviance divided by the degrees of freedom. For OLS linear regression this is equal to the sum of (y_i - mu_i)^2 / (n-p), an estimate of sigma^2; with no covariates it is equal to the sample variance.

source

pub fn expectation<S>( &self, data_x: &ArrayBase<S, Ix2>, lin_off: Option<&Array1<F>> ) -> Array1<F>where S: Data<Elem = F>,

👎Deprecated since 0.0.10: use predict() instead
source

pub fn fisher(&self, params: &Array1<F>) -> Array2<F>

Returns the fisher information (the negative hessian of the likelihood) at the parameter values given. The regularization is included.

source

pub fn lr_test(&self) -> F

Perform a likelihood-ratio test, returning the statistic -2*ln(L_0/L) where L_0 is the likelihood of the best-fit null model (with no parameters but the intercept) and L is the likelihood of the fit result. The number of degrees of freedom of this statistic, equal to the number of parameters fixed to zero to form the null model, is test_ndf(). By Wilks’ theorem this statistic is asymptotically chi-squared distributed with this number of degrees of freedom.

source

pub fn lr_test_against(&self, alternative: &Array1<F>) -> F

Perform a likelihood-ratio test against a general alternative model, not necessarily a null model. The alternative model is regularized the same way that the regression resulting in this fit was. The degrees of freedom cannot be generally inferred.

source

pub fn ndf(&self) -> usize

Returns the residual degrees of freedom in the model, i.e. the number of data points minus the number of parameters. Not to be confused with test_ndf(), the degrees of freedom in the statistical tests of the fit.

source

pub fn null_like(&self) -> F

Returns the likelihood given the null model, which fixes all parameters to zero except the intercept (if it is used). A total of test_ndf() parameters are constrained.

source

pub fn predict<S>( &self, data_x: &ArrayBase<S, Ix2>, lin_off: Option<&Array1<F>> ) -> Array1<F>where S: Data<Elem = F>,

Returns the expected value of Y given the input data X. This data need not be the training data, so an option for linear offsets is provided. Panics if the number of covariates in the data matrix is not consistent with the training set. The data matrix may need to be padded by ones if it is not part of a Model. The utility::one_pad() function facilitates this.

source

pub fn resid_dev(&self) -> Array1<F>

Return the deviance residuals for each point in the training data. Equal to sign(y-E[y|x])*sqrt(-2*(L[y|x] - L_sat[y])). This is usually a better choice for non-linear models. NaNs might be possible if L[y|x] > L_sat[y] due to floating-point operations. These are not checked or clipped right now.

source

pub fn resid_dev_std(&self) -> RegressionResult<Array1<F>>

Return the standardized deviance residuals, also known as the “internally studentized deviance residuals”. This is generally applicable for outlier detection, although the influence of each point on the fit is only approximately accounted for. d / sqrt(phi * (1 - h)) where d is the deviance residual, phi is the dispersion (e.g. sigma^2 for linear regression, 1 for logistic regression), and h is the leverage.

source

pub fn resid_part(&self) -> Array1<F>

Return the partial residuals.

source

pub fn resid_pear(&self) -> Array1<F>

Return the Pearson residuals for each point in the training data. This is equal to (y - E[y])/sqrt(V(E[y])), where V is the variance function. These are not scaled by the sample standard deviation for families with a free dispersion parameter like linear regression.

source

pub fn resid_pear_std(&self) -> RegressionResult<Array1<F>>

Return the standardized Pearson residuals for every observation. Also known as the “internally studentized Pearson residuals”. (y - E[y]) / (sqrt(Var[y] * (1 - h))) where h is a vector representing the leverage for each observation.

source

pub fn resid_resp(&self) -> Array1<F>

Return the response residuals, or fitting deviation, for each data point in the fit; that is, the difference y - E[y|x] where the expectation value is the y value predicted by the model given x.

source

pub fn resid_student(&self) -> RegressionResult<Array1<F>>

Return the studentized residuals, which are the changes in the fit likelihood resulting from leaving each observation out. This is a robust and general method for outlier detection, although a one-step approximation is used to avoid re-fitting the model completely for each observation. If the linear errors are standard normally distributed then this statistic should follow a t-distribution with self.ndf() - 1 degrees of freedom.

source

pub fn resid_work(&self) -> Array1<F>

Returns the working residuals d\eta/d\mu * (y - E{y|x}). This should be equal to the response residuals divided by the variance function (as opposed to the square root of the variance as in the Pearson residuals).

source

pub fn score(&self, params: &Array1<F>) -> Array1<F>

Returns the score function (the gradient of the likelihood) at the parameter values given. It should be zero within FPE at the minimized result.

source

pub fn score_test(&self) -> RegressionResult<F>

Returns the score test statistic. This statistic is asymptotically chi-squared distributed with test_ndf() degrees of freedom.

source

pub fn score_test_against(&self, alternative: Array1<F>) -> RegressionResult<F>

Returns the score test statistic compared to another set of model parameters, not necessarily a null model. The degrees of freedom cannot be generally inferred.

source

pub fn test_ndf(&self) -> usize

The degrees of freedom for the likelihood ratio test, the score test, and the Wald test. Not to be confused with ndf(), the degrees of freedom in the model fit.

source

pub fn wald_test(&self) -> F

Returns the Wald test statistic compared to a null model with only an intercept (if one is used). This statistic is asymptotically chi-squared distributed with test_ndf() degrees of freedom.

source

pub fn wald_test_against(&self, alternative: &Array1<F>) -> F

Returns the Wald test statistic compared to another specified model fit instead of the null model. The degrees of freedom cannot be generally inferred.

source

pub fn wald_z(&self) -> RegressionResult<Array1<F>>

Returns the signed square root of the Wald test statistic for each parameter. Since it does not account for covariance between the parameters it may not be accurate.

source§

impl<'a, F> Fit<'a, Linear, F>where F: 'static + Float,

Specialized functions for OLS.

source

pub fn r_sq(&self) -> F

Returns the coefficient of multiple correlation, R^2.

source

pub fn resid_sum_sq(&self) -> F

Returns the residual sum of squares, i.e. the sum of the squared residuals.

Auto Trait Implementations§

§

impl<'a, M, F> !RefUnwindSafe for Fit<'a, M, F>

§

impl<'a, M, F> !Send for Fit<'a, M, F>

§

impl<'a, M, F> !Sync for Fit<'a, M, F>

§

impl<'a, M, F> Unpin for Fit<'a, M, F>where F: Unpin, M: Unpin,

§

impl<'a, M, F> !UnwindSafe for Fit<'a, M, F>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V