CompactGeneralizedLinearModel

Package: classreg.regr

Compact generalized linear regression model class

Description

CompactGeneralizedLinearModel is a compact generalized linear regression model object. It consumes less memory than a full generalized linear regression model (GeneralizedLinearModel) because it does not store the data used to fit the model. The compact model does not store the input data, so you cannot use it to perform certain tasks. However, you can use a compact generalized linear regression model to predict responses using new input data.

Fitting operations (fitlm, fitglm, ...) automatically use compact objects when you work with tall arrays. Fitting operations with in-memory tables and arrays produce full objects. You can use the compact method to make them smaller.

Construction

compactMdl = compact(mdl) returns a compact generalized linear regression model compactMdl from the full generalized linear regression model mdl. For more information, see compact.

Input Arguments

expand all

Full generalized linear regression model, specified as a GeneralizedLinearModel object.

Properties

expand all

This property is read-only.

Covariance matrix of coefficient estimates, specified as a p-by-p matrix of numeric values. p is the number of coefficients in the fitted model.

For details, see Coefficient Standard Errors and Confidence Intervals.

Data Types: single | double

This property is read-only.

Coefficient names, specified as a cell array of character vectors, each containing the name of the corresponding term.

Data Types: cell

This property is read-only.

Coefficient values, specified as a table. Coefficients contains one row for each coefficient and these columns:

  • Estimate — Estimated coefficient value

  • SE — Standard error of the estimate

  • tStatt-statistic for a test that the coefficient is zero

  • pValuep-value for the t-statistic

Use anova (only for a linear regression model) or coefTest to perform other tests on the coefficients. Use coefCI to find the confidence intervals of the coefficient estimates.

To obtain any of these columns as a vector, index into the property using dot notation. For example, obtain the estimated coefficient vector in the model mdl:

beta = mdl.Coefficients.Estimate

Data Types: table

This property is read-only.

Deviance of fit, specified as a numeric value. Deviance is useful for comparing two models when one is a special case of the other. The difference between the deviance of the two models has a chi-square distribution with degrees of freedom equal to the difference in the number of estimated parameters between the two models. For more information on deviance, see Deviance.

Data Types: single | double

This property is read-only.

Degrees of freedom for the error (residuals), equal to the number of observations minus the number of estimated coefficients, specified as a positive integer.

Data Types: double

This property is read-only.

Scale factor of the variance of the response, specified as a numeric value. Dispersion multiplies the variance function for the distribution.

For example, the variance function for the binomial distribution is p(1–p)/n, where p is the probability parameter and n is the sample size parameter. If Dispersion is near 1, the variance of the data appears to agree with the theoretical variance of the binomial distribution. If Dispersion is larger than 1, the data are “overdispersed” relative to the binomial distribution.

Data Types: double

This property is read-only.

Flag to indicate use of dispersion scale factor, specified as a logical value. Use DispersionEstimated to indicate whether fitglm used the Dispersion scale factor to compute standard errors for the coefficients in Coefficients.SE. If DispersionEstimated is false, then fitglm used the theoretical value of the variance.

  • DispersionEstimated can be false only for 'binomial' or 'poisson' distributions.

  • To set DispersionEstimated, set the DispersionFlag name-value pair in fitglm.

Data Types: logical

This property is read-only.

Generalized distribution information, specified as a structure with the following fields relating to the generalized distribution.

FieldDescription
NameName of the distribution. Options are: 'normal', 'binomial', 'poisson', 'gamma', or 'inverse gaussian'.
DevianceFunctionFunction that computes the components of the deviance as a function of the fitted parameter values and the response values.
VarianceFunctionFunction that computes the theoretical variance for the distribution as a function of the fitted parameter values. When DispersionEstimated is true, Dispersion multiplies the variance function in the computation of the coefficient standard errors.

Data Types: struct

This property is read-only.

Model information, specified as a LinearFormula object.

Display the formula of the fitted model mdl using dot notation:

mdl.Formula

This property is read-only.

Log likelihood of the model distribution at the response values, specified as a numeric value. The mean is fitted from the model, and other parameters are estimated as part of the model fit.

Data Types: single | double

This property is read-only.

Criterion for model comparison, specified as a structure with these fields:

  • AIC — Akaike information criterion. AIC = –2*logL + 2*m, where logL is the loglikelihood and m is the number of estimated parameters.

  • AICc — Akaike information criterion corrected for the sample size. AICc = AIC + (2*m*(m+1))/(n–m–1), where n is the number of observations.

  • BIC — Bayesian information criterion. BIC = –2*logL + m*log(n).

  • CAIC — Consistent Akaike information criterion. CAIC = –2*logL + m*(log(n)+1).

