# levfwdplot

levfwdplot plots the trajectories of leverage along the search

## Syntax

• plotopt=levfwdplot(out)example
• plotopt=levfwdplot(out,Name,Value)example

## Description

 plotopt =levfwdplot(out) Produce monitoring leverage plot with all the default options.

 plotopt =levfwdplot(out, Name, Value) Example of the use of some options inside structure standard.

## Examples

expand all

### Produce monitoring leverage plot with all the default options.

Generate input structure for the levfwdplot

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
% Uncontaminated data
y=randn(n,1);
% Contaminated data
y(1:5)=y(1:5)+6;
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
levfwdplot(out);

### Example of the use of some options inside structure standard.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
% 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;
levfwdplot(out,'standard',standard);

## Related Examples

expand all

### Example of the use of some options inside structure fground.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
% 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
levfwdplot(out,'fground',fground);

### Same as above, but the colormap used for leverage trajectories is based on residual values.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
fground = struct;
fground.LineWidth=3;
levfwdplot(out,'fground',fground,'xground','res');

### Example of the use of some options inside structure bground n=200; p=3; randn('state', 123456); X=randn(n,p); y=randn(n,1); [out]=LXS(y,X,'nsamp',1000); [out]=FSReda(y,X,out.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
bground = struct;
% Specify a threshold to define the "background" trajectories
bground.bthresh=0.1;
% Trajectories whose leverage is always between -btresh and +bthresh
% are shown as specified in bground.bstyle
bground.bstyle='hide';
levfwdplot(out,'bground',bground);

### Example of the use of option datatooltip.

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.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
datatooltip = struct;
% In this example the style of the datatooltip is 'datatip'. Click on a
% trajectory when the levfwdplot is displayed.
datatooltip.DisplayStyle = 'datatip';
levfwdplot(out,'datatooltip',datatooltip);
% Now we use the default style, which is 'window'.
datatooltip.DisplayStyle = 'window';
levfwdplot(out,'datatooltip',datatooltip);

### Interactive example 1. n=200; p=3; randn('state', 123456); X=randn(n,p); y=randn(n,1); [out]=LXS(y,X,'nsamp',1000); [out]=FSReda(y,X,out.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
%   Example of the use of option databrush
%   (brushing is done only once using a rectangular selection tool)
levfwdplot(out,'databrush',1)
%   An equivalent statement is
databrush=struct;
databrush.selectionmode='Rect';
levfwdplot(out,'databrush',databrush);

### Interactive example 2. n=200; p=3; randn('state', 123456); X=randn(n,p); y=randn(n,1); [out]=LXS(y,X,'nsamp',1000); [out]=FSReda(y,X,out.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
% Example of the use of brush using selection with circular tool
databrush=struct;
databrush.selectionmode='Brush';
levfwdplot(out,'databrush',databrush);

### Interactive example 3. n=200; p=3; randn('state', 123456); X=randn(n,p); y=randn(n,1); [out]=LXS(y,X,'nsamp',1000); [out]=FSReda(y,X,out.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
%   Example of the use of brush using lasso selection tool and fleur
%   pointer
databrush=struct;
databrush.selectionmode='lasso';
databrush.Pointer='fleur';
levfwdplot(out,'databrush',databrush);

### Interactive example 4. n=200; p=3; randn('state', 123456); X=randn(n,p); y=randn(n,1); [out]=LXS(y,X,'nsamp',1000); [out]=FSReda(y,X,out.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
%   Example of the use of rectangular brush with superimposed 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';
levfwdplot(out,'databrush',databrush);

### Interactive example 5. n=200; p=3; randn('state', 123456); X=randn(n,p); y=randn(n,1); [out]=LXS(y,X,'nsamp',1000); [out]=FSReda(y,X,out.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
%   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';
levfwdplot(out,'databrush',databrush);

### Interactive example 6. n=200; p=3; randn('state', 123456); X=randn(n,p); y=randn(n,1); [out]=LXS(y,X,'nsamp',1000); [out]=FSReda(y,X,out.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
%   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';
levfwdplot(out,'databrush',databrush);

### Interactive example 7. The same as before, but also fit one ols line to each selected group n=200; p=3; randn('state', 123456); X=randn(n,p); y=randn(n,1); [out]=LXS(y,X,'nsamp',1000); [out]=FSReda(y,X,out.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
databrush=struct;
databrush.selectionmode='Rect';
databrush.Label='on';
databrush.RemoveLabels='on';
databrush.persist='on';
databrush.bivarfit='0';
levfwdplot(out,'databrush',databrush);

### Interactive example 8. The same but now fit a single ols line to all data.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
databrush=struct;
databrush.selectionmode='Rect';
databrush.Label='on';
databrush.RemoveLabels='off';
databrush.persist='on';
databrush.bivarfit='1';
levfwdplot(out,'databrush',databrush);

### Interactive example 9. The same but now fit a first ols line to all data and a second line on the group of observations which remain unselected.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
databrush=struct;
databrush.selectionmode='Rect';
databrush.Label='on';
databrush.RemoveLabels='off';
databrush.persist='on';
databrush.bivarfit='2';
levfwdplot(out,'databrush',databrush);

### Interactive example 10. The same but now fit a single ols line to the group with index 4.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
databrush=struct;
databrush.selectionmode='Rect';
databrush.Label='on';
databrush.RemoveLabels='off';
databrush.persist='on';
databrush.bivarfit='i4';
levfwdplot(out,'databrush',databrush);

### Interactive example 11. The same but now add the line mean(y)+Ci*Xi.

