xval_SVR

May 7, 2026 · View on GitHub

Object methods index · Toolbox folders

End-to-end SVR pipeline for continuous outcomes, with the same scaffolding as xval_SVM: stratified holdouts that respect repeated-measures groupings, optional nested hyperparameter optimisation, repeated random splits, and bootstrap inference on feature weights. Use this when the target is continuous (e.g. pain rating, age, behavioural score) and you want a defensible, fully cross-validated linear regression.

Code map

xval_SVR code map

Editable PowerPoint version

Usage

S = xval_SVR(X, Y, id, varargin)

Inputs

ArgumentTypeDescription
X[N × p] numericPredictor matrix (observations × features).
Y[N × 1] numericContinuous outcome to predict.
id[N × 1] numericGrouping codes (e.g. subject id). All observations sharing an id are kept together in train or test. Use 1:N or [] for no grouping.
'doplot', logicalflagCreate plots. Default true. Use 'noplot' to suppress.
'doverbose', logicalflagVerbose output. Default true. Use 'noverbose' to suppress.
'dooptimize', logicalflagNested hyperparameter optimisation via Bayesian search. Default true. Use 'nooptimize' to skip.
'doprepeats', integerparamNumber of repeated cross-validations with different partitions. Default 10. Use 'norepeats' to skip.
'dobootstrap' / 'nobootstrap' / 'nboot', integerflag / paramBootstrap feature weights for inference. Default on. 'nboot', N sets number of bootstrap samples.
'modeloptions', cellparamCell array of name/value pairs forwarded to fitrsvm. Default {'KernelFunction', 'linear'}.

Outputs

S is a structure with (among others):

FieldDescription
Y, yfitTrue and cross-validated predicted continuous outcomes.
idGrouping variable.
w, bFinal-model weights and bias.
SVRModelThe full-data RegressionSVM object (Beta, Bias, KernelParameters.Scale).
nfolds, cvpartition, trIdx, teIdxCV bookkeeping.
dist_from_hyperplane_xvalCross-validated continuous score.
class_probability_xvalPlatt-scaled probability (legacy field; see Notes).
crossval_accuracyCross-validated prediction r² (no hyperparam opt).
prediction_outcome_rSimple prediction-outcome correlation (not for use as quantitative objective).
regression_d_singleintervalCohen's d effect size derived from r.
crossval_accuracy_opt_hyperparamsAccuracy with optimised hyperparameters (when dooptimize).
Y_within_id, scores_within_id, scorediffWithin-person reorganisation for paired tests.
crossval_accuracy_within, classification_d_withinWithin-person metrics.
boot_w_mean, boot_w_ste, wZ, wP, wP_fdr_thr, boot_w_fdrsig, w_thresh_fdrBootstrap inference on feature weights, including FDR-corrected significance.
accfunFunction handle for accuracy computation.

Notes

  • Linear fitrsvm only by default; the source has commented hooks for nonlinear kernels.
  • Hyperparameter optimisation uses Bayesian search with a 5-fold inner CV (not grouped by id) and the smooth best-estimate criterion. Needs reasonably large samples to be useful.
  • If you optimise hyperparameters AND repeat cross-validation, you get nested cross-validation — accurate but potentially slow.
  • The class_probability_xval field is a holdover from the SVM scaffolding; for regression, the most useful continuous score is S.yfit (or S.dist_from_hyperplane_xval, which is the same up to a constant in the regression case).
  • prediction_outcome_r is provided for reporting but should not be used as the optimisation objective — it is overly forgiving when predictions have the right rank but wrong scale. Use crossval_accuracy (prediction r²) for that. See Scheinost et al. 2019 for the rationale.

Example

% One observation per person, true linear signal + heavy noise
n = 50;                                       % participants
k = 120;                                      % features
Y = randn(n, 1);                              % True continuous outcome
X = Y * randn(1, k) + ones(n, 1) * randn(1, k) + 5 * randn(n, k);
id = (1:n)';                                  % One observation per id

% Quick cross-validated performance
S = xval_SVR(X, Y, id, 'nooptimize', 'norepeats', 'nobootstrap');

% Two observations per participant
id2 = [(1:n/2)'; (1:n/2)'];
S2 = xval_SVR(X, Y, id2, 'nooptimize', 'norepeats', 'nobootstrap');

Other examples

% Quick bootstrap test (small N — not for final inference)
S = xval_SVR(X, Y, id, 'nooptimize', 'norepeats', 'nboot', 100);

% Repeated cross-val only, 5 repeats
S = xval_SVR(X, Y, id, 'nooptimize', 'dorepeats', 5, 'nobootstrap');

% Nested hyperparameter optimisation only
S = xval_SVR(X, Y, id, 'norepeats', 'nobootstrap');

% Full pipeline: optimise, repeat, bootstrap
S = xval_SVR(X, Y, id);

% Silent run for batch use
S = xval_SVR(X, Y, id, 'nooptimize', 'norepeats', 'nobootstrap', ...
    'noverbose', 'noplot');

See also