anova1 — One-way analysis of variance for grouped observations.
Compare two or more group means with the one-way F-test, returning an ANOVA table and group statistics.
Syntax
[p,tbl,stats] = anova1(y,group,display)Inputs
y- Type
NumericArray- Required
- Yes
- Default
- —
- Description
- Real single or double vector or matrix of observations.
group- Type
Any- Required
- No
- Default
[]- Description
- Numeric/logical, text, cellstr or categorical grouping labels; required for vectors.
display- Type
Any- Required
- No
- Default
'on'- Description
- 'on' prints the table and renders a boxplot; 'off' suppresses presentation.
Returns
p- Type
NumericArray- Description
- Upper-tail F-test probability.
tbl- Type
Any- Description
- 4-by-6 ANOVA cell array with Source, SS, df, MS, F, and Prob>F columns.
stats- Type
Any- Description
- Scalar structure with gnames, n, source, means, df and s.
Errors
RunMat:anova1:InvalidArgument- When
- Sample/group class, geometry, observed-group count, device residency intent, display or output count is unsupported.
- Message
anova1: invalid argument
Observation grouping
anova1(y) treats the columns of a real single or double matrix as groups. anova1(y,group) accepts one grouping label per matrix column; repeated labels combine those columns. For vector observations group is required and supplies one label per observation. [] selects default column groups for a matrix.
Grouping accepts a real single/double numeric vector, logical vector, character rows, string array, cell array of text scalars, or categorical observations. Labels retain typed numeric identity; they are not compared by rounded display strings. Groups are returned in first-observed order. Empty/missing labels and NaN labels omit corresponding observations; NaN y values are omitted independently. All-empty groups are removed. At least two observed groups and positive within-group degrees of freedom are required.
Native integer, logical, complex, object, and distributed sample arrays are unsupported. Native integer grouping arrays are also unsupported. Numeric computation and outputs use host binary64, including single-input observations; no single-output-class parity is claimed.
Outputs and display
[p,tbl,stats] returns the upper-tail F-test probability; a 4-by-6 cell table with Source, SS, df, MS, F, and Prob>F columns; and a scalar statistics structure. The table rows are header, Groups, Error, and Total. Unused cells are empty character rows. stats contains gnames (column cellstr), n and means (row vectors), source ('anova1'), error degrees of freedom df, and pooled within-group standard deviation s.
The default display is 'on': RunMat prints the ANOVA table in the console and renders the groups through its boxplot implementation with notches. This is not MATLAB's separate interactive table window. The plot-core feature is required for 'on'; a build without plotting rejects that form explicitly. anova1(y,group,'off') suppresses both presentation actions and returns only the requested outputs. Unknown display values and excess inputs or outputs raise errors.
A zero within-group variance with distinct group means gives an infinite F statistic and p=0. If every observation is identical the F ratio and p are undefined (NaN). Infinite observations can also make statistics undefined. This function supplies group summaries; it does not implement multcompare or claim the complete statistics-toolbox surface.
Execution and resource limits
The host implementation reuses RunMat's regularized-beta probability kernel for F survival. Only authenticated automatic residency may use the context-owned host gather fallback, for observations and grouping values alike. Explicit gpuArray or unproven device intent is rejected before any argument transfer; call gather explicitly to request host analysis. There is no provider-native ANOVA kernel, numerical fusion producer, distributed implementation, or separately enabled explicit-host-fallback extension; original gather and cancellation failures propagate.
Observation scans and moments cooperate with the owning execution context. Finite host-memory requests fail before gather or group/result allocation: those workspaces have no complete allocation certificate. Display='off' has no console, host-callback, or UI effects; unknown/default display retains the conservative presentation effects.
Examples
Compare matrix columns
y = [1 4;2 5;3 6]; [p,tbl,s] = anova1(y,{'A','B'},'off');Group vector observations
y = [1;2;3;4;5]; g = {'A';'A';'B';'B';'B'}; [p,tbl,s] = anova1(y,g,'off');Using anova1 with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how anova1 changes the result.
Run a small anova1 example, explain the result, then change one input and compare the output.
Related Stats functions
Summary
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
Ml
bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · nlparci · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · squareform · test · training · tsne
Random
binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · gpurng · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd
Hist
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.