Information criteria are model selection tools that you can use to compare multiple models fit to the same data. These criteria are likelihood-based measures of model fit that include a penalty for complexity (specifically, the number of parameters). Different information criteria are distinguished by the form of the penalty.

When you compare multiple models, the model with the lowest information criterion value is the best-fitting model. The best-fitting model can vary depending on the criterion used for model comparison.

To obtain any of the criterion values as a scalar, index into the property using dot notation. For example, obtain the AIC value aic in the model mdl:

aic = mdl.ModelCriterion.AIC

Data Types: struct

This property is read-only.

Number of model coefficients, specified as a positive integer. NumCoefficients includes coefficients that are set to zero when the model terms are rank deficient.

Data Types: double

This property is read-only.

Number of estimated coefficients in the model, specified as a positive integer. NumEstimatedCoefficients does not include coefficients that are set to zero when the model terms are rank deficient. NumEstimatedCoefficients is the degrees of freedom for regression.

Data Types: double

This property is read-only.

Number of observations the fitting function used in fitting, specified as a positive integer. NumObservations is the number of observations supplied in the original table, dataset, or matrix, minus any excluded rows (set with the 'Exclude' name-value pair argument) or rows with missing values.

Data Types: double

This property is read-only.

Number of predictor variables used to fit the model, specified as a positive integer.

Data Types: double

This property is read-only.

Number of variables in the input data, specified as a positive integer. NumVariables is the number of variables in the original table or dataset, or the total number of columns in the predictor matrix and response vector.

NumVariables also includes any variables that are not used to fit the model as predictors or as the response.

Data Types: double

This property is read-only.

Names of predictors used to fit the model, specified as a cell array of character vectors.

Data Types: cell

This property is read-only.

Response variable name, specified as a character vector.

Data Types: char

This property is read-only.

R-squared value for the model, specified as a structure with five fields:

  • Ordinary — Ordinary (unadjusted) R-squared

  • Adjusted — R-squared adjusted for the number of coefficients

  • LLR — Log-likelihood ratio

  • Deviance — Deviance

  • AdjGeneralized — Adjusted generalized R-squared

The R-squared value is the proportion of total sum of squares explained by the model. The ordinary R-squared value relates to the SSR and SST properties:

Rsquared = SSR/SST = 1 - SSE/SST.

To obtain any of these values as a scalar, index into the property using dot notation. For example, the adjusted R-squared value in mdl is

r2 = mdl.Rsquared.Adjusted

Data Types: struct

This property is read-only.

Sum of squared errors (residuals), specified as a numeric value.

The Pythagorean theorem implies

SST = SSE + SSR,

where SST is the total sum of squares, SSE is the sum of squared errors, and SSR is the regression sum of squares.

Data Types: single | double

This property is read-only.

Regression sum of squares, specified as a numeric value. The regression sum of squares is equal to the sum of squared deviations of the fitted values from their mean.

The Pythagorean theorem implies

SST = SSE + SSR,

where SST is the total sum of squares, SSE is the sum of squared errors, and SSR is the regression sum of squares.

Data Types: single | double

This property is read-only.

Total sum of squares, specified as a numeric value. The total sum of squares is equal to the sum of squared deviations of the response vector y from the mean(y).

The Pythagorean theorem implies

SST = SSE + SSR,

where SST is the total sum of squares, SSE is the sum of squared errors, and SSR is the regression sum of squares.

Data Types: single | double

This property is read-only.

Information about variables contained in Variables, specified as a table with one row for each variable and the columns described in this table.

ColumnDescription
ClassVariable class, specified as a cell array of character vectors, such as 'double' and 'categorical'
Range

Variable range, specified as a cell array of vectors

  • Continuous variable — Two-element vector [min,max], the minimum and maximum values

  • Categorical variable — Vector of distinct variable values

InModelIndicator of which variables are in the fitted model, specified as a logical vector. The value is true if the model includes the variable.
IsCategoricalIndicator of categorical variables, specified as a logical vector. The value is true if the variable is categorical.

VariableInfo also includes any variables that are not used to fit the model as predictors or as the response.

Data Types: table

This property is read-only.

