-
Notifications
You must be signed in to change notification settings - Fork 87
/
create_diagrams.R
159 lines (145 loc) · 7.62 KB
/
create_diagrams.R
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# This script will create png and svg diagrams of different distributions. The
# diagrams will be put in four directories created in the current working
# directory: svg, svg_woth_params, png and png_with_params. In addition to this
# a couple of plots will be created in the current directory that show all the
# distributions.
source("plot_dist.R") # Make sure dist_plot.R is in the current working directory
dir.create("png", showWarnings=F)
setwd("./png")
for(dist in dists) {
plot_dist_png(dist)
}
setwd("..")
dir.create("svg", showWarnings=F)
setwd("./svg")
for(dist in dists) {
plot_dist_svg(dist)
}
setwd("..")
dir.create("svg_without_names", showWarnings=F)
setwd("./svg_without_names")
for(dist in dists) {
plot_dist_svg(dist, plot_dist_name=F)
}
setwd("..")
dir.create("png_with_params", showWarnings=F)
setwd("./png_with_params")
plot_dist_png(dists$normal, labels=expression(mu, sigma[1], sigma[2]))
plot_dist_png(dists$t, labels=expression(mu, sigma[1], sigma[2], df[1], df[2]))
plot_dist_png(dists$uniform, expression(L, H))
plot_dist_png(dists$beta, expression(list(a,b)))
plot_dist_png(dists$beta_binomial, expression(list(a,b)))
plot_dist_png(dists$bernoulli, expression(theta))
plot_dist_png(dists$gamma, expression(list(S, R)))
plot_dist_png(dists$inv_gamma, expression(list(alpha, beta)))
plot_dist_png(dists$binomial, expression(list(p, n)))
plot_dist_png(dists$negative_binomial, expression(list(p, r)))
plot_dist_png(dists$folded_t, labels=expression(mu, sigma, df))
plot_dist_png(dists$poisson, labels=expression(lambda))
plot_dist_png(dists$chi_squared, labels=expression(k))
plot_dist_png(dists$noncentral_chi_squared, labels=expression(list(k, lambda)))
plot_dist_png(dists$double_exponential, labels=expression(mu, tau[1], tau[2]))
plot_dist_png(dists$exponential, labels=expression(lambda))
plot_dist_png(dists$shifted_exponential, labels=expression(lambda))
plot_dist_png(dists$F, labels=expression(list(df[1], df[2])))
plot_dist_png(dists$generalized_gamma, labels=expression(list(r, lambda, b)))
plot_dist_png(dists$logistic, labels=expression(mu, tau[1], tau[2]))
plot_dist_png(dists$log_normal, labels=expression(mu, sigma))
plot_dist_png(dists$pareto, labels=expression(list(mu, sigma)))
plot_dist_png(dists$weibull, labels=expression(list(v, lambda)))
plot_dist_png(dists$categorical, labels=expression(list(v, lambda)))
plot_dist_png(dists$noncentral_hypergeometric, labels=expression(list(n[1], n[2], m[1], psi)))
plot_dist_png(dists$right_censored_normal, expression(mu, sigma[1], c, sigma[2]))
plot_dist_png(dists$left_censored_normal, expression(mu, sigma[1], c, sigma[2]))
plot_dist_png(dists$cauchy, labels=expression(x[0], gamma[1], gamma[2]))
plot_dist_png(dists$half_t, labels=expression(sigma, df))
plot_dist_png(dists$half_cauchy, labels=expression(gamma))
plot_dist_png(dists$half_normal, labels=expression(sigma))
setwd("..")
dir.create("svg_with_params", showWarnings=F)
setwd("./svg_with_params")
plot_dist_svg(dists$normal, labels=expression(mu, sigma[1], sigma[2]))
plot_dist_svg(dists$t, labels=expression(mu, sigma[1], sigma[2], df[1], df[2]))
plot_dist_svg(dists$uniform, expression(L, H))
plot_dist_svg(dists$beta, expression(list(a,b)))
plot_dist_svg(dists$beta_binomial, expression(list(a,b)))
plot_dist_svg(dists$bernoulli, expression(theta))
plot_dist_svg(dists$gamma, expression(list(S, R)))
plot_dist_svg(dists$inv_gamma, expression(list(alpha, beta)))
plot_dist_svg(dists$binomial, expression(list(p, n)))
plot_dist_svg(dists$negative_binomial, expression(list(p, r)))
plot_dist_svg(dists$folded_t, labels=expression(mu, sigma, df))
plot_dist_svg(dists$poisson, labels=expression(lambda))
plot_dist_svg(dists$chi_squared, labels=expression(k))
plot_dist_svg(dists$noncentral_chi_squared, labels=expression(list(k, lambda)))
plot_dist_svg(dists$double_exponential, labels=expression(mu, tau[1], tau[2]))
plot_dist_svg(dists$exponential, labels=expression(lambda))
plot_dist_svg(dists$shifted_exponential, labels=expression(lambda))
plot_dist_svg(dists$F, labels=expression(list(df[1], df[2])))
plot_dist_svg(dists$generalized_gamma, labels=expression(list(r, lambda, b)))
plot_dist_svg(dists$logistic, labels=expression(mu, tau[1], tau[2]))
plot_dist_svg(dists$log_normal, labels=expression(mu, sigma))
plot_dist_svg(dists$pareto, labels=expression(list(mu, sigma)))
plot_dist_svg(dists$weibull, labels=expression(list(v, lambda)))
plot_dist_svg(dists$categorical, labels=expression(list(v, lambda)))
plot_dist_svg(dists$noncentral_hypergeometric, labels=expression(list(n[1], n[2], m[1], psi)))
plot_dist_svg(dists$right_censored_normal, expression(mu, sigma[1], c, sigma[2]))
plot_dist_svg(dists$left_censored_normal, expression(mu, sigma[1], c, sigma[2]))
plot_dist_svg(dists$cauchy, labels=expression(x[0], gamma[1], gamma[2]))
plot_dist_svg(dists$half_t, labels=expression(sigma, df))
plot_dist_svg(dists$half_cauchy, labels=expression(gamma))
plot_dist_svg(dists$half_normal, labels=expression(sigma))
setwd("..")
plot_all_dist <- function() {
old_par <- par(mfrow=c(7,5), xpd=NA)
plot.new()
text(0.5, 0.5, "Coded\nby\nRasmus Bååth (2012)", cex=1.5)
plot_dist(dists$normal, labels=expression(mu, sigma[1], sigma[2]))
plot_dist(dists$t, labels=expression(mu, sigma[1], sigma[2], df[1], df[2]))
plot_dist(dists$uniform, expression(L, H))
plot_dist(dists$beta, expression(list(a,b)))
plot_dist(dists$beta_binomial, expression(list(a,b)))
plot_dist(dists$bernoulli, expression(theta))
plot_dist(dists$gamma, expression(list(S, R)))
plot_dist(dists$inv_gamma, expression(list(alpha, beta)))
plot_dist(dists$binomial, expression(list(p, n)))
plot_dist(dists$negative_binomial, expression(list(p, r)))
plot_dist(dists$folded_t, labels=expression(mu, sigma, df))
plot_dist(dists$poisson, labels=expression(lambda))
plot_dist(dists$chi_squared, labels=expression(k))
plot_dist(dists$noncentral_chi_squared, labels=expression(list(k, lambda)))
plot_dist(dists$double_exponential, labels=expression(mu, tau[1], tau[2]))
plot_dist(dists$exponential, labels=expression(lambda))
plot_dist(dists$shifted_exponential, labels=expression(lambda))
plot_dist(dists$F, labels=expression(list(df[1], df[2])))
plot_dist(dists$generalized_gamma, labels=expression(list(r, lambda, b)))
plot_dist(dists$logistic, labels=expression(mu, tau[1], tau[2]))
plot_dist(dists$log_normal, labels=expression(mu, sigma))
plot_dist(dists$pareto, labels=expression(list(mu, sigma)))
plot_dist(dists$weibull, labels=expression(list(v, lambda)))
plot_dist(dists$categorical, labels=expression(list(v, lambda)))
plot_dist(dists$noncentral_hypergeometric, labels=expression(list(n[1], n[2], m[1], psi)))
plot_dist(dists$right_censored_normal, expression(mu, sigma[1], c, sigma[2]))
plot_dist(dists$left_censored_normal, expression(mu, sigma[1], c, sigma[2]))
plot_dist(dists$cauchy, labels=expression(x[0], gamma[1], gamma[2]))
plot_dist(dists$half_t, labels=expression(sigma, df))
plot_dist(dists$half_cauchy, labels=expression(gamma))
plot_dist(dists$half_normal, labels=expression(sigma))
par(old_par)
}
# X11(width=9, height=8.7);plot_all_dist()
png("all_dists.png", 155 * 5, 118*7, res=96)
plot_all_dist()
dev.off()
png("all_dists_smaller.png", 136 * 5, 105* 7, res=85)
plot_all_dist()
dev.off()
svg("all_dists.svg", 1.67 * 5, 1.28 * 7)
plot_all_dist()
dev.off()
# Not embedding any fonts unfortunately. Will only render correctly if the right
# fonts are on the viewer's computer...
pdf("all_dists.pdf", 1.67 * 5, 1.28 * 7)
plot_all_dist()
dev.off()
zip("distribution_diagrams.zip", c("./all_dists.pdf", "./all_dists.png","./all_dists.svg",dir(c("svg", "png","svg_with_params", "png_with_params", "svg_without_names"),pattern="\\.(png|svg|pdf)$",recursive=F, full.names=T)))