# Sreg

Sreg computes S estimators in linear regression

## Syntax

• out =Sreg(y,X)example
• out =Sreg(y,X,Name,Value)example
• [out , varargout]=Sreg(___)example

## Description

 out =Sreg(y, X) Sreg with all default options.

 out =Sreg(y, X, Name, Value) Sreg with optional input arguments.

 [out , varargout] =Sreg(___) Sreg with hyperbolic rho function.

## Examples

expand all

### Sreg with all default options.

Run this code to see the output shown in the help file

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
% Uncontaminated data
y=randn(n,1);
% Contaminated data
ycont=y;
ycont(1:5)=ycont(1:5)+6;
[out]=Sreg(ycont,X);
laby='Scaled S residuals';
titl='';
resindexplot(out.residuals,'title',titl,'laby',laby,'numlab','')
Total estimated time to complete S estimate:  2.67 seconds ### Sreg with optional input arguments.

Sreg with optimal rho function. Run this code to see the output shown in the help file

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
% Uncontaminated data
y=randn(n,1);
% Contaminated data
ycont=y;
ycont(1:5)=ycont(1:5)+6;
[out]=Sreg(ycont,X,'rhofunc','optimal');

### Sreg with hyperbolic rho function.

Run this code to see the output shown in the help file

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
% Uncontaminated data
y=randn(n,1);
% Contaminated data
ycont=y;
ycont(1:5)=ycont(1:5)+6;
[out]=Sreg(ycont,X,'rhofunc','hyperbolic','plots',1);
Total estimated time to complete S estimate:  1.46 seconds ## Input Arguments

### y — Response variable. Vector.

A vector with n elements that contains the response variable. y can be either a row or a column vector.

Data Types: single| double

### X — Data matrix of explanatory variables (also called 'regressors') of dimension (n x p-1). Rows of X represent observations, and columns represent variables.

Missing values (NaN's) and infinite values (Inf's) are allowed, since observations (rows) with missing or infinite values will automatically be excluded from the computations.

Data Types: single| double

### Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as  Name1,Value1,...,NameN,ValueN.

Example:  'bdp',0.4 , 'bestr',10 , 'conflev',0.99 , 'intercept',false , 'minsctol',1e-7 , 'msg',false , 'nocheck',true , 'nsamp',1000 , 'refsteps',10 , 'refstepsbestr',10 , 'reftol',1e-05 , 'reftolbestr',1e-10 , 'rhofunc','optimal' , 'rhofuncparam',5 , 'yxsave',1 , 'plots',0 

### bdp —breakdown point.scalar.

It measures the fraction of outliers the algorithm should resist. In this case any value greater than 0 but smaller or equal than 0.5 will do fine.

Note that given bdp nominal efficiency is automatically determined.

Example:  'bdp',0.4 

Data Types: double

### bestr —number of "best betas" to remember.scalar.

Scalar defining number of "best betas" to remember from the subsamples.

These will be later iterated until convergence (default=5).

Example:  'bestr',10 

Data Types: single | double

### conflev —Confidence level which is used to declare units as outliers.scalar.

Usually conflev=0.95, 0.975 0.99 (individual alpha) or 1-0.05/n, 1-0.025/n, 1-0.01/n (simultaneous alpha).

Default value is 0.975

Example:  'conflev',0.99 

Data Types: double

### intercept —Indicator for constant term.true (default) | false.

Indicator for the constant term (intercept) in the fit, specified as the comma-separated pair consisting of 'Intercept' and either true to include or false to remove the constant term from the model.

Example:  'intercept',false 

Data Types: boolean

### minsctol —tolerance for the iterative procedure for finding the minimum value of the scale.scalar.

Value of tolerance for the iterative procedure for finding the minimum value of the scale for each subset and each of the best subsets (It is used by subroutine minscale.m) The default value is 1e-7;

Example:  'minsctol',1e-7 

Data Types: single | double

### msg —Level of output to display.boolean.

It controls whether to display or not messages on the screen.

If msg==true (default) messages are displayed on the screen about estimated time to compute the estimator and the warnings about 'MATLAB:rankDeficientMatrix', 'MATLAB:singularMatrix' and 'MATLAB:nearlySingularMatrix' are set to off.

If msg is false no message is displayed on the screen

Example:  'msg',false 

Data Types: logical

### nocheck —Check input arguments.boolean.

If nocheck is equal to true no check is performed on matrix y and matrix X. Notice that y and X are left unchanged. In other words the additional column of ones for the intercept is not added.

As default nocheck=false.

Example:  'nocheck',true 

Data Types: logical

### nsamp —Number of subsamples which will be extracted to find the robust estimator.scalar.

