File: prob2.dem

package info (click to toggle)
gnuplot 3.5beta6.347-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 5,032 kB
  • ctags: 4,235
  • sloc: ansic: 42,086; makefile: 561; asm: 539; sh: 386; objc: 379; csh: 297; pascal: 194; perl: 138; lisp: 88
file content (357 lines) | stat: -rw-r--r-- 10,396 bytes parent folder | download | duplicates (2)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#
# $Id: prob2.dem,v 1.3 1994/03/30 01:28:45 alex Exp $
#
# Demo Statistical Approximations version 1.1
#
# Permission granted to distribute freely for non-commercial purposes only
#
# Copyright (c) 1991, Jos van der Woude, jvdwoude@hut.nl

pause  0 ""
pause  0 ""
pause  0 ""
pause  0 ""
pause  0 ""
pause  0 ""
pause  0 "                        Statistical Approximations, version 1.1"
pause  0 ""
pause  0 "        Copyright (c) 1991, 1992, Jos van de Woude, jvdwoude@hut.nl"
pause  0 ""
pause  0 ""
pause  0 " Permission granted to distribute freely for non-commercial purposes only"
pause  0 ""
pause  0 ""
pause  0 ""
pause  0 ""
pause  0 ""
pause  0 ""
pause  0 ""
pause  0 ""
pause  0 ""
pause  0 "     NOTE: contains 10 plots and consequently takes some time to run"
pause  0 "                      Press Ctrl-C to exit right now"
pause  0 ""
pause -1 "                      Press Return to start demo ..."

load "stat.inc"

# Binomial PDF using normal approximation
n = 25; p = 0.15
mu = n * p
sigma = sqrt(n * p * (1.0 - p))
xmin = floor(mu - 4.0 * sigma)
xmin = xmin < 0 ? 0 : xmin
xmax = ceil(mu + 4.0 * sigma)
ymax = 1.1 * binom(mu) #mode of binomial PDF used
xinc = ceil((xmax - xmin) / 10)
xinc = xinc > 1 ? xinc : 1
set key
set nozeroaxis
set xrange [xmin - 1 : xmax + 1]
set yrange [0 : ymax]
set xlabel "k, x ->"
set ylabel "probability density ->"
set xtics xmin + 0.499, ceil(sigma), xmax
set ytics 0, ymax / 10.0, ymax
set format x "%2.0f"
set format y "%3.2f"
set sample 200
set title "binomial PDF using normal approximation"
set arrow from mu + 0.5, 0 to mu + 0.5, normal(mu) nohead
set arrow from mu + 0.5, normal(mu + sigma) \
          to mu + 0.5 + sigma, normal(mu + sigma) nohead
set label "mu" at mu + 1, ymax / 10
set label "sigma" at mu + 1 + sigma, normal(mu + sigma)
plot binom(x), normal(x - 0.5)
pause -1 "Hit return to continue"
set noarrow
set nolabel

# Binomial PDF using poisson approximation
n = 50; p = 0.1
mu = n * p
sigma = sqrt(mu)
xmin = floor(mu - 4.0 * sigma)
xmin = xmin < 0 ? 0 : xmin
xmax = ceil(mu + 4.0 * sigma)
ymax = 1.1 * binom(mu) #mode of binomial PDF used
xinc = ceil((xmax - xmin) / 10)
xinc = xinc > 1 ? xinc : 1
set key
set nozeroaxis
set xrange [xmin - 1 : xmax + 1]
set yrange [0 : ymax]
set xlabel "k ->"
set ylabel "probability density ->"
set xtics xmin + 0.499, ceil(sigma), xmax
set ytics 0, ymax / 10.0, ymax
set format x "%2.0f"
set format y "%3.2f"
set sample 200
set title "binomial PDF using poisson approximation"
set arrow from mu + 0.5, 0 to mu + 0.5, normal(mu) nohead
set arrow from mu + 0.5, normal(mu + sigma) \
          to mu + 0.5 + sigma, normal(mu + sigma) nohead
set label "mu" at mu + 1, ymax / 10
set label "sigma" at mu + 1 + sigma, normal(mu + sigma)
plot binom(x), poisson(x)
pause -1 "Hit return to continue"
set noarrow
set nolabel

# Geometric PDF using gamma approximation
p = 0.3
mu = (1.0 - p) / p
sigma = sqrt(mu / p)
lambda = p
rho = 1.0 - p
xmin = floor(mu - 4.0 * sigma)
xmin = xmin < 0 ? 0 : xmin
xmax = ceil(mu + 4.0 * sigma)
xinc = ceil((xmax - xmin) / 10)
xinc = xinc > 1 ? xinc : 1
ymax = 1.1 * p
set key
set nozeroaxis
set xrange [xmin - 1 : xmax + 1]
set yrange [0 : ymax]
set xlabel "k, x ->"
set ylabel "probability density ->"
set xtics xmin + 0.499, ceil((xmax - xmin)/ 10.0), xmax
set ytics 0, ymax / 10.0, ymax
set format x "%2.0f"
set format y "%3.2f"
set sample 200
set title "geometric PDF using gamma approximation"
set arrow from mu + 0.5, 0 to mu + 0.5, g(mu) nohead
set arrow from mu + 0.5, g(mu + sigma) \
          to mu + 0.5 + sigma, g(mu + sigma) nohead