Names of variables, specified as a cell array of character vectors.

  • If the fit is based on a table or dataset, this property provides the names of the variables in the table or dataset.

  • If the fit is based on a predictor matrix and response vector, VariableNames contains the values specified by the 'VarNames' name-value pair argument of the fitting method. The default value of 'VarNames' is {'x1','x2',...,'xn','y'}.

VariableNames also includes any variables that are not used to fit the model as predictors or as the response.

Data Types: cell

Methods

coefCIConfidence intervals of coefficient estimates of generalized linear model
coefTestLinear hypothesis test on generalized linear regression model coefficients
devianceTestAnalysis of deviance
dispDisplay generalized linear regression model
fevalEvaluate generalized linear regression model prediction
plotSlicePlot of slices through fitted generalized linear regression surface
predictPredict response of generalized linear regression model
randomSimulate responses for generalized linear regression model

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects (MATLAB).

Examples

collapse all

Reduce the size of a full, fitted generalized linear regression model by discarding the sample data and some information related to the fitting process.

Load the data into the workspace. The simulated sample data contains 15,000 observations and 45 predictor variables.

load(fullfile(matlabroot,'examples','stats','largedata4reg.mat'))

Fit a generalized linear regression model to the data using the first 15 predictor variables.

mdl = fitglm(X(:,1:15),Y)
mdl = 
Generalized linear regression model:
    y ~ [Linear formula with 16 terms in 15 predictors]
    Distribution = Normal

Estimated Coefficients:
                    Estimate          SE         tStat       pValue   
                   ___________    __________    _______    ___________

    (Intercept)         3.2903    0.00010447      31497              0
    x1              -0.0006461    4.9991e-08     -12924              0
    x2             -0.00024739    8.6874e-08    -2847.7              0
    x3             -9.5161e-05    1.1138e-07    -854.38              0
    x4              0.00013143     1.551e-07     847.35              0
    x5               7.163e-05    1.9793e-07      361.9              0
    x6              4.5064e-06    2.2247e-07     20.257     4.9539e-90
    x7             -2.6258e-05    2.5462e-07    -103.13              0
    x8               6.284e-05    2.5633e-07     245.15              0
    x9             -0.00014288     2.817e-07    -507.19              0
    x10            -2.2642e-05    3.0963e-07    -73.127              0
    x11            -6.0227e-05    3.1639e-07    -190.36              0
    x12             1.1665e-05    3.3921e-07     34.388    1.6995e-249
    x13             3.8595e-05    3.5601e-07     108.41              0
    x14             0.00010021    4.0312e-07     248.57              0
    x15            -6.5674e-06    4.1692e-07    -15.752      1.844e-55


15000 observations, 14984 error degrees of freedom
Estimated Dispersion: 0.000164
F-statistic vs. constant model: 1.18e+07, p-value = 0

Compact the model. The compact model discards the original sample data and some information related to the fitting process, so it uses less memory than the full model.

compactMdl = compact(mdl)
compactMdl = 
Compact generalized linear regression model:
    y ~ [Linear formula with 16 terms in 15 predictors]
    Distribution = Normal

Estimated Coefficients:
                    Estimate          SE         tStat       pValue   
                   ___________    __________    _______    ___________

    (Intercept)         3.2903    0.00010447      31497              0
    x1              -0.0006461    4.9991e-08     -12924              0
    x2             -0.00024739    8.6874e-08    -2847.7              0
    x3             -9.5161e-05    1.1138e-07    -854.38              0
    x4              0.00013143     1.551e-07     847.35              0
    x5               7.163e-05    1.9793e-07      361.9              0
    x6              4.5064e-06    2.2247e-07     20.257     4.9539e-90
    x7             -2.6258e-05    2.5462e-07    -103.13              0
    x8               6.284e-05    2.5633e-07     245.15              0
    x9             -0.00014288     2.817e-07    -507.19              0
    x10            -2.2642e-05    3.0963e-07    -73.127              0
    x11            -6.0227e-05    3.1639e-07    -190.36              0
    x12             1.1665e-05    3.3921e-07     34.388    1.6995e-249
    x13             3.8595e-05    3.5601e-07     108.41              0
    x14             0.00010021    4.0312e-07     248.57              0
    x15            -6.5674e-06    4.1692e-07    -15.752      1.844e-55


15000 observations, 14984 error degrees of freedom
Estimated Dispersion: 0.000164
F-statistic vs. constant model: 1.18e+07, p-value = 0

Extended Capabilities

Introduced in R2016b