resfwdplot plots the trajectories of the monitored scaled (squared) residuals

generate input structure for the resfwdplot In this example FS estimator is used

n=100; y=randn(n,1); X=randn(n,4); [out]=LXS(y,X,'nsamp',1000); [out]=FSReda(y,X,out.bs); % Produce resfwdplot resfwdplot(out);

Initialize structure standard Specify the steps in which labels have to be put

standard=struct; standard.LineStyle={'-';'-.';':'}; % Specify the line width standard.LineWidth=0.5; resfwdplot(out,'standard',standard)

Initialize structure fground

fground = struct; % Specify which trajectories have to be highlighted fground.funit=[2 5 20 23 35 45]; % Specify the steps in which labels have to be put n=length(y); fground.flabstep=[n/2 n*0.75 n+0.5];; % Specify the line width of the highlighted trajectories fground.LineWidth=3; % Produce a monitoring residuals plot in which labels are put for units % [2 5 20 23 35 45] in steps [n/2 n*0.75 n+0.5] of the search resfwdplot(out,'fground',fground)

bground = struct; % Specify a threshold to define the "background" trajectories bground.bthresh=2; % Trajectories whose residual is always between -btresh and +bthresh % are shown as specified in bground.bstyle bground.bstyle='hide'; resfwdplot(out,'bground',bground)

Gives the user the possibility of clicking on the different points and have information about the unit selected, the step of entry into the subset and the associated label.

datatooltip = struct; % In this example the style of the datatooltip is 'datatip'. Click on a % trajectory when the resfwdplot is displayed. % datatooltip.DisplayStyle = 'datatip'; resfwdplot(out,'datatooltip',datatooltip); % % Now we use the default style, which is 'window'. datatooltip.DisplayStyle = 'window'; resfwdplot(out,'datatooltip',datatooltip); % Here we specify the RGB color used to highlight the selected trajectory. % Note that we can obtain the RGB vector with our MATLAB class FSColors. % datatooltip = struct; datatooltip.LineColor = FSColors.yellowish.RGB; resfwdplot(out,'datatooltip',datatooltip); % now LineColor is not a valid RGB vector, but red (default) will be used datatooltip.LineColor = [123 41 12 32 1]; resfwdplot(out,'datatooltip',datatooltip);

% The user can highlight the trajectories of the units that are in % the subset at a given step with a mouse click in proximity % of that step. A right click will terminate the exercise. % To activate this modality, we set the field SubsetLinesColor, % which specifies the color used to highlight the trajectories. datatooltip = struct; datatooltip.SubsetLinesColor = FSColors.purplish.RGB; resfwdplot(out,'datatooltip',datatooltip); % Here we show that the modality is also activated when % SubsetLinesColor is not a valid RGB vector. % In this case the default highlight color (blue) is used. datatooltip = struct; datatooltip.SubsetLinesColor = 999; resfwdplot(out,'datatooltip',datatooltip);

% (brushing is done only once using a rectangular selection tool) resfwdplot(out,'databrush',1) % An equivalent statement is databrush=struct; databrush.selectionmode='Rect'; resfwdplot(out,'databrush',databrush);

% Use a cyan colour. resfwdplot(out,'databrush',{'selectionmode' 'Rect' 'FlagColor' 'c'})

databrush=struct; databrush.selectionmode='Brush'; resfwdplot(out,'databrush',databrush)

databrush=struct; databrush.selectionmode='lasso'; databrush.Pointer='fleur'; resfwdplot(out,'databrush',databrush)

% We havesuperimposed labels % for the brushed units and persistent labels in the plot which has % been brushed. databrush=struct; databrush.selectionmode='Rect'; databrush.Label='on'; databrush.RemoveLabels='off'; resfwdplot(out,'databrush',databrush)

% Example of the use of persistent non cumulative brush. Every time a % brushing action is performed previous highlightments are removed databrush=struct; databrush.selectionmode='Rect'; databrush.Label='on'; databrush.RemoveLabels='off'; databrush.persist='off'; resfwdplot(out,'databrush',databrush)

% Example of the use of persistent cumulative brush. Every time a % brushing action is performed current highlightments are added to % previous highlightments databrush=struct; databrush.selectionmode='Rect'; databrush.Label='on'; databrush.RemoveLabels='on'; databrush.persist='on'; resfwdplot(out,'databrush',databrush)

