Annotation of OpenXM_contrib/gnuplot/demo/prob.dem, Revision 1.1.1.3
1.1 maekawa 1: #
1.1.1.3 ! ohara 2: # $Id: prob.dem,v 1.2.2.2 2001/09/18 11:48:47 lhecking Exp $
1.1 maekawa 3: #
4: # Demo Statistical Functions version 2.3
5: #
6: # Copyright (c) 1991, 1992 Jos van der Woude, jvdwoude@hut.nl
7:
8: print " Statistical Library Demo, version 2.3"
9: print "\n Copyright (c) 1991, 1992, Jos van de Woude, jvdwoude@hut.nl"
10: print "\n\n\n\n\n\n\n"
11: print "NOTE: contains 54 plots and consequently takes a lot of time to run"
12: print " Press Ctrl-C to exit right now"
13: pause -1 " Press Return to start demo ..."
14:
15: load "stat.inc"
16:
17: # Arcsinus PDF and CDF
18: r = 2.0
19: mu = 0.0
20: sigma = r / sqrt2
21: xmin = -r
22: xmax = r
23: ymax = 1.1 * r #No mode
24: set nokey
25: set zeroaxis
26: set xrange [xmin : xmax]
27: set yrange [0 : ymax]
28: set xlabel "x ->"
29: set ylabel "probability density ->"
30: set xtics autofreq
31: set ytics autofreq
32: set format x "%.1f"
33: set format y "%.1f"
34: set sample 200
35: set title "arcsin PDF with r = 2.0"
36: plot arcsin(x)
37: pause -1 "Hit return to continue"
38: set title "arcsin CDF with r = 2.0"
39: set yrange [0 : 1.1]
40: plot carcsin(x)
41: pause -1 "Hit return to continue"
42:
43: # Beta PDF and CDF
44: #p = 0.5; q = 0.7
45: #mu = p / (p + q)
46: #sigma = sqrt(p**q) / ((p + q ) * sqrt(p + q + 1.0))
47: #xmin = 0.0
48: #xmax = 1.0
49: #Mode of beta PDF used
50: #ymax = (p < 1.0 || q < 1.0) ? 2.0 : 1.1 * beta((p - 1.0)/(p + q - 2.0))
1.1.1.2 maekawa 51: set key right box
1.1 maekawa 52: set zeroaxis
53: #set xrange [xmin : xmax]
54: #set yrange [0 : ymax]
55: set xlabel "x ->"
56: set ylabel "probability density ->"
57: set xtics autofreq
58: set ytics autofreq
59: set format x "%.1f"
60: set format y "%.1f"
61: set sample 100
62: set title "beta PDF"
63: plot [0:1] [0:5] p = 0.5, q = 0.7, beta(x) title "p = 0.5, q = 0.7", \
64: p = 5.0, q = 3.0, beta(x) title "p = 5.0, q = 3.0", \
65: p = 0.5, q = 2.5, beta(x) title "p = 0.5, q = 2.5"
66: pause -1 "Hit return to continue"
67: set title "incomplete beta CDF"
1.1.1.2 maekawa 68: set key left box
1.1 maekawa 69: plot [0:1] [0:1.1] p = 0.5, q = 0.7, cbeta(x) title "p = 0.5, q = 0.7", \
70: p = 5.0, q = 3.0, cbeta(x) title "p = 5.0, q = 3.0", \
71: p = 0.5, q = 2.5, cbeta(x) title "p = 0.5, q = 2.5"
72: pause -1 "Hit return to continue"
73:
74: # Binomial PDF and CDF
75: n = 25; p = 0.15
76: mu = n * p
77: sigma = sqrt(n * p * (1.0 - p))
78: xmin = int(mu - 4.0 * sigma)
79: xmin = xmin < 0 ? 0 : xmin
80: xmax = int(mu + 4.0 * sigma)
81: ymax = 1.1 * binom(mu) #Mode of normal PDF used
82: xinc = ceil((xmax - xmin) / 10)
83: xinc = xinc > 1 ? xinc : 1
84: set nokey
85: set nozeroaxis
86: set xrange [xmin : xmax]
87: set yrange [0 : ymax]
88: set xlabel "k ->"
89: set ylabel "probability density ->"
90: set xtics xmin + 0.499, xinc, xmax
91: set ytics 0, ymax / 10, ymax
92: set format x "%2.0f"
93: set format y "%3.2f"
94: set sample (xmax - xmin) + 1
95: set title "binomial PDF with n = 25, p = 0.15"
96: plot binom(x) with steps
97: pause -1 "Hit return to continue"
98: set title "binomial CDF with n = 25, p = 0.15"
99: set yrange [0 : 1.1]
100: set ytics 0, 1.1 / 10.5, 1.1
101: plot cbinom(x) with steps
102: pause -1 "Hit return to continue"
103:
104: # Cauchy PDF and CDF
105: #a = 0.0; b = 2.0
106: #cauchy PDF has no moments
107: #xmin = a - 4.0 * b
108: #xmax = a + 4.0 * b
109: #ymax = 1.1 * cauchy(a) #Mode of cauchy PDF used
1.1.1.2 maekawa 110: set key left box
1.1 maekawa 111: set zeroaxis
112: #set xrange [xmin : xmax]
113: #set yrange [0 : ymax]
114: set xlabel "x ->"
115: set ylabel "probability density ->"
116: set xtics autofreq
117: set ytics autofreq
118: set format x "%.1f"
119: set format y "%.2f"
120: set sample 100
121: set title "cauchy PDF"
122: plot [-15:15] [0:0.2] a = 0, b = 2, cauchy(x) title "a = 0, b = 2", \
123: a = 0, b = 4, cauchy(x) title "a = 0, b = 4"
124: pause -1 "Hit return to continue"
125: set title "cauchy CDF"
126: plot [-30:30] [0:1.1] a = 0, b = 2, ccauchy(x) title "a = 0, b = 2", \
127: a = 0, b = 4, ccauchy(x) title "a = 0, b = 4"
128: pause -1 "Hit return to continue"
129:
130: # Chi-square PDF and CDF
131: #df1 = 4.0
132: #mu = df1
133: #sigma = sqrt(2.0 * df1)
134: #xmin = mu - 4.0 * sigma
135: #xmin = xmin < 0 ? 0 : xmin
136: #xmax = mu + 4.0 * sigma
137: #ymax = 1.1 * (df1 > 2.0 ? chi(df1 - 2.0) : 1.0) #Mode of chi PDF used
1.1.1.2 maekawa 138: set key right box
1.1 maekawa 139: set zeroaxis
140: #set xrange [xmin : xmax]
141: #set yrange [0 : ymax]
142: set xlabel "x ->"
143: set ylabel "probability density ->"
144: set xtics autofreq
145: set ytics autofreq
146: set format x "%.1f"
147: set format y "%.2f"
148: set sample 100
149: set title "chi-square PDF"
1.1.1.2 maekawa 150: set key right box
1.1 maekawa 151: plot [0:15] [0:0.2] df1 = 4, chi(x) title "df = 4", \
152: df1 = 6, chi(x) title "df = 6", \
153: df1 = 8, chi(x) title "df = 8"
154: pause -1 "Hit return to continue"
1.1.1.2 maekawa 155: set key left box
1.1 maekawa 156: set title "chi-square CDF"
157: plot [0:15] [0:1.1] df1 = 4, cchi(x) title "df = 4", \
158: df1 = 6, cchi(x) title "df = 6", \
159: df1 = 8, cchi(x) title "df = 8"
160: pause -1 "Hit return to continue"
161:
162: # Erlang PDF and CDF
163: #lambda = 1.0; n = 2.0
164: #mu = n / lambda
165: #sigma = sqrt(n) / lambda
166: #xmin = mu - 4.0 * sigma
167: #xmin = xmin < 0 ? 0 : xmin
168: #xmax = mu + 4.0 * sigma
169: #ymax = n < 2.0 ? 1.0 : 1.1 * erlang((n - 1.0) / lambda) #Mode of erlang PDF used
170: set zeroaxis
171: #set xrange [xmin : xmax]
172: #set yrange [0 : ymax]
173: set xlabel "x ->"
174: set ylabel "probability density ->"
175: set xtics autofreq
176: set ytics autofreq
177: set format x "%.1f"
178: set format y "%.1f"
179: set sample 100
180: set title "erlang PDF"
1.1.1.2 maekawa 181: set key right box
1.1 maekawa 182: plot [0:10] [0:1] lambda = 1, n = 2, erlang(x) title "lambda = 1, n = 2", \
183: lambda = 2, n = 2, erlang(x) title "lambda = 2, n = 2"
184: pause -1 "Hit return to continue"
185: set title "erlang CDF"
1.1.1.2 maekawa 186: set key left box
1.1 maekawa 187: plot [0:10] [0:1.1] lambda = 1, n = 2, cerlang(x) title "lambda = 1, n = 2", \
188: lambda = 2, n = 2, cerlang(x) title "lambda = 2, n = 2"
189: pause -1 "Hit return to continue"
190:
191: # Thanks to mrb2j@kelvin.seas.Virginia.EDU for telling us about this.
192: # Extreme (Gumbel extreme value) PDF and CDF
193: #alpha = 0.5; u = 1.0
194: #mu = u + (0.577215665/alpha) # Euler's constant
195: #sigma = pi/(sqrt(6.0)*alpha)
196: #xmin = mu - 4.0 * sigma
197: #xmax = mu + 4.0 * sigma
198: #ymax = 1.1 * extreme(u) #Mode of extreme PDF used
199: set zeroaxis
200: #set xrange [xmin : xmax]
201: #set yrange [0 : ymax]
202: set xlabel "x ->"
203: set ylabel "probability density ->"
204: set xtics autofreq
205: set ytics autofreq
206: set format x "%.1f"
207: set format y "%.2f"
208: set sample 100
209: set title "extreme PDF"
1.1.1.2 maekawa 210: set key left box
1.1 maekawa 211: plot [-10:10] [0:0.4] alpha = 0.5, u = 1.0, extreme(x) title "alpha = 0.5, u = 1.0", \
212: alpha = 1.0, u = 0.0, extreme(x) title "alpha = 1.0, u = 0.0"
213: pause -1 "Hit return to continue"
214: set title "extreme CDF"
1.1.1.2 maekawa 215: set key left box
1.1 maekawa 216: plot [-10:10] [0:1.1] alpha = 0.5, u = 1.0, cextreme(x) title "alpha = 0.5, u = 1.0", \
217: alpha = 1.0, u = 0.0, cextreme(x) title "alpha = 1.0, u = 0.0"
218: pause -1 "Hit return to continue"
219:
220: # F PDF and CDF
221: #df1 = 5.0; df2 = 9.0
222: #mu = df2 < 2.0 ? 1.0 : df2 / (df2 - 2.0)
223: #sigma = df2 < 4.0 ? 1.0 : mu * sqrt(2.0 * (df1 + df2 - 2.0) / (df1 * (df2 - 4.0)))
224: #xmin = mu - 4.0 * sigma
225: #xmin = xmin < 0 ? 0 : xmin
226: #xmax = mu + 4.0 * sigma
227: #Mode of F PDF used
228: #ymax = df1 < 3.0 ? 1.0 : 1.1 * f((df1 / 2.0 - 1.0) / (df1 / 2.0 + df1 / df2))
229: set zeroaxis
230: #set xrange [xmin : xmax]
231: #set yrange [0 : ymax]
232: set xlabel "x ->"
233: set ylabel "probability density ->"
234: set xtics autofreq
235: set ytics autofreq
236: set format x "%.1f"
237: set format y "%.2f"
238: set sample 100
239: set title "F PDF"
1.1.1.2 maekawa 240: set key right box
1.1 maekawa 241: plot [0:4] [0:0.8] df1 = 5.0, df2 = 9.0, f(x) title "df1 = 5, df2 = 9", \
242: df1 = 7.0, df2 = 6.0, f(x) title "df1 = 7, df2 = 6"
243: pause -1 "Hit return to continue"
244: set title "F CDF"
1.1.1.2 maekawa 245: set key left box
1.1 maekawa 246: plot [0:4] [0:1.1] df1 = 5.0, df2 = 9.0, cf(x) title "df1 = 5, df2 = 9", \
247: df1 = 7.0, df2 = 6.0, cf(x) title "df1 = 7, df2 = 6"
248: pause -1 "Hit return to continue"
249:
250: # Gamma PDF and incomplete gamma CDF
251: #rho = 0.5; lambda = 1.0
252: #mu = rho / lambda
253: #sigma = sqrt(rho) / lambda
254: #xmin = mu - 4.0 * sigma
255: #xmin = xmin < 0 ? 0 : xmin
256: #xmax = mu + 4.0 * sigma
257: #ymax = rho < 1.0 ? 2.0 : 1.1 * g((rho - 1.0) / lambda) #Mode of gamma pdf used
258: set zeroaxis
259: #set xrange [xmin: xmax]
260: #set yrange [0: ymax]
261: set xlabel "x ->"
262: set ylabel "probability density ->"
263: set xtics autofreq
264: set ytics autofreq
265: set format x "%.1f"
266: set format y "%.1f"
267: set sample 100
268: set title "gamma PDF"
1.1.1.2 maekawa 269: set key right
1.1 maekawa 270: plot [0:5] [0:1.5] rho = 0.5, lambda = 1.0, g(x) title "rho = 0.5, lambda = 1.0", \
271: rho = 1.0, lambda = 1.0, g(x) title "rho = 1.0, lambda = 1.0", \
272: rho = 2.0, lambda = 2.0, g(x) title "rho = 2.0, lambda = 2.0"
273: pause -1 "Hit return to continue"
274: set title "incomplete gamma CDF (lambda == 1.0)"
1.1.1.2 maekawa 275: set key right bottom
1.1 maekawa 276: plot [0:5] [0:1.1] rho = 0.5, cgamma(x) title "rho = 0.5", \
277: rho = 1.0, cgamma(x) title "rho = 1.0", \
278: rho = 2.0, cgamma(x) title "rho = 2.0"
279: pause -1 "Hit return to continue"
280:
281: # Geometric PDF and CDF
282: p = 0.4
283: mu = (1.0 - p) / p
284: sigma = sqrt(mu / p)
285: xmin = int(mu - 4.0 * sigma)
286: xmin = xmin < 0 ? 0 : xmin
287: xmax = int(mu + 4.0 * sigma)
288: xinc = ceil((xmax - xmin) / 10)
289: xinc = xinc > 1 ? xinc : 1
290: ymax = 1.1 * geometric(mu - 1/p) #mode of gamma PDF used
291: set nokey
292: set nozeroaxis
293: set xrange [xmin : xmax]
294: set yrange [0 : ymax]
295: set xlabel "k ->"
296: set ylabel "probability density ->"
297: set xtics xmin + 0.499, xinc, xmax
298: set ytics 0, ymax / 10, ymax
299: set format x "%2.0f"
300: set format y "%3.2f"
301: set sample (xmax - xmin) + 1
302: set title "geometric PDF with p = 0.4"
303: plot geometric(x) with steps
304: pause -1 "Hit return to continue"
305: set title "geometric CDF with p = 0.4"
306: set yrange [0 : 1.1]
307: set ytics 0, 1.1 / 10.5, 1.1
308: plot cgeometric(x) with steps
309: pause -1 "Hit return to continue"
310:
311: # Half normal PDF and CDF
312: mu = sqrt2invpi
313: sigma = 1.0
314: s = sigma*sqrt(1.0 - 2.0/pi)
315: xmin = 0.0
316: xmax = mu + 4.0 * s
317: ymax = 1.1 * halfnormal(0) #Mode of half normal PDF used
318: set nokey
319: set zeroaxis
320: set xrange [xmin: xmax]
321: set yrange [0: ymax]
322: set xlabel "x ->"
323: set ylabel "probability density ->"
324: set xtics autofreq
325: set ytics autofreq
326: set format x "%.1f"
327: set format y "%.1f"
328: set sample 100
329: set title "half normal PDF, sigma = 1.0"
330: plot halfnormal(x)
331: pause -1 "Hit return to continue"
332: set title "half normal CDF, sigma = 1.0"
333: set yrange [0:1.1]
334: plot chalfnormal(x)
335: pause -1 "Hit return to continue"
336:
337: # Hypergeometric PDF and CPF
338: nn = 75; mm = 25; n = 10
339: p = real(mm) / nn
340: mu = n * p
341: sigma = sqrt(real(nn - n) / (nn - 1.0) * n * p * (1.0 - p))
342: xmin = int(mu - 4.0 * sigma)
343: xmin = xmin < 0 ? 0 : xmin
344: xmax = int(mu + 4.0 * sigma)
345: xinc = ceil((xmax - xmin) / 10)
346: xinc = xinc > 1 ? xinc : 1
347: ymax = 1.1 * hypgeo(mu) #mode of binomial PDF used
348: set nokey
349: set nozeroaxis
350: set xrange [xmin : xmax]
351: set yrange [0 : ymax]
352: set xlabel "k ->"
353: set ylabel "probability density ->"
354: set xtics xmin + 0.499, xinc, xmax
355: set ytics 0, ymax / 10, ymax
356: set format x "%2.0f"
357: set format y "%3.2f"
358: set sample (xmax - xmin) + 1
359: set title "hypergeometric PDF with nn = 75, mm = 25, n = 10"
360: plot hypgeo(x) with steps
361: pause -1 "Hit return to continue"
362: set yrange [0 : 1.1]
363: set ytics 0, 1.1 / 10.5, 1.1
364: set title "hypergeometric CDF with nn = 75, mm = 25, n = 10"
365: plot chypgeo(x) with steps
366: pause -1 "Hit return to continue"
367:
368: # Laplace PDF
369: a = 0.0; b = 1.0
370: mu = a
371: sigma = sqrt(2.0) * b
372: xmin = mu - 4.0 * sigma
373: xmax = mu + 4.0 * sigma
374: ymax = 1.1 * laplace(a) #Mode of laplace PDF used
375: set nokey
376: set zeroaxis
377: set xrange [xmin: xmax]
378: set yrange [0: ymax]
379: set xlabel "x ->"
380: set ylabel "probability density ->"
381: set xtics autofreq
382: set ytics autofreq
383: set format x "%.1f"
384: set format y "%.2f"
385: set sample 100
386: set title "laplace (or double exponential) PDF with a = 0, b = 1"
387: plot laplace(x)
388: pause -1 "Hit return to continue"
389: set title "laplace (or double exponential) CDF with a = 0, b = 1"
390: set yrange [0: 1.1]
391: plot claplace(x)
392: pause -1 "Hit return to continue"
393:
394: # Logistic PDF and CDF
395: a = 0.0; lambda = 2.0
396: mu = a
397: sigma = pi / (sqrt(3.0) * lambda)
398: xmin = mu - 4.0 * sigma
399: xmax = mu + 4.0 * sigma
400: ymax = 1.1 * logistic(mu) #Mode of logistic PDF used
401: set nokey
402: set zeroaxis
403: set xrange [xmin: xmax]
404: set yrange [0: ymax]
405: set nokey
406: set zeroaxis
407: set xlabel "x ->"
408: set ylabel "probability density ->"
409: set xtics autofreq
410: set ytics autofreq
411: set format x "%.1f"
412: set format y "%.1f"
413: set sample 100
414: set title "logistic PDF with a = 0, lambda = 2"
415: plot logistic(x)
416: pause -1 "Hit return to continue"
417: set title "logistic CDF with a = 0, lambda = 2"
418: set yrange [0: 1.1]
419: plot clogistic(x)
420: pause -1 "Hit return to continue"
421:
422: # Lognormal PDF and CDF
423: mu = 1.0; sigma = 0.5
424: m = exp(mu + 0.5 * sigma**2)
425: s = sqrt(exp(2.0 * mu + sigma**2) * (2.0 * exp(sigma) - 1.0))
426: xmin = m - 4.0 * s
427: xmin = xmin < 0 ? 0 : xmin
428: xmax = m + 4.0 * s
429: ymax = 1.1 * lognormal(exp(mu - sigma**2)) #Mode of lognormal PDF used
430: set nokey
431: set zeroaxis
432: set xrange [xmin: xmax]
433: set yrange [0: ymax]
434: set xlabel "x ->"
435: set ylabel "probability density ->"
436: set xtics autofreq
437: set ytics autofreq
438: set format x "%.2f"
439: set format y "%.2f"
440: set sample 100
441: set title "lognormal PDF with mu = 1.0, sigma = 0.5"
442: plot lognormal(x)
443: pause -1 "Hit return to continue"
444: set title "lognormal CDF with mu = 1.0, sigma = 0.5"
445: set yrange [0: 1.1]
446: plot clognormal(x)
447: pause -1 "Hit return to continue"
448:
449: # Maxwell PDF
450: #a = 0.1
451: #mu = 2.0 / sqrt(pi) / a
452: #sigma = sqrt(3.0 - 8.0/pi) / a
453: #xmin = mu - 4.0 * sigma
454: #xmin = xmin < 0 ? 0 : xmin
455: #xmax = mu + 4.0 * sigma
456: #ymax = 1.1 * maxwell(1.0 / a) #Mode of maxwell PDF used
457: set zeroaxis
458: #set xrange[xmin: xmax]
459: #set yrange[0: ymax]
460: set xlabel "x ->"
461: set ylabel "probability density ->"
462: set xtics autofreq
463: set ytics autofreq
464: set format x "%.1f"
465: set format y "%.1f"
466: set sample 100
467: set title "maxwell PDF"
1.1.1.2 maekawa 468: set key right top box
1.1 maekawa 469: plot [0:6] [0:1.4] a = 1.5, maxwell(x) title "a = 1.5", \
470: a = 1.0, maxwell(x) title "a = 1.0", \
471: a = 0.5, maxwell(x) title "a = 0.5"
472: pause -1 "Hit return to continue"
473: set title "maxwell CDF"
1.1.1.2 maekawa 474: set key right bottom box
1.1 maekawa 475: plot [0:6] [0:1.1] a = 1.5, cmaxwell(x) title "a = 1.5", \
476: a = 1.0, cmaxwell(x) title "a = 1.0", \
477: a = 0.5, cmaxwell(x) title "a = 0.5"
478: pause -1 "Hit return to continue"
479:
480: # Negative binomial PDF and CDF
481: r = 8; p = 0.4
482: mu = r * (1.0 - p) / p
483: sigma = sqrt(mu / p)
484: xmin = int(mu - 4.0 * sigma)
485: xmin = xmin < 0 ? 0 : xmin
486: xmax = int(mu + 4.0 * sigma)
487: xinc = ceil((xmax - xmin) / 10)
488: xinc = xinc > 1 ? xinc : 1
489: ymax = 1.1 * negbin(mu - 1.0/p) #mode of gamma PDF used
490: set nokey
491: set nozeroaxis
492: set xrange [xmin : xmax]
493: set yrange [0 : ymax]
494: set xlabel "k ->"
495: set ylabel "probability density ->"
496: set xtics xmin + 0.499, xinc, xmax
497: set ytics 0, ymax / 10, ymax
498: set format x "%2.0f"
499: set format y "%3.2f"
500: set sample (xmax - xmin) + 1
501: set title "negative binomial (or pascal or polya) PDF with r = 8, p = 0.4"
502: plot negbin(x) with steps
503: pause -1 "Hit return to continue"
504: set yrange [0 : 1.1]
505: set ytics 0, 1.1 / 10.5, 1.1
506: set title "negative binomial (or pascal or polya) CDF with r = 8, p = 0.4"
507: plot cnegbin(x) with steps
508: pause -1 "Hit return to continue"
509:
510: # Negative exponential PDF and CDF
511: lambda = 2.0
512: mu = 1.0 / lambda
513: sigma = 1.0 / lambda
514: xmax = mu + 4.0 * sigma
515: ymax = lambda #No mode
516: set nokey
517: set zeroaxis
518: set xrange [0: xmax]
519: set yrange [0: ymax]
520: set xlabel "x ->"
521: set ylabel "probability density ->"
522: set xtics autofreq
523: set ytics autofreq
524: set format x "%.2f"
525: set format y "%.1f"
526: set sample 100
527: set title "negative exponential (or exponential) PDF with lambda = 2.0"
528: plot nexp(x)
529: pause -1 "Hit return to continue"
530: set title "negative exponential (or exponential) CDF with lambda = 2.0"
531: set yrange [0: 1.1]
532: plot cnexp(x)
533: pause -1 "Hit return to continue"
534:
535: # Normal PDF and CDF
536: #mu = 0.0; sigma = 1.0
537: #xmin = mu - 4.0 * sigma
538: #xmax = mu + 4.0 * sigma
539: #ymax = 1.1 * normal(mu) #Mode of normal PDF used
540: set zeroaxis
541: #set xrange [xmin: xmax]
542: #set yrange [0: ymax]
543: set xlabel "x ->"
544: set ylabel "probability density ->"
545: set xtics autofreq
546: set ytics autofreq
547: set format x "%.1f"
548: set format y "%.1f"
549: set sample 100
550: set title "normal (also called gauss or bell-curved) PDF"
1.1.1.2 maekawa 551: set key left top box
1.1 maekawa 552: plot [-4:4] [0:1] mu = 0, sigma = 1.0, normal(x) title "mu = 0, sigma = 1.0", \
553: mu = 2, sigma = 0.5, normal(x) title "mu = 2, sigma = 0.5", \
554: mu = 1, sigma = 2.0, normal(x) title "mu = 1, sigma = 2.0"
555: pause -1 "Hit return to continue"
556: set title "normal (also called gauss or bell-curved) CDF"
1.1.1.2 maekawa 557: set key left top box
1.1 maekawa 558: plot [-4:4] [0:1.1] mu = 0, sigma = 1.0, cnormal(x) title "mu = 0, sigma = 1.0", \
559: mu = 2, sigma = 0.5, cnormal(x) title "mu = 2, sigma = 0.5", \
560: mu = 1, sigma = 2.0, cnormal(x) title "mu = 1, sigma = 2.0"
561: pause -1 "Hit return to continue"
562:
563: # Pareto PDF and CDF
564: a = 1.0; b = 3.0
565: mu = a * b / (b - 1.0)
566: sigma = a * sqrt(b) / (sqrt(b - 2.0) * (b - 1.0))
567: xmin = mu - 4.0 * sigma
568: xmin = xmin < 0 ? 0 : xmin
569: xmax = mu + 4.0 * sigma
570: ymax = 1.1 * pareto(a) #mode of pareto PDF used
571: set nokey
572: set zeroaxis
573: set xrange [xmin: xmax]
574: set yrange [0: ymax]
575: set xlabel "x ->"
576: set ylabel "probability density ->"
577: set xtics autofreq
578: set ytics autofreq
579: set format x "%.1f"
580: set format y "%.1f"
581: set sample 500
582: set title "pareto PDF with a = 1, b = 3"
583: plot pareto(x)
584: pause -1 "Hit return to continue"
585: set title "pareto CDF with a = 1, b = 3"
586: set yrange [0: 1.1]
587: plot cpareto(x)
588: pause -1 "Hit return to continue"
589:
590: # Poisson PDF and CDF
591: mu = 4.0
592: sigma = sqrt(mu)
593: xmin = int(mu - 4.0 * sigma)
594: xmin = xmin < 0 ? 0 : xmin
595: xmax = int(mu + 4.0 * sigma)
596: xinc = ceil((xmax - xmin) / 10)
597: xinc = xinc > 1 ? xinc : 1
598: ymax = 1.1 * poisson(mu) #mode of poisson PDF used
599: set nokey
600: set nozeroaxis
601: set xrange [xmin : xmax]
602: set yrange [0 : ymax]
603: set xlabel "k ->"
604: set ylabel "probability density ->"
605: set xtics xmin + 0.499, xinc, xmax
606: set ytics 0, ymax / 10, ymax
607: set format x "%2.0f"
608: set format y "%3.2f"
609: set sample (xmax - xmin) + 1
610: set title "poisson PDF with mu = 4.0"
611: plot poisson(x) with steps
612: pause -1 "Hit return to continue"
613: set yrange [0 : 1.1]
614: set ytics 0, 1.1 / 10.5, 1.1
615: set title "poisson CDF with mu = 4.0"
616: plot cpoisson(x) with steps
617: pause -1 "Hit return to continue"
618:
619: # Rayleigh PDF and CDF
620: lambda = 2.0
621: mu = 0.5 * sqrt(pi / lambda)
622: sigma = sqrt((1.0 - pi / 4.0) / lambda)
623: xmax = mu + 4.0 * sigma
624: ymax = 1.1 * rayleigh(1.0 / sqrt(2.0 * lambda)) #Mode of rayleigh PDF used
625: set nokey
626: set zeroaxis
627: set xrange [0: xmax]
628: set yrange [0: ymax]
629: set xlabel "x ->"
630: set ylabel "probability density ->"
631: set xtics autofreq
632: set ytics autofreq
633: set format x "%.2f"
634: set format y "%.1f"
635: set sample 100
636: set title "rayleigh PDF with lambda = 2.0"
637: plot rayleigh(x)
638: pause -1 "Hit return to continue"
639: set title "rayleigh CDF with lambda = 2.0"
640: set yrange [0: 1.1]
641: plot crayleigh(x)
642: pause -1 "Hit return to continue"
643:
644: # Sine PDF and CDF
645: #a = 3.0; n = 2
646: #mu = a / 2.0
647: #sigma = sqrt(a * a / 3.0 * (1.0 - 3.0 / (2.0 * n * n * pi * pi)) - mu * mu)
648: #xmin = 0.0
649: #xmax = a
650: #ymax = 1.1 * 2.0 / a #Mode of sine PDF used
651: set zeroaxis
652: #set xrange [xmin: xmax]
653: #set yrange [0: ymax]
654: set xlabel "x ->"
655: set ylabel "probability density ->"
656: set xtics autofreq
657: set ytics autofreq
658: set format x "%.2f"
659: set format y "%.1f"
660: set sample 100
661: set title "sine PDF"
1.1.1.2 maekawa 662: set key bottom outside
1.1 maekawa 663: plot [0:2] [0:1.1] a = 2.0, n = 1, sine(x) title "a = 2.0, n = 1", \
664: a = 2.0, n = 3, sine(x) title "a = 2.0, n = 3"
665: pause -1 "Hit return to continue"
666: set title "sine CDF"
1.1.1.2 maekawa 667: set key top left
1.1 maekawa 668: plot [0:2] [0:1.1] a = 2.0, n = 1, csine(x) title "a = 2.0, n = 1", \
669: a = 2.0, n = 3, csine(x) title "a = 2.0, n = 3"
670: pause -1 "Hit return to continue"
671:
672: # t PDF and CDF
673: df1 = 3.0
674: mu = 0.0
675: sigma = df1 > 2.0 ? sqrt(df1 / (df1 - 2.0)) : 1.0
676: xmin = mu - 4.0 * sigma
677: xmax = mu + 4.0 * sigma
678: ymax = 1.1 * t(mu) #Mode of t PDF used
679: set nokey
680: set zeroaxis
681: set xrange [xmin: xmax]
682: set yrange [0: ymax]
683: set xlabel "x ->"
684: set ylabel "probability density ->"
685: set xtics autofreq
686: set ytics autofreq
687: set format x "%.1f"
688: set format y "%.2f"
689: set sample 100
690: set title "t PDF with df1 = 3.0"
691: plot t(x)
692: pause -1 "Hit return to continue"
693: set title "t CDF with df1 = 3.0"
694: set yrange [0: 1.1]
695: plot ct(x)
696: pause -1 "Hit return to continue"
697:
698: # Thanks to efrank@upenn5.hep.upenn.edu for telling us about this
699: # triangular PDF and CDF
700: m = 3.0
701: g = 2.0
702: mu = m
703: sigma = g/sqrt(6.0)
704: xmin = m - g
705: xmax = m + g
706: ymax = 1.1 * triangular(m) #Mode of triangular PDF used
707: set nokey
708: set zeroaxis
709: set xrange [xmin: xmax]
710: set yrange [0: ymax]
711: set xlabel "x ->"
712: set ylabel "probability density ->"
713: set xtics autofreq
714: set ytics autofreq
715: set format x "%.1f"
716: set format y "%.2f"
717: set sample 100
718: set title "triangular PDF with m = 3.0, g = 2.0"
719: plot triangular(x)
720: pause -1 "Hit return to continue"
721: set title "triangular CDF with m = 3.0, g = 2.0"
722: set yrange [0: 1.1]
723: plot ctriangular(x)
724: pause -1 "Hit return to continue"
725:
726: # Uniform PDF and CDF
727: a = -2.0; b= 2.0
728: mu = (a + b) / 2.0
729: sigma = (b - a) / sqrt(12.0)
730: xmin = a
731: xmax = b
732: ymax = 1.1 * uniform(mu) #No mode
733: set nokey
734: set zeroaxis
735: set xrange [xmin: xmax]
736: set yrange [0: ymax]
737: set xlabel "x ->"
738: set ylabel "probability density ->"
739: set xtics autofreq
740: set ytics autofreq
741: set format x "%.2f"
742: set format y "%.2f"
743: set sample 100
744: set title "uniform PDF with a = -2.0, b = 2.0"
745: plot uniform(x)
746: pause -1 "Hit return to continue"
747: set title "uniform CDF with a = -2.0, b = 2.0"
748: set yrange [0: 1.1]
749: plot cuniform(x)
750: pause -1 "Hit return to continue"
751:
752: # Weibull PDF and CDF
753: #lambda = 1.0; n = 1.5
754: #mu = lambda**(-1.0 / n) * gamma(1.0 / n) / n
755: #sigma = sqrt(2.0 * lambda**(-2.0 / n) * gamma(2.0 / n) / n - mu * mu)
756: #xmin = mu - 4.0 * sigma
757: #xmin = xmin < 0 ? 0 : xmin
758: #xmax = mu + 4.0 * sigma
759: #Mode of weibull PDF used
760: #ymax = 1.1 * (n > 1.0 ? weibull(((n - 1.0) / (lambda * n))**(1.0 / n)) : 2.0)
761: set key
762: set zeroaxis
763: #set xrange [xmin : xmax]
764: #set yrange [0: ymax]
765: set xlabel "x ->"
766: set ylabel "probability density ->"
767: set xtics autofreq
768: set ytics autofreq
769: set format x "%.2f"
770: set format y "%.1f"
771: set sample 100
772: set title "weibull PDF"
773: plot [0:2] [0:1.5] lambda = 1, n = 0.5, weibull(x) title "lambda = 1, n = 0.5", \
774: lambda = 1, n = 1.0, weibull(x) title "lambda = 1, n = 1.0", \
775: lambda = 1, n = 2.0, weibull(x) title "lambda = 1, n = 2.0", \
776: lambda = 3, n = 2.0, weibull(x) title "lambda = 3, n = 2.0"
777: pause -1 "Hit return to continue"
778: set title "weibull CDF"
779: plot [0:3] [0:1.2] lambda = 1, n = 0.5, cweibull(x) title "lambda = 1, n = 0.5", \
780: lambda = 1, n = 1.0, cweibull(x) title "lambda = 1, n = 1.0", \
781: lambda = 1, n = 2.0, cweibull(x) title "lambda = 1, n = 2.0", \
782: lambda = 3, n = 2.0, cweibull(x) title "lambda = 3, n = 2.0"
1.1.1.2 maekawa 783: reset
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>