set label "mu" at mu + 1, ymax / 10
set label "sigma" at mu + 1 + sigma, g(mu + sigma)
plot geometric(x), g(x - 0.5)
pause -1 "Hit return to continue"
set noarrow
set nolabel

# Geometric PDF using normal approximation
p = 0.3
mu = (1.0 - p) / p
sigma = sqrt(mu / p)
xmin = floor(mu - 4.0 * sigma)
xmin = xmin < 0 ? 0 : xmin
xmax = ceil(mu + 4.0 * sigma)
xinc = ceil((xmax - xmin) / 10)
xinc = xinc > 1 ? xinc : 1
ymax = 1.1 * p
set key
set nozeroaxis
set xrange [xmin - 1 : xmax + 1]
set yrange [0 : ymax]
set xlabel "k, x ->"
set ylabel "probability density ->"
set xtics xmin + 0.499, ceil((xmax - xmin)/ 10.0), xmax
set ytics 0, ymax / 10.0, ymax
set format x "%2.0f"
set format y "%3.2f"
set sample 200
set title "geometric PDF using normal approximation"
set arrow from mu + 0.5, 0 to mu + 0.5, normal(mu) nohead
set arrow from mu + 0.5, normal(mu + sigma) \
          to mu + 0.5 + sigma, normal(mu + sigma) nohead
set label "mu" at mu + 1, ymax / 10
set label "sigma" at mu + 1 + sigma, normal(mu + sigma)
plot geometric(x), normal(x - 0.5)
pause -1 "Hit return to continue"
set noarrow
set nolabel

# Hypergeometric PDF using binomial approximation
nn = 75; mm = 25; n = 10
p = real(mm) / nn
mu = n * p
sigma = sqrt(real(nn - n) / (nn - 1.0) * n * p * (1.0 - p))
xmin = floor(mu - 4.0 * sigma)
xmin = xmin < 0 ? 0 : xmin
xmax = ceil(mu + 4.0 * sigma)
xinc = ceil((xmax - xmin) / 10)
xinc = xinc > 1 ? xinc : 1
ymax = 1.1 * hypgeo(mu) #mode of binom PDF used
set key
set nozeroaxis
set xrange [xmin - 1 : xmax + 1]
set yrange [0 : ymax]
set xlabel "k ->"
set ylabel "probability density ->"
set xtics xmin, xinc, xmax
set ytics 0, ymax / 10.0, ymax
set format x "%2.0f"
set format y "%3.2f"
set sample 200
set title "hypergeometric PDF using binomial approximation"
set arrow from mu + 0.5, 0 to mu + 0.5, binom(mu) nohead
set arrow from mu + 0.5, binom(mu + sigma) \
          to mu + 0.5 + sigma, binom(mu + sigma) nohead
set label "mu" at mu + 1, ymax / 10
set label "sigma" at mu + 1 + sigma, binom(mu + sigma)
plot hypgeo(x), binom(x)
pause -1 "Hit return to continue"
set noarrow
set nolabel

# Hypergeometric PDF using normal approximation
nn = 75; mm = 25; n = 10
p = real(mm) / nn
mu = n * p
sigma = sqrt(real(nn - n) / (nn - 1.0) * n * p * (1.0 - p))
xmin = floor(mu - 4.0 * sigma)
xmin = xmin < 0 ? 0 : xmin
xmax = ceil(mu + 4.0 * sigma)
xinc = ceil((xmax - xmin) / 10)
xinc = xinc > 1 ? xinc : 1
ymax = 1.1 * hypgeo(mu) #mode of binom PDF used
set key
set nozeroaxis
set xrange [xmin - 1 : xmax + 1]
set yrange [0 : ymax]
set xlabel "k, x ->"
set ylabel "probability density ->"
set xtics xmin, xinc, xmax
set ytics 0, ymax / 10.0, ymax
set format x "%2.0f"
set format y "%3.2f"
set sample 200
set title "hypergeometric PDF using normal approximation"
set arrow from mu + 0.5, 0 to mu + 0.5, normal(mu) nohead
set arrow from mu + 0.5, normal(mu + sigma) \
          to mu + 0.5 + sigma, normal(mu + sigma) nohead
set label "mu" at mu + 1, ymax / 10
set label "sigma" at mu + 1 + sigma, normal(mu + sigma)
plot hypgeo(x), normal(x - 0.5)
pause -1 "Hit return to continue"
set noarrow
set nolabel

