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