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
CoefficientCovariance
— Covariance matrix of coefficient estimates
numeric matrix
This property is readonly.
Covariance matrix of coefficient estimates, specified as a pbyp 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
CoefficientNames
— Coefficient names
cell array of character vectors
This property is readonly.
Coefficient names, specified as a cell array of character vectors, each containing the name of the corresponding term.
Data Types: cell
Coefficients
— Coefficient values
table
This property is readonly.
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
— tstatistic for a test that the coefficient is zeropValue
— pvalue for the tstatistic
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
NumCoefficients
— Number of model coefficients
positive integer
This property is readonly.
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
NumEstimatedCoefficients
— Number of estimated coefficients
positive integer
This property is readonly.
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
DFE
— Degrees of freedom for error
positive integer
This property is readonly.
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
LogLikelihood
— Loglikelihood
numeric value
This property is readonly.
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
ModelCriterion
— Criterion for model comparison
structure
This property is readonly.
Criterion for model comparison, specified 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 likelihoodbased 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 bestfitting model. The bestfitting 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
MSE
— Mean squared error
numeric value
This property is readonly.
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
RMSE
— Root mean squared error
numeric value
This property is readonly.
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
Rsquared
— Rsquared value for model
structure
This property is readonly.
Rsquared value for the model, specified as a structure with two fields:
Ordinary
— Ordinary (unadjusted) RsquaredAdjusted
— Rsquared adjusted for the number of coefficients
The Rsquared value is the proportion of the total sum of squares explained by the
model. The ordinary Rsquared 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 (RSquared).
To obtain either of these values as a scalar, index into the property using dot
notation. For example, obtain the adjusted Rsquared value in the model
mdl
:
r2 = mdl.Rsquared.Adjusted
Data Types: struct
SSE
— Sum of squared errors
numeric value
This property is readonly.
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
SSR
— Regression sum of squares
numeric value
This property is readonly.
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
SST
— Total sum of squares
numeric value
This property is readonly.
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
Fitting Method
Robust
— Robust fit information
structure
This property is readonly.
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
Formula
— Model information
LinearFormula
object
This property is readonly.
Model information, specified as a LinearFormula
object.
Display the formula of the fitted model mdl
using dot
notation:
mdl.Formula
NumObservations
— Number of observations
positive integer
This property is readonly.
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'
namevalue pair
argument) or rows with missing values.
Data Types: double
NumPredictors
— Number of predictor variables
positive integer
This property is readonly.
Number of predictor variables used to fit the model, specified as a positive integer.
Data Types: double
NumVariables
— Number of variables
positive integer
This property is readonly.
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
PredictorNames
— Names of predictors used to fit model
cell array of character vectors
This property is readonly.
Names of predictors used to fit the model, specified as a cell array of character vectors.
Data Types: cell
ResponseName
— Response variable name
character vector
This property is readonly.
Response variable name, specified as a character vector.
Data Types: char
VariableInfo
— Information about variables
table
This property is readonly.
Information about variables contained in Variables
, specified as a
table with one row for each variable and the columns described in this table.
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 that are not used to fit
the model as predictors or as the response.
Data Types: table
VariableNames
— Names of variables
cell array of character vectors
This property is readonly.
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'
namevalue 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
Object Functions
Predict Responses
Evaluate Linear Model
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 
Visualize Linear Model
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 Properties of Linear Model
gather  Gather properties of Statistics and Machine Learning Toolbox object from GPU 
Examples
Compact Linear Regression Model
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
81537 11408528
The compact model consumes less memory than the full model.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
For more information, see Introduction to Code Generation.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
Usage notes and limitations:
The following object functions fully support GPU arrays:
The following object functions support model objects fitted with GPU array input arguments:
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
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)