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
y- Type
NumericArray- Required
- Yes
- Description
- Response vector.
X- Type
NumericArray- Required
- Yes
- Description
- Design matrix with observations in rows and model terms in columns.
alpha- Type
NumericScalar- Required
- No
- Default
0.05- Description
- Significance level for coefficient and residual intervals.
Returns
b- Type
NumericArray- Description
- Least-squares coefficient estimates.
bint- Type
NumericArray- Description
- Confidence intervals for coefficient estimates.
r- Type
NumericArray- Description
- Regression residuals for complete observations.
rint- Type
NumericArray- Description
- Confidence intervals for residuals.
stats- Type
NumericArray- Description
- Row vector [R2 F p errorVariance].
Returned values from regress depend on how many outputs the caller requests.
Errors
RunMat:regress:InvalidArgument- When
- Inputs, dimensions, alpha, or requested output counts are malformed.
- Message
regress: invalid argument
RunMat:regress:Numerical- When
- The regression design cannot be solved numerically.
- Message
regress: numerical failure
RunMat:regress:Internal- When
- RunMat cannot allocate or construct regression outputs.
- Message
regress: internal error
Inputs and computation
y is a numeric response vector with one value per row of the two-dimensional design matrix X. The documented floating computation admits single and double. Typed-integer y, X, and alpha are RunMat extensions: each integer must cross the checked exact binary64 boundary, and MATLAB compatibility mode rejects the extension before provider access. Logical y and X are also admitted by the current host conversion.
Rows with NaN in y or any predictor are omitted. An Inf in y or X is an error. The optional significance level alpha defaults to 0.05 and must be a scalar in [0,1). A rank-deficient design uses rank-revealing column selection; dependent coefficients and their intervals are zero.
Outputs and execution
The requested outputs are [b,bint,r,rint,stats], including partial forms. Coefficient intervals are in bint. Residuals and their studentized, deleted-variance intervals are in r and rint. The 1-by-4 stats row contains [R2 F p errorVariance]. Interval values can be NaN when the available degrees of freedom are insufficient.
Admitted GPU inputs are gathered to host. The SVD-backed coefficient fit and interval diagnostics run on CPU; there is no provider-native regression kernel, GPU fusion, or implicit intercept term.
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. Add 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 · nlparci · optimizableVariable · pdist · pdist2 · perfcurve · predict · ridge · squareform · test · training · tsne
Summary
anova1 · binocdf · binscatter · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · ksdensity · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pca · pdf · prctile · qqplot · quantile · refline · rmse · scatterhist · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest · ttest2 · wblinv
Random
binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · gpurng · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd
Hist
Source you can read
Every RunMat function's source is public. 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 a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.