regress — Fit a multiple linear regression model by ordinary least squares.
regress(y,X) estimates coefficients for the linear model y = X*b. Include a column of ones in X when an intercept is required.
Syntax
b = regress(y, X)
b = regress(y, X, alpha)
[b, bint] = regress(y, X)
[b, bint] = regress(y, X, alpha)
[b, bint, r] = regress(y, X)
[b, bint, r] = regress(y, X, alpha)All supported regress forms
b = regress(y, X)
b = regress(y, X, alpha)
[b, bint] = regress(y, X)
[b, bint] = regress(y, X, alpha)
[b, bint, r] = regress(y, X)
[b, bint, r] = regress(y, X, alpha)
[b, bint, r, rint] = regress(y, X)
[b, bint, r, rint] = regress(y, X, alpha)
[b, bint, r, rint, stats] = regress(y, X)
[b, bint, r, rint, stats] = regress(y, X, alpha)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
y | NumericArray | Yes | — | Response vector. |
X | NumericArray | Yes | — | Design matrix with observations in rows and model terms in columns. |
alpha | NumericScalar | No | 0.05 | Significance level for coefficient and residual intervals. |
Returns
| Name | Type | Description |
|---|---|---|
b | NumericArray | Least-squares coefficient estimates. |
bint | NumericArray | Confidence intervals for coefficient estimates. |
r | NumericArray | Regression residuals for complete observations. |
rint | NumericArray | Confidence intervals for residuals. |
stats | NumericArray | Row vector [R2 F p errorVariance]. |
Returned values from regress depend on how many outputs the caller requests.
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:regress:InvalidArgument | Inputs, dimensions, alpha, or requested output counts are malformed. | regress: invalid argument |
RunMat:regress:Numerical | The regression design cannot be solved numerically. | regress: numerical failure |
RunMat:regress:Internal | RunMat cannot allocate or construct regression outputs. | regress: internal error |
How regress works
ymust be a numeric vector with one element per row ofX;Xmust be a 2-D numeric design matrix.- Rows containing
NaNinyor any predictor are omitted before fitting. alphais optional and defaults to0.05; it controls coefficient and residual confidence intervals.- Requested outputs follow MATLAB's
[b,bint,r,rint,stats]form, including partial forms such as[b,bint]and[b,bint,r].statsis[R2 F p errorVariance]. - Rank-deficient designs use rank-revealing column pivoting, zero dependent-column coefficients, and return zero coefficient intervals for dependent columns.
- Residual intervals use deleted-residual variance estimates for studentized residual diagnostics; interval outputs become
NaNwhere degrees of freedom are insufficient.
Example
Fit a line with an explicit intercept column
X = [ones(4,1) (0:3)']; y = [1;3;5;7]; [b,bint,r,rint,stats] = regress(y,X)Expected output:
b is approximately [1; 2] and stats(1) is 1.Using regress with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how regress changes the result.
Run a small regress example, explain the result, then change one input and compare the output.
FAQ
Does regress add an intercept automatically?⌄
No. Match MATLAB usage by adding a column of ones to X when the model should include an intercept.
Related Stats functions
Ml
bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · predict · ridge · squareform · test · training · tsne
Summary
binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv
Random
binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd
Hist
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how regress is executed, line by line, in Rust.
- View the source for regress in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.