% The same as before, but also fit one ols line to each selected group databrush=struct; databrush.selectionmode='Rect'; databrush.Label='on'; databrush.RemoveLabels='on'; databrush.persist='on'; databrush.bivarfit='0'; resfwdplot(out,'databrush',databrush)

% The same but now fit a single ols line to all data. databrush=struct; databrush.selectionmode='Rect'; databrush.Label='on'; databrush.RemoveLabels='off'; databrush.persist='on'; databrush.bivarfit='1'; resfwdplot(out,'databrush',databrush)

% The same but now fit a first ols line to all data and a second line % on the group of observations which remain unselected. databrush=struct; databrush.selectionmode='Rect'; databrush.Label='on'; databrush.RemoveLabels='off'; databrush.persist='on'; databrush.bivarfit='2'; resfwdplot(out,'databrush',databrush)

% The same but now fit a single ols line to the group with index 4. databrush=struct; databrush.selectionmode='Rect'; databrush.Label='on'; databrush.RemoveLabels='off'; databrush.persist='on'; databrush.bivarfit='i4'; resfwdplot(out,'databrush',databrush)

% The same but now add the line mean(y)+Ci*Xi. databrush=struct; databrush.selectionmode='Rect'; databrush.Label='on'; databrush.RemoveLabels='off'; databrush.persist='on'; databrush.multivarfit='1'; resfwdplot(out,'databrush',databrush)

% Example of use of option databrush suboptions multivarfit 2, persist on load('multiple_regression.txt'); y=multiple_regression(:,4); X=multiple_regression(:,1:3); [out]=LXS(y,X,'nsamp',10000); [out]=FSReda(y,X,out.bs); out1=out; out1.RES=out.RES.^2; mdrplot(out,'ylimy',[1 5]); databrush=struct; databrush.selectionmode='Rect'; databrush.Label='on'; databrush.RemoveLabels='off'; databrush.persist='on'; databrush.multivarfit='2'; resfwdplot(out,'databrush',databrush)

% Fidelity cards data XX=load('loyalty.txt'); namey='Sales' y=XX(:,end); y=y.^0.4; nameX={'Number of visits', 'Age', 'Number of persons in the family'}; X=XX(:,1:end-1); [out]=LXS(y,X,'nsamp',10000); [out]=FSReda(y,X,out.bs); mdrplot(out,'ylimy',[1.6 4.5],'xlimx',[420 510],'lwd',2,'FontSize',16,'SizeAxesNum',16,'lwdenv',2); mdrplot(out,'ylimy',[1.6 4.5],'envm',489,'xlimx',[420 510],'lwd',2,'FontSize',16,'SizeAxesNum',16,'lwdenv',2); databrush=struct; databrush.selectionmode='Rect'; databrush.Label='on'; databrush.RemoveLabels='on'; databrush.persist='on'; databrush.multivarfit='2'; resfwdplot(out,'databrush',databrush)

Fidelity cards data

XX=load('loyalty.txt'); namey='Sales' y=XX(:,end); y=y.^0.4; X=XX(:,1:end-1); [out]=LXS(y,X,'nsamp',10000); [out]=FSReda(y,X,out.bs); % msg is 1 therefore used options are also shown on the screen. plotopt=resfwdplot(out,'msg',1) % In order to reuse the options which have been stored inside plotopt % use the following sintax % resfwdplot(out,plotopt{:})

XX=load('loyalty.txt'); namey='Sales' y=XX(:,end); y=y.^0.4; X=XX(:,1:end-1); [out]=LXS(y,X,'nsamp',10000); [out]=FSReda(y,X,out.bs); standard=struct; % xlabels start from 400 standard.xvalues=400:1:(size(out.RES,2)+400-1); resfwdplot(out,'standard',standard)

n=100; y=randn(n,1); X=randn(n,4); [out]=Sregeda(y,X); % Produce resfwdplot resfwdplot(out);

`out`

— Structure containing monitoring of scaled residuals.
Structure.Structure containing the following fields.

Value | Description |
---|---|

`RES` |
matrix containing the residuals monitored in each step of the forward search or any other robust procedure. Every row is associated with a residual (unit). This matrix can be created using function FSReda, Sregeda, MMregeda. |

`Un` |
matrix containing the order of entry in the subset of each unit (required only when datatooltip is true or databrush is not empty). |

`y` |
a vector containing the response (required only when option databrush is not empty). |

`X` |
a matrix containing the explanatory variables (required only when option databrush is not empty). |

