CompactLinearModel
Compact linear regression model
Description
CompactLinearModel
is a compact version of a full linear
regression model object LinearModel
. Because a compact model does
not store the input data used to fit the model or information related to the fitting
process, a CompactLinearModel
object consumes less memory than a
LinearModel
object. You can still use a compact model to predict
responses using new input data, but some LinearModel
object functions
do not work with a compact model.
Creation
Create a CompactLinearModel
model from a full, trained LinearModel
model by using compact
.
Properties
Coefficient Estimates
This property is read-only.
Covariance matrix of coefficient estimates, represented as a
p-by-p matrix of numeric values. p
is the number of coefficients in the fitted model, as given by
NumCoefficients
.
For details, see Coefficient Standard Errors and Confidence Intervals.
Data Types: single
| double
This property is read-only.
Coefficient names, represented 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 valueSE
— Standard error of the estimatetStat
— t-statistic for a two-sided test with the null hypothesis that the coefficient is zeropValue
— p-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.
Number of model coefficients, represented 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
Summary Statistics
This property is read-only.
Degrees of freedom for the error (residuals), equal to the number of observations minus the number of estimated coefficients, represented as a positive integer.
Data Types: double
This property is read-only.
Loglikelihood of response values, specified as a numeric value, based
on the assumption that each response value follows a normal
distribution. The mean of the normal distribution is the fitted
(predicted) response value, and the variance is the
MSE
.
Data Types: single
| double
This property is read-only.
Criterion for model comparison, represented as a structure with these fields:
AIC
— Akaike information criterion.AIC = –2*logL + 2*m
, wherelogL
is the loglikelihood andm
is the number of estimated parameters.AICc
— Akaike information criterion corrected for the sample size.AICc = AIC + (2*m*(m + 1))/(n – m – 1)
, wheren
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.
Mean squared error (residuals), specified as a numeric value.
MSE = SSE / DFE,
where MSE is the mean squared error, SSE is the sum of squared errors, and DFE is the degrees of freedom.
Data Types: single
| double
This property is read-only.
Root mean squared error (residuals), specified as a numeric value.
RMSE = sqrt(MSE),
where RMSE is the root mean squared error and MSE is the mean squared error.
Data Types: single
| double
This property is read-only.
R-squared value for the model, specified as a structure with two fields:
Ordinary
— Ordinary (unadjusted) R-squaredAdjusted
— R-squared adjusted for the number of coefficients
The R-squared value is the proportion of the total sum of squares explained by the
model. The ordinary R-squared value relates to the SSR
and
SST
properties:
Rsquared = SSR/SST
,
where SST
is the total sum of squares, and
SSR
is the regression sum of squares.
For details, see Coefficient of Determination (R-Squared).
To obtain either of these values as a scalar, index into the property using dot
notation. For example, obtain the adjusted R-squared value in the model
mdl
:
r2 = mdl.Rsquared.Adjusted
Data Types: struct
This property is read-only.
Sum of squared errors (residuals), specified as a numeric value. If the model was
trained with observation weights, the sum of squares in the SSE
calculation is the weighted sum of squares.
For a linear model with an intercept, 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.
For more information on the calculation of SST
for a robust
linear model, see SST
.
Data Types: single
| double
This property is read-only.
Regression sum of squares, specified as a numeric value.
SSR
is equal to the sum of the squared deviations between the fitted
values and the mean of the response. If the model was trained with observation weights, the
sum of squares in the SSR
calculation is the weighted sum of
squares.
For a linear model with an intercept, 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.
For more information on the calculation of SST
for a robust linear
model, see SST
.
Data Types: single
| double
This property is read-only.
Total sum of squares, specified as a numeric value. SST
is equal
to the sum of squared deviations of the response vector y
from the
mean(y)
. If the model was trained with observation weights, the
sum of squares in the SST
calculation is the weighted sum of
squares.
For a linear model with an intercept, 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.
For a robust linear model, SST
is not calculated as the sum of
squared deviations of the response vector y
from the
mean(y)
. It is calculated as SST = SSE +
SSR
.
Data Types: single
| double
Fitting Method
This property is read-only.
Robust fit information, specified as a structure with the fields described in this table.
Field | Description |
---|---|
WgtFun | Robust weighting function, such as 'bisquare' (see
'RobustOpts' ) |
Tune | Tuning constant. This field is empty ([] ) if
WgtFun is 'ols' or if
WgtFun is a function handle for a custom weight
function with the default tuning constant 1. |
Weights | Vector of weights used in the final iteration of robust fit. This
field is empty for a CompactLinearModel
object. |
This structure is empty unless you fit the model using robust regression.
Data Types: struct
Input Data
This property is read-only after object creation.
Model information, represented as a LinearFormula
object.
Display the formula of the fitted model mdl
using dot
notation:
mdl.Formula
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 after object creation.
Number of predictor variables used to fit the model, represented as a positive integer.
Data Types: double
This property is read-only after object creation.
Number of variables in the input data, represented as a positive integer.
NumVariables
is the number of variables in the original table, or
the total number of columns in the predictor matrix and response vector.
NumVariables
also includes any variables not used to fit the model
as predictors or as the response.
Data Types: double
This property is read-only after object creation.
Names of predictors used to fit the model, represented as a cell array of character vectors.
Data Types: cell
This property is read-only after object creation.
Response variable name, represented as a character vector.
Data Types: char
This property is read-only after object creation.
Information about the variables contained in Variables
,
represented as a table with one row for each variable and the columns described
below.
Column | Description |
---|---|
Class | Variable class, specified as a cell array of character vectors, such
as 'double' and
'categorical' |
Range | Variable range, specified as a cell array of vectors
|
InModel | Indicator of which variables are in the fitted model, specified as a
logical vector. The value is true if the model
includes the variable. |
IsCategorical | Indicator of categorical variables, specified as a logical vector.
The value is true if the variable is
categorical. |
VariableInfo
also includes any variables not used to fit the model
as predictors or as the response.
Data Types: table
This property is read-only after object creation.
Names of the variables, returned as a cell array of character vectors.
If the fit is based on a table, this property contains the names of the variables in the table.
If the fit is based on a predictor matrix and response vector, this property contains the values specified by the
VarNames
name-value argument of the fitting method. The default value ofVarNames
is{'x1','x2',...,'xn','y'}
.
VariableNames
also includes any variables not used to fit the model
as predictors or as the response.
Data Types: cell
Object Functions
anova | Analysis of variance for linear regression model |
coefCI | Confidence intervals of coefficient estimates of linear regression model |
coefTest | Linear hypothesis test on linear regression model coefficients |
partialDependence | Compute partial dependence |
plotEffects | Plot main effects of predictors in linear regression model |
plotInteraction | Plot interaction effects of two predictors in linear regression model |
plotPartialDependence | Create partial dependence plot (PDP) and individual conditional expectation (ICE) plots |
plotSlice | Plot of slices through fitted linear regression surface |
gather | Gather properties of Statistics and Machine Learning Toolbox object from GPU |
Examples
Fit a linear regression model to data and 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 largedata4reg
data set, which contains 15,000 observations and 45 predictor variables.
load largedata4reg
Fit a linear regression model to the data.
mdl = fitlm(X,Y);
Compact the model.
compactMdl = compact(mdl);
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
85228 11412705
The compact model consumes less memory than the full model.
Extended Capabilities
Usage notes and limitations:
For more information, see Introduction to Code Generation.
Usage notes and limitations:
The object functions of a
CompactLinearModel
model fully support GPU arrays.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2016a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)