FUNCTION REFERENCE
fitlm
Fit a numeric linear regression model with coefficient inference.
Fit a numeric linear regression model with coefficient inference.
Syntax
mdl = fitlm(X,y); mdl = fitlm(X,y,modelspec); mdl = fitlm(tbl,formula); mdl = fitlm(...,'Intercept',false)Adds an intercept by default and solves least squares with column-pivoted QR. A table uses its last variable as the response unless a formula names another variable. Numeric scalar table columns and real numeric predictor matrices are supported. Model specifications are 'linear', 'interactions', 'quadratic', 'purequadratic' and 'constant'. Formulas support +, -1, x1:x2, x1*x2 and x1^2 (which adds both x1 and its square). Other syntax and unknown options raise errors. NaN observations in used variables are omitted; Fitted and Residuals.Raw retain their original row positions. Coefficients has Estimate, SE, tStat and pValue columns and named rows. Other properties include Rsquared.Ordinary, Rsquared.Adjusted, RMSE, NumObservations, DFE, SSE, SST, SSR, Fitted, Residuals, CoefficientNames, Formula, LogLikelihood and ModelCriterion.AIC/BIC. Model properties are read-only and assignments share immutable storage.
Example
mdl=fitlm([0;1;2;3;4],[1;3;4;8;9]); mdl.CoefficientsDifferences from MATLAB: only numeric predictors and the documented formula subset/options are supported; no categorical expansion, weights, robust fits, term matrices or feval. Formulas are character text. Normal log likelihood uses the fitted residual mean squared error; AIC/BIC penalize the number of estimated coefficients. Rank deficient fits set dependent coefficients to zero, with NaN standard errors for them and NaN prediction intervals. Fits require positive residual degrees of freedom. Designs are bounded to 1000000 rows, 256 terms, 2000000 elements and 100000000 QR work units; large workspaces can hit the host evaluation budget earlier.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.