-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbar_add_error_bars.gss
More file actions
81 lines (65 loc) · 1.77 KB
/
bar_add_error_bars.gss
File metadata and controls
81 lines (65 loc) · 1.77 KB
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
new;
/*
** Load 'Age' and 'Limit' variables
** into a 2 column matrix
*/
file = getGAUSSHome() $+ "/examples/credit.dat";
data = loadd(file, "Age + Limit");
// Define age and limit data
age = data[., 1];
limit = data[., 2];
num_ranges = 4;
age_ranges = { 20 40,
40 60,
60 80,
80 100 };
/*
** Pre-allocate vector to hold means
** and standard deviation of the samples
*/
mu = zeros(num_ranges, 1);
s = zeros(num_ranges, 1);
for i(1, num_ranges, 1);
// Get the index for different age level
level_idx = indexcat(age, age_ranges[i, .]');
// mean of limit for different age level
mu[i] = meanc(limit[level_idx]);
// Calculate the standard deviation of the sample
s[i] = stdc(limit[level_idx]);
endfor;
/*
** Note: We will use HTML interpreter
** for text labels, < is '<' in html
*/
labels = "20 < age ≤ 40" $|
"40 < age ≤ 60" $|
"60 < age ≤ 80" $|
"80 < age ≤ 100";
/*
** Declare 'ctl' to be a plotControl structure
** and fill with default settings for bar plots
*/
struct plotControl ctl;
ctl = plotGetDefaults("bar");
// Set bar fill to be: solid, 100% opaque and steel blue
plotSetFill(&ctl, 1, 1, "steel blue");
// Set title and axes labels
plotSetTitle(&ctl, "Credit Limits and Age", "arial", 20);
plotSetYLabel(&ctl, "Credit Limits", "arial", 18);
plotSetXLabel(&ctl, "Age", "arial", 18);
// Draw bar plot
plotBar(ctl, labels, mu);
/*
** File 'ctl' plotControl structure with
** default settings for 'xy' plots
*/
ctl = plotGetDefaults("xy");
// Set line color
plotSetLineColor(&ctl, "black");
/*
** 'x' location of error bars
** 1 is first bar, 2 is second bar, etc
*/
x = seqa(1, 1, num_ranges);
// Draw error bars on bar plot
plotAddErrorBar(ctl, x, mu, s);