/
linearModelExamples.m
105 lines (91 loc) · 2.07 KB
/
linearModelExamples.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
function linearModelExamples
% % Linear model call format
%
%
% % Build data
% rng(555),
% n=10;
% R=rand(n,5);
% R(:,3)=R(:,3)+1;
%
% X=repmat(1:5,size(R,1),1);
% lemmings=R(:);
% group=X(:);
%
% clf
%
% % We can call notBoxPlot with just X and Y
% subplot(2,2,1)
% notBoxPlot(lemmings,group,'jitter',0.75)
% grid on, box on
% ylim([-0.5,2.2])
% title('two vectors')
%
% % We can create a table and get the same plot plus the variable names on the axes
% subplot(2,2,2)
% T = table(lemmings,group);
% notBoxPlot(T,'jitter',0.75)
% grid on, box on
% ylim([-0.5,2.2])
% title('table')
%
% % We can fit a linear model do the data and plot this
% subplot(2,2,3)
% group = categorical(group);
% T = table(lemmings,group);
% M = fitlm(T,'lemmings ~ group');
% notBoxPlot(M,'jitter',0.75)
% grid on, box on
% ylim([-0.5,2.2])
% title('model')
%
% % Increase variance of one group
% subplot(2,2,4)
% lemmings(end-n+1:end) = lemmings(end-n+1:end)*1.75;
% T = table(lemmings,group);
% M = fitlm(T,'lemmings ~ group');
% notBoxPlot(M,'jitter',0.75)
% grid on, box on
% ylim([-0.5,2.2])
% title('increased variance in group 5')
help(['NBP.',mfilename])
% Build data
rng(555),
n=10;
R=rand(n,5);
R(:,3)=R(:,3)+1;
X=repmat(1:5,size(R,1),1);
lemmings=R(:);
group=X(:);
clf
% We can call notBoxPlot with just X and Y
subplot(2,2,1)
notBoxPlot(lemmings,group,'jitter',0.75)
grid on, box on
ylim([-0.5,2.2])
title('two vectors')
% We can create a table and get the same plot plus the variable names on the axes
subplot(2,2,2)
T = table(lemmings,group);
notBoxPlot(T,'jitter',0.75)
grid on, box on
ylim([-0.5,2.2])
title('table')
% We can fit a linear model do the data and plot this
subplot(2,2,3)
group = categorical(group);
T = table(lemmings,group);
M = fitlm(T,'lemmings ~ group');
notBoxPlot(M,'jitter',0.75)
grid on, box on
ylim([-0.5,2.2])
title('model')
% Increase variance of one group
subplot(2,2,4)
lemmings(end-n+1:end) = lemmings(end-n+1:end)*1.75;
T = table(lemmings,group);
M = fitlm(T,'lemmings ~ group');
notBoxPlot(M,'jitter',0.75)
grid on, box on
ylim([-0.5,2.2])
title('increased variance in group 5')