Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.

CompactLinearModel clase

Superclases:

Compact linear regression model class

Description

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

Construction

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

Input Arguments

expandir todo

Full, fitted linear regression model, specified as a LinearModel object.

Propiedades

expandir todo

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.

Coefficient names, specified as a cell array of character vectors containing a label for each coefficient.

Coefficient values, specified as a table. Coefficients has one row for each coefficient and the following 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

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

beta = mdl.Coefficients.Estimate

Use coefTest to perform other tests on the coefficients.

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

Model information, specified as a LinearFormula object or NonLinearFormula object. If you fit a linear or generalized linear regression model, then Formula is a LinearFormula object. If you fit a nonlinear regression model, then Formula is a NonLinearFormula object.

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.

Criterion for model comparison, specified as a structure with the following 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 by using dot notation. For example, in the model mdl, the AIC value aic is:

aic = mdl.ModelCriterion.AIC

Mean squared error (residuals), specified as a numeric value. Mean square error is calculated as MSE = SSE / DFE, where MSE is the mean square error, SSE is the sum of squared errors, and DFE is the degrees of freedom.

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

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.

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

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

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 when the fit is based on those arrays. It includes variables, if any, that are not used as predictors or as the response.

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

Response variable name, specified as a character vector.

Root mean squared error (residuals), specified as a numeric value. The root mean squared error (RMSE) is equal to RMSE = sqrt(MSE), where MSE is the mean squared error.

Robust fit information, specified as a structure with the following fields:

FieldDescription
WgtFunRobust weighting function, such as 'bisquare' (see robustfit)
TuneValue specified for tuning parameter (can be [])
WeightsVector of weights used in final iteration of robust fit. This field is empty for compacted CompactLinearModel models.

This structure is empty unless fitlm constructed the model using robust regression.

R-squared value for the model, specified as a structure.

For a linear or nonlinear model, Rsquared is a structure with two fields:

  • Ordinary — Ordinary (unadjusted) R-squared

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

For a generalized linear model, Rsquared is 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

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

The Pythagorean theorem implies

SST = SSE + SSR.

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.

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

The Pythagorean theorem implies

SST = SSE + SSR.

Information about input variables contained in Variables, specified as a table with one row for each model term and the following columns.

FieldDescription
ClassCharacter vector giving variable class, such as 'double'
Range

Cell array giving variable range:

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

  • Categorical variable — Cell array of distinct variable values

InModelLogical vector, where true indicates the variable is in the model
IsCategoricalLogical vector, where true indicates a categorical variable

Names of variables used in fit, 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 that table or dataset.

  • If the fit is based on a predictor matrix and response vector, VariableNames is the values in the VarNames name-value pair of the fitting method.

  • Otherwise the variables have the default fitting names.

Methods

anovaAnalysis of variance for linear model
coefCIConfidence intervals of coefficient estimates of linear model
coefTestLinear hypothesis test on linear regression model coefficients
dispDisplay linear regression model
fevalEvaluate linear regression model prediction
plotEffectsPlot main effects of each predictor in linear regression model
plotInteractionPlot interaction effects of two predictors in linear regression model
plotSlicePlot of slices through fitted linear regression surface
predictPredict response of linear regression model
randomSimulate responses for linear regression model

Copy Semantics

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

Ejemplos

contraer todo

This example shows how to reduce the size of a full, fitted linear regression model by discarding the sample data and some information related to the fitting process.

Load the data into the workspace.

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

The simulated sample data contains 15,000 observations and 45 predictor variables.

Fit a simple linear regression model to the data.

mdl = fitlm(X,Y)
mdl = 
Linear regression model:
    y ~ [Linear formula with 46 terms in 45 predictors]

Estimated Coefficients:
                    Estimate          SE           tStat         pValue   
                   ___________    __________    ___________    ___________

    (Intercept)         3.2903    1.2333e-05     2.6679e+05              0
    x1              -0.0006461    5.9019e-09    -1.0947e+05              0
    x2             -0.00024739    1.0256e-08         -24121              0
    x3             -9.5161e-05    1.3149e-08        -7236.9              0
    x4              0.00013143    1.8311e-08         7177.3              0
    x5               7.163e-05    2.3367e-08         3065.4              0
    x6              4.5064e-06    2.6264e-08         171.58              0
    x7             -2.6258e-05     3.006e-08        -873.51              0
    x8               6.284e-05    3.0262e-08         2076.5              0
    x9             -0.00014288    3.3258e-08        -4296.1              0
    x10            -2.2642e-05    3.6555e-08        -619.41              0
    x11            -6.0227e-05    3.7353e-08        -1612.4              0
    x12             1.1665e-05    4.0048e-08         291.27              0
    x13             3.8595e-05     4.203e-08         918.26              0
    x14             0.00010021    4.7592e-08         2105.5              0
    x15            -6.5674e-06    4.9221e-08        -133.43              0
    x16             8.5598e-06    5.0296e-08         170.19              0
    x17            -3.9107e-05       5.3e-08        -737.87              0
    x18            -6.5841e-06    5.5355e-08        -118.94              0
    x19            -1.7053e-05    5.7431e-08        -296.94              0
    x20            -3.8911e-06    6.2724e-08        -62.036              0
    x21            -9.7219e-06    6.3515e-08        -153.06              0
    x22            -1.8749e-06    6.5388e-08        -28.673    4.6032e-176
    x23            -4.7514e-06    6.6636e-08        -71.303              0
    x24            -1.7756e-05    6.8495e-08        -259.23              0
    x25            -9.6673e-06    7.0054e-08           -138              0
    x26             7.6237e-06    7.2442e-08         105.24              0
    x27            -8.4338e-07    7.7519e-08         -10.88     1.8249e-27
    x28             7.0502e-06    8.1889e-08         86.094              0
    x29            -1.4703e-05    8.7126e-08        -168.75              0
    x30             2.7008e-05    9.0084e-08          299.8              0
    x31             6.3685e-07    9.1253e-08          6.979     3.0977e-12
    x32            -1.9916e-05    1.0034e-07        -198.48              0
    x33             1.7369e-05     1.019e-07         170.45              0
    x34             -9.931e-06    1.0706e-07        -92.764              0
    x35            -1.5195e-05    1.0858e-07        -139.94              0
    x36            -1.0118e-05    1.1122e-07        -90.976              0
    x37             2.4595e-06    1.1254e-07         21.856    2.9315e-104
    x38            -2.2928e-06    1.1493e-07         -19.95     2.0535e-87
    x39             1.1397e-05    1.1855e-07         96.136              0
    x40             4.0239e-06    1.2327e-07         32.643      7.75e-226
    x41            -8.6667e-06    1.2535e-07        -69.142              0
    x42            -8.2932e-06    1.3095e-07        -63.334              0
    x43             2.7309e-06    1.3452e-07         20.301     2.0697e-90
    x44            -6.9235e-06    1.3725e-07        -50.444              0
    x45             1.1165e-06    1.4021e-07         7.9633     1.7956e-15