# Negative binomial PDF using gamma approximation
r = 8; p = 0.6
mu = r * (1.0 - p) / p
sigma = sqrt(mu / p)
lambda = p
rho = r * (1.0 - p)
xmin = int(mu - 4.0 * sigma)
xmin = xmin < 0 ? 0 : xmin
xmax = int(mu + 4.0 * sigma)
xinc = ceil((xmax - xmin) / 10)
xinc = xinc > 1 ? xinc : 1
ymax = 1.1 * g((rho - 1) / lambda) #mode of gamma PDF used
set key
set nozeroaxis
set xrange [xmin - 1 : xmax + 1]
set yrange [0 : ymax]
set xlabel "k, x ->"
set ylabel "probability density ->"
set xtics xmin + 0.499, ceil((xmax - xmin)/ 10.0), xmax
set ytics 0, ymax / 10.0, ymax
set format x "%2.0f"
set format y "%3.2f"
set sample 200
set title "negative binomial PDF using gamma approximation"
set arrow from mu + 0.5, 0 to mu + 0.5, g(mu) nohead
set arrow from mu + 0.5, g(mu + sigma) \
          to mu + 0.5 + sigma, g(mu + sigma) nohead
set label "mu" at mu + 1, ymax / 10
set label "sigma" at mu + 1 + sigma, g(mu + sigma)
plot negbin(x), g(x - 0.5)
pause -1 "Hit return to continue"
set noarrow
set nolabel

# Negative binomial PDF using normal approximation
r = 8; p = 0.4
mu = r * (1.0 - p) / p
sigma = sqrt(mu / p)
xmin = floor(mu - 4.0 * sigma)
xmin = xmin < 0 ? 0 : xmin
xmax = ceil(mu + 4.0 * sigma)
xinc = ceil((xmax - xmin) / 10)
xinc = xinc > 1 ? xinc : 1
ymax = 1.1 * negbin(mu - 1/p) #mode of gamma PDF used
set key
set nozeroaxis
set xrange [xmin - 1 : xmax + 1]
set yrange [0 : ymax]
set xlabel "k, x ->"
set ylabel "probability density ->"
set xtics xmin + 0.499, ceil((xmax - xmin)/ 10.0), xmax
set ytics 0, ymax / 10.0, ymax
set format x "%2.0f"
set format y "%3.2f"
set sample 200
set title "negative binomial PDF using normal approximation"
set arrow from mu + 0.5, 0 to mu + 0.5, normal(mu) nohead
set arrow from mu + 0.5, normal(mu + sigma) \
          to mu + 0.5 + sigma, normal(mu + sigma) nohead
set label "mu" at mu + 1, ymax / 10
set label "sigma" at mu + 1 + sigma, normal(mu + sigma)
plot negbin(x), normal(x - 0.5)
pause -1 "Hit return to continue"
set noarrow
set nolabel

# Normal PDF using logistic approximation
mu = 1.0; sigma = 1.5
a = mu
lambda = pi / (sqrt(3.0) * sigma)
xmin = mu - 4.0 * sigma
xmax = mu + 4.0 * sigma
ymax = 1.1 * logistic(mu) #mode of logistic PDF used
set key
set nozeroaxis
set xrange [xmin: xmax]
set yrange [0 : ymax]
set xlabel "x ->"
set ylabel "probability density ->"
set xtics xmin, (xmax - xmin)/ 10.0, xmax
set ytics 0, ymax / 10.0, ymax
set format x "%.1f"
set format y "%.2f"
set sample 200
set title "normal PDF using logistic approximation"
set arrow from mu,0 to mu, normal(mu) nohead
set arrow from mu, normal(mu + sigma) \
          to mu + sigma, normal(mu + sigma) nohead
set label "mu" at mu + 1, ymax / 10
set label "sigma" at mu + 1 + sigma, normal(mu + sigma)
plot logistic(x), normal(x)
pause -1 "Hit return to continue"
set noarrow
set nolabel

# Poisson PDF using normal approximation
mu = 5.0
sigma = sqrt(mu)
xmin = floor(mu - 4.0 * sigma)
xmin = xmin < 0 ? 0 : xmin
xmax = ceil(mu + 4.0 * sigma)
xinc = ceil((xmax - xmin) / 10)
xinc = xinc > 1 ? xinc : 1
ymax = 1.1 * poisson(mu) #mode of poisson PDF used
set key
set nozeroaxis
set xrange [xmin - 1 : xmax + 1]
set yrange [0 : ymax]
set xlabel "k, x ->"
set ylabel "probability density ->"
set xtics xmin, xinc, xmax
set ytics 0, ymax / 10.0, ymax
set format x "%2.0f"
set format y "%3.2f"
set sample 200
set title "poisson PDF using normal approximation"
set arrow from mu + 0.5, 0 to mu + 0.5, normal(mu) nohead
set arrow from mu + 0.5, normal(mu + sigma) \
          to mu + 0.5 + sigma, normal(mu + sigma) nohead
set label "mu" at mu + 1, ymax / 10
set label "sigma" at mu + 1 + sigma, normal(mu + sigma)
plot poisson(x), normal(x - 0.5)
set noarrow
set nolabel