forked from mwgeurts/libra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lsscatter.m
executable file
·53 lines (48 loc) · 1.4 KB
/
lsscatter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function lsscatter(x,y,fitted,attrib)
%LSSCATTER makes a scatter plot with regression (LTS/LS) line
%
% Required input arguments:
% x : predictor variabele (without missing values)
% y : response variabele
% fitted : fitted values corresponding with the regression
% attrib : string identifying the used method = 'LS', 'LTS'
%
% I/O: lsscatter(x,y,fitted,attrib)
%
% This function is part of LIBRA: the Matlab Library for Robust Analysis,
% available at:
% http://wis.kuleuven.be/stat/robust.html
%
% Written by Nele Smets on : 26/11/2003
% Last Update: 29/01/2008
set(gcf,'Name', 'Scatter plot', 'NumberTitle', 'off');
[n,p]=size(x);
if p~=1
disp(['Scatter plot with regression line ',...
'is only available for bivariate data'])
else
x1 = x(1);
xn = x(n);
y1 = fitted(1);
yn = fitted(n);
dx = xn - x1;
dy = yn - y1;
slope = dy./dx;
centerx = (x1 + xn)/2;
centery = (y1 + yn)/2;
maxx = max(x);
minx = min(x);
maxy = centery + slope.*(maxx - centerx);
miny = centery - slope.*(centerx - minx);
mx = [minx; maxx];
my = [miny; maxy];
plot(x,y,'o');
hold on
xrange=0.1*(abs(maxx-abs(minx)));
yrange=0.2*(abs(maxy-abs(miny)+5));
xlim([minx-xrange maxx+xrange])
ylim([min(y)-yrange max(y)+yrange])
plot(mx,my,'-');
title(attrib)
hold off
end