If nsamp=0 all subsets will be extracted.

They will be (n choose p).

If the number of all possible subset is <1000 the default is to extract all subsets otherwise just 1000.

Example:  'nsamp',1000 

Data Types: single | double

### refsteps —Number of refining iterations.scalar.

Number of refining iterationsin each subsample (default = 3).

refsteps = 0 means "raw-subsampling" without iterations.

Example:  'refsteps',10 

Data Types: single | double

### refstepsbestr —number of refining iterations for each best subset.scalar.

Scalar defining number of refining iterations for each best subset (default = 50).

Example:  'refstepsbestr',10 

Data Types: single | double

### reftol —tolerance for the refining steps.scalar.

The default value is 1e-6;

Example:  'reftol',1e-05 

Data Types: single | double

### reftolbestr —Tolerance for the refining steps.scalar.

Tolerance for the refining steps for each of the best subsets The default value is 1e-8;

Example:  'reftolbestr',1e-10 

Data Types: single | double

### rhofunc —rho function.string.

String which specifies the rho function which must be used to weight the residuals.

Possible values are 'bisquare';

'optimal';

'hyperbolic';

'hampel';

'mdpd'.

'bisquare' uses Tukey's $\rho$ and $\psi$ functions.

See TBrho and TBpsi.

'optimal' uses optimal $\rho$ and $\psi$ functions.

See OPTrho and OPTpsi.

'hyperbolic' uses hyperbolic $\rho$ and $\psi$ functions.

See HYPrho and HYPpsi.

'hampel' uses Hampel $\rho$ and $\psi$ functions.

See HArho and HApsi.

'mdpd' uses Minimum Density Power Divergence $\rho$ and $\psi$ functions.

See PDrho and PDpsi.

The default is bisquare

Example:  'rhofunc','optimal' 

Data Types: double

### rhofuncparam —Additional parameters for the specified rho function.scalar | vector.

For hyperbolic rho function it is possible to set up the value of k = sup CVC (the default value of k is 4.5).

For Hampel rho function it is possible to define parameters a, b and c (the default values are a=2, b=4, c=8)

Example:  'rhofuncparam',5 

Data Types: single | double

### yxsave —save option.scalar.

if yxsave is equal to 1, the response vector y and data matrix X are saved into the output structure out. Default is 0, i.e. no saving is done.

Example:  'yxsave',1 

Data Types: double

### plots —Plot on the screen.scalar.

If plots = 1, generates a plot with the robust residuals against index number. The confidence level used to draw the confidence bands for the residuals is given by the input option conflev. If conflev is not specified a nominal 0.975 confidence interval will be used.

Example:  'plots',0 

Data Types: single | double

## Output Arguments

### out — description Structure

A structure containing the following fields

Value Description
beta

vector containing the S estimator of regression coefficients

scale

scalar containing the estimate of the scale (sigma). This is the value of the objective function

bs

p x 1 vector containing the units forming best subset associated with S estimate of regression coefficient.

residuals

n x 1 vector containing the estimates of the robust scaled residuals.

fittedvalues

n x 1 vector containing the fitted values.

outliers

this output is present only if conflev has been specified. It is a vector containing the list of the units declared as outliers using confidence level specified in input scalar conflev

conflev

confidence level which is used to declare outliers.

Remark: scalar out.conflev will be used to draw the horizontal line (confidence band) in the plot.

singsub

Number of subsets wihtout full rank. Notice that out.singsub > 0.1*(number of subsamples) produces a warning

weights

n x 1 vector containing the estimates of the weights

rhofunc

string identifying the rho function which has been used

rhofuncparam

vector which contains the additional parameters for the specified rho function which have been used. For hyperbolic rho function the value of k =sup CVC. For Hampel rho function the parameters a, b and c. If input option argument 'rhofunc' is not 'hyperbolic' or 'hampel' this field is empty.

y

response vector Y. The field is present only if option yxsave is set to 1.

X

data matrix X. The field is present only if option yxsave is set to 1.

class

'Sreg'

### varargout —Indices of the subsamples extracted for computing the estimate (the so called elemental sets). C : matrix

Maronna, R.A., Martin D. and Yohai V.J. (2006), "Robust Statistics, Theory and Methods", Wiley, New York.

## Acknowledgements

This function follows the lines of MATLAB/R code developed during the years by many authors.

For more details see http://www.econ.kuleuven.be/public/NDBAE06/programs/ and the R library robustbase http://robustbase.r-forge.r-project.org/ The core of these routines, e.g. the resampling approach, however, has been completely redesigned, with considerable increase of the computational performance.