n=200;
p=3;
randn('state', 123456);
X=randn(n,p);
y=randn(n,1);
[out]=LXS(y,X,'nsamp',1000);
[out]=FSReda(y,X,out.bs);
databrush=struct;
databrush.selectionmode='Rect';
databrush.Label='on';
databrush.RemoveLabels='off';
databrush.persist='on';
databrush.multivarfit='1';
levfwdplot(out,'databrush',databrush);

### Interactive example 12. 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';
levfwdplot(out,'databrush',databrush);

### Interactive example 13. Fidelity cards data 1.

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';
levfwdplot(out,'databrush',databrush);

### Fidelity cards data 2.

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);
plotopt=levfwdplot(out,'msg',2)
% In order to reuse the options which have been stored inside plotopt
% use the following sintax
% levfwdplot(out,plotopt{:});

## Input Arguments

### out — Structure containing monitoring of leverage. Structure.

Structure containing the following fields.

Value Description
LEV

matrix containing the leverage monitored in each step of the forward search. Every row is associated with a unit.

This matrix can be created using function FSReda (compulsory argument)

RES

matrix containing the residuals monitored in each step of the forward search. Every row is associated with a unit.

This matrix can be created using function FSReda (compulsory argument)

Un

matrix containing the order of entry of each unit (necessary only if datatooltip or databrush are not empty)

y

a vector containing the response (necessary only if option databrush is not empty)

X

a matrix containing the explanatory variables (necessary only if option databrush is not empty)

Bols

(n-init+1) x (p+1) matrix containing the monitoring of estimated beta coefficients in each step of the forward search (necessary only if option databrush is not empty and suboption lineadd is not empty)

Data Types: struct

### 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:  'standard.LineWidth','1' , 'fground.LineWidth','1' , 'bground.bstyle','faint' , 'xground','res' , '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:'Leverage').

SizeAxesLab

Scalar specifying the fontsize of the labels of the axes. Default value is 12.

subsize

numeric vector containing the subset size with length equal to the number of columns of the leverage matrix. The default value of subsize is (n-nsteps+1):n

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.

Remark. The default values of structure standard are:

standard.SizeAxesNum=10 standard.SizeAxesLab=12 standard.xlim='' (Automatic scale) standard.ylim='' (Automatic scale) standard.titl='' (empty title) standard.labx='Subset size m' standard.laby='Leverage' standard.LineWidth=1 standard.Color={'b'} standard.LineStyle={'-'}

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.

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 after step [n/2 + 1] have at least once a leverage bigger than fthresh. Alternatively (if option 'xground' is set to be 'res' by the user) the trajectories are highlighted if throughtout the search the units had at leat once a residual (in absolute value) greater than fthresh.

The default value of fthresh is 2p/n for leverage values or 2.5 for residual values.

- If length(fthresh)=2 the highlighted trajectories are those of units that throughtout the search had a leverage value at leat once bigger than fthresh(2) or smaller than fthresh(1).

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

fground.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.

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

fground.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} fground.LineStyle : cell containing the line type of the highlighted trajectories.

fground.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).

Remark. The default values of structure fground are:

fground.fthresh=2.5 fground.flabstep=[m0 n] fground.LineWidth=1 fground.LineStyle={'-'} Remark. if fground='' no unit is highlighted and no label is inserted into the plot.

Example:  'fground.LineWidth','1' 

Data Types: struct

### bground —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.

Structure bground 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 leverage smaller (in absolute value) than thresh.

- If length(bthresh)=2 the irrelevant units are those which always had a leverage greater than bthresh(1) and smaller than bthresh(2).

The default is:

bthresh=2p/n if n>100 and bthresh=-inf if n<=100.

Like for fthresh, if the user option xground is 'res', then the background trajectories are set in relation to the residual values and the default threshold becomes bthresh=2.5 if n>100 and bthresh=-inf if n<=100.

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

### xground —trajectories to highlight in connection with resfwdplot.character 'lev' (default) | 'res'.

xground = 'lev' (default).

The levfwdplot trajectories are put in foreground or in background depending on the leverage values.

xground = 'res'.

The levfwdplot trajectories are put in foreground or in background depending on the residual values.

See options bground.bthresh and fground.fthresh.

Example:  'xground','res' 

Data Types: char

### tag —Personalized 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 (default)| structure.

The default is datatooltip=1 If datatooltip is not empty the user can use the mouse in order to have information about the unit selected, the step in which the unit enters the search and the associated label. If datatooltip is a structure, it is possible to control the aspect of the data cursor (see function datacursormode for more details or the examples below). The default options of the structure are DisplayStyle='Window' and SnapToDataVertex='on'.

Example:  'datatooltip','' 

Data Types: char

### 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.

Please note that the window style of the other figures is set equal to that which contains the monitoring leverage plot. In other words, if the monitoring leverage 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 variables of the regression dataset.cell array of strings.

If it is empty (default) the sequence X1, ..., Xp will be created automatically.

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

Data Types: cell of strings

### namey —label of the response.character.

Character containing the label of the response.

Example:  'namey','response' 

Data Types: char

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

plotopt=levfwdplot(out,'msg',1) enables to save inside cell plotopt the options which have been used to draw the three types of trajectories (standard, foreground and background) plotopt=resfwdplot(out,'msg',2) saves inside cell plotopt the options which have been used and prints them on the screen.

Example:  'msg',1 

Data Types: single or double

## Output Arguments

### plotopt —options which have been used to create the plot. Cell array of strings

Store all options which have been used to generate the plot inside cell plotopt.

## References

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