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

NameTypeRequiredDefaultDescription
yNumericArrayYesResponse vector.
XNumericArrayYesDesign matrix with observations in rows and model terms in columns.
alphaNumericScalarNo0.05Significance level for coefficient and residual intervals.

Returns

NameTypeDescription
bNumericArrayLeast-squares coefficient estimates.
bintNumericArrayConfidence intervals for coefficient estimates.
rNumericArrayRegression residuals for complete observations.
rintNumericArrayConfidence intervals for residuals.
statsNumericArrayRow vector [R2 F p errorVariance].

Returned values from regress depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:regress:InvalidArgumentInputs, dimensions, alpha, or requested output counts are malformed.regress: invalid argument
RunMat:regress:NumericalThe regression design cannot be solved numerically.regress: numerical failure
RunMat:regress:InternalRunMat cannot allocate or construct regression outputs.regress: internal error

How regress works

  • y must be a numeric vector with one element per row of X; X must be a 2-D numeric design matrix.
  • Rows containing NaN in y or any predictor are omitted before fitting.
  • alpha is optional and defaults to 0.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]. stats is [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 NaN where 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.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how regress is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.