`Bols` |
(n-init+1) x (p+1) matrix containing the estimated beta coefficients monitored in each step of the robust procedure (required only when option databrush is not empty and suboption multivarfit is not empty). |

**
Data Types: **`single|double`

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
```

.

```
'standard.LineWidth','1'
```

,```
'fground.LineWidth','1'
```

,```
'bground.bstyle','faint'
```

,```
'tag','myplot'
```

,```
'datatooltip',''
```

,```
'label',{'Smith','Johnson','Robert','Stallone'}
```

,```
'databrush',1
```

,```
'nameX',{'var1', var2, 'var3'}
```

,```
'namey','response'
```

,```
'msg',1
```

`standard`

—appearance of the plot
in terms of xlim, ylim, axes labels and their font size
style, color of the lines, etc.structure.Structure standard contains the following fields

Value | Description |
---|---|

`SizeAxesNum` |
scalar specifying the fontsize of the axes numbers. Default value is 10. |

`xlim` |
two elements vector with minimum and maximum of the x axis. Default value is '' (automatic scale). |

`ylim` |
two elements vector with minimum and maximum of the y axis. Default value is '' (automatic scale). |

`titl` |
a label for the title (default: ''). |

`labx` |
a label for the x-axis (default: 'Subset size m'). |

`laby` |
a label for the y-axis (default:'Scaled residuals' or 'Scaled squared residuals'). standard. SizeAxesLab = Scalar specifying the fontsize of the labels of the axes. Default value is 12. |

`xvalues` |
vector. x axis values. Numeric vector of length(size(out.RES,2)) controlling the x axis coordinates. The default value of xvalues is size(out.RES,1)-size(out.RES,2)+1:size(out.RES,1) |

`LineWidth` |
scalar specifying line width for the trajectories. |

`Color` |
cell array of strings containing the colors to be used for the highlighted units. If length(Color)=1 the same color will be used for all units. If length(Color)=2 half of the trajectories will appear with Color{1} and the other half with Color{2}. And so on with 3 cell elements, etc. |

`LineStyle` |
cell containing the line types. The default values of structure standard are: standard.SizeAxesNum=10 |

`SizeAxesLab` |
12 standard.xlim='' (Automatic scale) standard.ylim='' (Automatic scale) standard.titl='' (empty title) standard.labx='Subset size m' standard.laby='Scaled residuals' standard.LineWidth=1 standard.Color={'b'} standard.LineStyle={'-'} standard.xvalues=size(out.RES,1)-size(out.RES,2)+1:size(out.RES,1) |

**Example: **```
'standard.LineWidth','1'
```

**Data Types: **`struct`

`fground`

—trajectories in foregroud.structure.Structure which controls which trajectories are highlighted and how they are plotted to be distinguishable from the others.

It is possible to control the label, the width, the color, the line type and the marker of the highlighted units. The structure fground contains the following fields:

Value | Description |
---|---|

`fthresh` |
(alternative to funit) numeric vector of length 1 or 2 which specifies the highlighted trajectories. If length(fthresh)=1 the highlighted trajectories are those of units that throughtout the search had at leat once a residual greater (in absolute value) than thresh. The default value of fthresh is 2.5. If length(fthresh)=2 the highlighted trajectories are those of units that throughtout the search had a residual at leat once bigger than fthresh(2) or smaller than fthresh(1). |

`funit` |
(alternative to fthresh) vector containing the list of the units to be highlighted. If funit is supplied, fthresh is ignored. |

`flabstep` |
numeric vector which specifies the steps of the search where to put labels for the highlighted trajectories (units). The default is to put the labels at the initial and final steps of the search. flabstep='' means no label. |

`LineWidth` |
scalar specifying line width for the highlighted trajectories (units). Default is 1. |

`Color` |
cell array of strings containing the colors to be used for the highlighted trajectories (units). If length(scolor)==1 the same color will be used for all highlighted units Remark: if for example length(scolor)=2 and there are 6 highlighted units, 3 highlighted trajectories appear with selunitcolor{1} and 3 highlighted trajectories with selunitcolor{2} |

`LineStyle` |
cell containing the line type of the highlighted trajectories. |

`fmark` |
scalar controlling whether to plot highlighted trajectories as markers. if 1 each line is plotted using a different marker else no marker is used (default). |

`FontSize` |
scalar controlling font size of the labels of the trajectories in foreground. The default values of structure fground are: fground.fthresh=2.5 fground.flabstep=[m0 n] fground.LineWidth=1 fground.LineStyle={'-'} fground.FontSize=12 |

Remark: if fground='' no unit is highlighted and no label is inserted into the plot.

**Example: **```
'fground.LineWidth','1'
```

**Data Types: **`struct`

`bground`

—characterictics of the trajectories in background.structure.Structure which specifies the trajectories in background, i.e. the trajectories corresponding to "unimmportant" units in the central part of the data. The structure also specifies the style used in the plot to give them less emphasis, so that to not distract the eye of the analyst from the trajectories of the relevant units.

The structure contains the following fields:

Value | Description |
---|---|

`bthresh` |
numeric vector of length 1 or 2 which specifies how to define the unimmportant trajectories. Unimmportant trajectories will be plotted using a colormap, in greysh or will be hidden. - If length(thresh)=1 the irrelevant units are those which always had a residual smaller (in absolute value) than thresh. - If length(bthresh)=2 the irrelevant units are those which always had a residual greater than bthresh(1) and smaller than bthresh(2). The default is: bthresh=2.5 if n>100 and bthresh=-inf if n<=100 i.e. to treat all trajectories as important if n<=100 and, if n>100, to reduce emphasis only to trajectories having in all steps of the search a value of scaled residual smaller than 2.5. |

`bstyle` |
specifies how to plot the unimportant trajectories as defined in option bthresh. 'faint': unimportant trajectories are plotted using a colormap. 'hide': unimportant trajectories are hidden. 'greysh': unimportant trajectories are displayed in a faint grey. When n>100 the default option is 'faint'. When n<=100 and bthresh = -Inf option bstyle is ignored. Remark: bground='' is equivalent to |

`thresh` |
-Inf that is all trajectories are considered relevant. |

**Example: **```
'bground.bstyle','faint'
```

**Data Types: **`struct`

`tag`

—Personalized plot tag.string.String which identifies the handle of the plot which is about to be created. The default is to use tag 'pl_resfwd'. Note that if the program finds a plot which has a tag equal to the one specified by the user, then the output of the new plot overwrites the existing one in the same window else a new window is created.

**Example: **```
'tag','myplot'
```

**Data Types: **`char`

`datatooltip`

—interactive clicking.empty value, scalar | structure.It is inactive if it is an empty value. The default is datatooltip = 1, i.e. the user can select with the mouse an individual residual trajectory in order to have information about the corresponding unit. The information displayed depends on the estimator in use.

For example for class FSReda the information concerns the label and the step of the search in which the unit enters the subset. If datatooltip is a structure it may contain the following fields

Value | Description |
---|---|

`DisplayStyle` |
determines how the data cursor displays. Possible values are 'datatip' and 'window' (default). 'datatip' displays data cursor information in a small yellow text box attached to a black square marker at a data point you interactively select. 'window' displays data cursor information for the data point you interactively select in a floating window within the figure. |

`SnapToDataVertex` |
specifies whether the data cursor snaps to the nearest data value or is located at the actual pointer position. Possible values are 'on' (default) and 'off'. |

`LineColor` |
controls the color of the trajectory selected with the mouse. It can be an RGB triplet of values between 0 and 1, or character vector indicating a color name. Note that a RGB vector can be conveniently chosen with our MATLAB class FSColor, see documentation. |

`SubsetLinesColor` |
enables to control the color of the trajectories of the units that are in the subset at a given step of the search (if resfwdplot is applied to an object of class FSReda) or have a weight greater than 0.9 (if resfwdplot is applied to an object of class LXSeda, Sregeda and MMregeda). This can be done (repeatedly) with a left mouse click in proximity of the step of interest. A right mouse click will terminate the selection by marking with a up-arrow the step corresponding to the highlighted lines. The highlighted lines by default are in red, but a different color can be specified as RGB triplet or character of color name. Note that a RGB vector can be conveniently chosen with our MATLAB class FSColor, see documentation. By default SubsetLinesColor ='', i.e. the modality is not active. Any initialization for SubsetLinesColor which cannot be interpreted as RGB vector will be converted to blue, i.e. SubsetLinesColor will be forced to be [0 0 1]. If SubsetLinesColor is not empty previous option LineColor is overlooked. |

**Example: **```
'datatooltip',''
```

**Data Types: **`empty value, scalar or struct`

`label`

—row labels.cell of strings.Cell containing the labels of the units (optional argument used when datatooltip=1. If this field is not present labels row1, ..., rown will be automatically created and included in the pop up datatooltip window)

**Example: **```
'label',{'Smith','Johnson','Robert','Stallone'}
```

**Data Types: **`cell`

`databrush`

—interactive mouse brushing.empty value, scalar | structure.If databrush is an empty value (default), no brushing is done.

The activation of this option (databrush is a scalar or a cell) enables the user to select a set of trajectories in the current plot and to see them highlighted in the y|X plot, i.e. a matrix of scatter plots of y against each column of X, grouped according to the selection(s) done by brushing. If the plot y|X does not exist it is automatically created.

In addition, brushed units are automatically highlighted in the minimum deletion residual plot if it is already open.

The extension to the following plots will be available in future versions of the toolbox:

- monitoring leverage plot;

- maximum studentized residual;

- s^2 and R^2;

- Cook distance and modified Cook distance;

- deletion t statistics.

Note that the window style of the other figures is set equal to that which contains the monitoring residual plot. In other words, if the monitoring residual plot is docked all the other figures will be docked too DATABRUSH IS A SCALAR If databrush is a scalar the default selection tool is a rectangular brush and it is possible to brush only once (that is persist='').

DATABRUSH IS A STRUCTURE.

If databrush is a structure, it is possible to use all optional arguments of function selectdataFS and the following optional argument:

- persist. Persist is an empty value or a scalar containing the strings 'on' or 'off'.

The default value of persist is '', that is brushing is allowed only once.

If persist is 'on' or 'off' brushing can be done as many time as the user requires.

If persist='on' then the unit(s) currently brushed are added to those previously brushed. it is possible, every time a new brushing is done, to use a different color for the brushed units.

If persist='off' every time a new brush is performed units previously brushed are removed.

- bivarfit. This option adds one or more least square lines based on SIMPLE REGRESSION to the plots of y|X, depending on the selected groups.

bivarfit = '' is the default: no line is fitted.

bivarfit = '1' fits a single ols line to all points of each bivariate plot in the scatter matrix y|X.

bivarfit = '2' fits two ols lines: one to all points and another to the last selected group. This is useful when there are only two groups, of which one refers to a set of potential outliers.

bivarfit = '0' fits one ols line for each selected group. This is useful for the purpose of fitting mixtures of regression lines.

bivarfit = 'i1' or 'i2' or 'i3' etc.

fits a ols line to a specific group, the one with index 'i' equal to 1, 2, 3 etc.

- multivarfit: This option adds one or more least square lines, based on MULTIVARIATE REGRESSION of y on X, to the plots of y|Xi.

multivarfit = '' is the default: no line is fitted.

multivarfit = '1' fits a single ols line to all points of each bivariate plot in the scatter matrix y|X.

The line added to the scatter plot y|Xi is avconst +Ci*Xi, where Ci is the coefficient of Xi in the multivariate regression and avconst is the effect of all the other explanatory variables different from Xi evaluated at their centroid (that is $\overline{y}'C$)).

multivarfit = '2' exactly equal to multivarfit ='1' but this time we add the line based on the group of unselected observations.

- labeladd. If this option is '1', we label the units of the last selected group with the unit row index in matrices X and y. The default value is labeladd='', i.e. no label is added.

**Example: **```
'databrush',1
```

**Data Types: **`single | double | struct`

`nameX`

—labels of the explanatory variables.cell.Cell array of strings of length p containing the labels of the variables of the regression dataset. If it is empty the sequence X1, ..., Xp will be created automatically

**Example: **```
'nameX',{'var1', var2, 'var3'}
```

**Data Types: **`cell of strings`

`namey`

—response label.character.Character containing the label of the response

**Example: **```
'namey','response'
```

**Data Types: **`character`

`msg`

—display used options.scalar.Scalar which controls whether to display as output the options inside structures standard, fground and bground which have been used to draw the plot.

plotopt=resfwdplot(out,'msg',1) prints on the screen the options which have been used to draw the three types of trajectories (standard, foreground and background).

**Example: **```
'msg',1
```

**Data Types: **`single or double`

`plotopt`

—options which have been used to create the plot.
Cell array
of stringsStore all options which have been used to generate the plot inside cell plotopt.

Atkinson, A.C. and Riani, M. (2000), "Robust Diagnostic Regression Analysis", Springer Verlag, New York.