Number of observations: 15000, Error degrees of freedom: 14954
Root Mean Squared Error: 0.00151
R-squared: 1,  Adjusted R-Squared 1
F-statistic vs. constant model: 2.82e+08, p-value = 0

Compact the model.

compactMdl = compact(mdl)
compactMdl = 
Compact linear regression model:
    y ~ [Linear formula with 46 terms in 45 predictors]

Estimated Coefficients:
                    Estimate          SE           tStat         pValue   
                   ___________    __________    ___________    ___________

    (Intercept)         3.2903    1.2333e-05     2.6679e+05              0
    x1              -0.0006461    5.9019e-09    -1.0947e+05              0
    x2             -0.00024739    1.0256e-08         -24121              0
    x3             -9.5161e-05    1.3149e-08        -7236.9              0
    x4              0.00013143    1.8311e-08         7177.3              0
    x5               7.163e-05    2.3367e-08         3065.4              0
    x6              4.5064e-06    2.6264e-08         171.58              0
    x7             -2.6258e-05     3.006e-08        -873.51              0
    x8               6.284e-05    3.0262e-08         2076.5              0
    x9             -0.00014288    3.3258e-08        -4296.1              0
    x10            -2.2642e-05    3.6555e-08        -619.41              0
    x11            -6.0227e-05    3.7353e-08        -1612.4              0
    x12             1.1665e-05    4.0048e-08         291.27              0
    x13             3.8595e-05     4.203e-08         918.26              0
    x14             0.00010021    4.7592e-08         2105.5              0
    x15            -6.5674e-06    4.9221e-08        -133.43              0
    x16             8.5598e-06    5.0296e-08         170.19              0
    x17            -3.9107e-05       5.3e-08        -737.87              0
    x18            -6.5841e-06    5.5355e-08        -118.94              0
    x19            -1.7053e-05    5.7431e-08        -296.94              0
    x20            -3.8911e-06    6.2724e-08        -62.036              0
    x21            -9.7219e-06    6.3515e-08        -153.06              0
    x22            -1.8749e-06    6.5388e-08        -28.673    4.6032e-176
    x23            -4.7514e-06    6.6636e-08        -71.303              0
    x24            -1.7756e-05    6.8495e-08        -259.23              0
    x25            -9.6673e-06    7.0054e-08           -138              0
    x26             7.6237e-06    7.2442e-08         105.24              0
    x27            -8.4338e-07    7.7519e-08         -10.88     1.8249e-27
    x28             7.0502e-06    8.1889e-08         86.094              0
    x29            -1.4703e-05    8.7126e-08        -168.75              0
    x30             2.7008e-05    9.0084e-08          299.8              0
    x31             6.3685e-07    9.1253e-08          6.979     3.0977e-12
    x32            -1.9916e-05    1.0034e-07        -198.48              0
    x33             1.7369e-05     1.019e-07         170.45              0
    x34             -9.931e-06    1.0706e-07        -92.764              0
    x35            -1.5195e-05    1.0858e-07        -139.94              0
    x36            -1.0118e-05    1.1122e-07        -90.976              0
    x37             2.4595e-06    1.1254e-07         21.856    2.9315e-104
    x38            -2.2928e-06    1.1493e-07         -19.95     2.0535e-87
    x39             1.1397e-05    1.1855e-07         96.136              0
    x40             4.0239e-06    1.2327e-07         32.643      7.75e-226
    x41            -8.6667e-06    1.2535e-07        -69.142              0
    x42            -8.2932e-06    1.3095e-07        -63.334              0
    x43             2.7309e-06    1.3452e-07         20.301     2.0697e-90
    x44            -6.9235e-06    1.3725e-07        -50.444              0
    x45             1.1165e-06    1.4021e-07         7.9633     1.7956e-15


Number of observations: 15000, Error degrees of freedom: 14954
Root Mean Squared Error: 0.00151
R-squared: 1,  Adjusted R-Squared 1
F-statistic vs. constant model: 2.82e+08, p-value = 0

The compact model discards the original sample data and some information related to the fitting process.

Compare the size of the full model mdl and the compact model compactMdl.

vars = whos('compactMdl','mdl');
[vars(1).bytes,vars(2).bytes]
ans = 1×2

       83506    11410618

The compacted model consumes less memory than the full model.

Capacidades ampliadas

Introducido en R2016a