📄 prob2.dem
字号:
## $Id: prob2.dem,v 1.8 2004/02/14 03:14:43 sfeam Exp $## Demo Statistical Approximations version 1.1## Copyright (c) 1991, Jos van der Woude, jvdwoude@hut.nlprint ""print ""print ""print ""print ""print ""print " Statistical Approximations, version 1.1"print ""print " Copyright (c) 1991, 1992, Jos van de Woude, jvdwoude@hut.nl"print ""print ""print ""print ""print ""print ""print ""print ""print ""print ""print ""print " NOTE: contains 10 plots and consequently takes some time to run"print " Press Ctrl-C to exit right now"print ""pause -1 " Press Return to start demo ..."load "stat.inc"# Binomial PDF using normal approximationn = 25; p = 0.15mu = n * psigma = sqrt(n * p * (1.0 - p))xmin = floor(mu - 4.0 * sigma)xmin = xmin < 0 ? 0 : xminxmax = ceil(mu + 4.0 * sigma)ymax = 1.1 * binom(mu) #mode of binomial PDF usedxinc = ceil((xmax - xmin) / 10)xinc = xinc > 1 ? xinc : 1set key boxunset zeroaxisset xrange [xmin - 1 : xmax + 1]set yrange [0 : ymax]set xlabel "k, x ->"set ylabel "probability density ->"set xtics xmin + 0.499, ceil(sigma), xmaxset ytics 0, ymax / 10.0, ymaxset format x "%2.0f"set format y "%3.2f"set sample 200set title "binomial PDF using normal approximation"set arrow from mu + 0.5, 0 to mu + 0.5, normal(mu) noheadset arrow from mu + 0.5, normal(mu + sigma) \ to mu + 0.5 + sigma, normal(mu + sigma) noheadset label "mu" at mu + 1, ymax / 10set label "sigma" at mu + 1 + sigma, normal(mu + sigma)plot binom(x), normal(x - 0.5)pause -1 "Hit return to continue"unset arrowunset label# Binomial PDF using poisson approximationn = 50; p = 0.1mu = n * psigma = sqrt(mu)xmin = floor(mu - 4.0 * sigma)xmin = xmin < 0 ? 0 : xminxmax = ceil(mu + 4.0 * sigma)ymax = 1.1 * binom(mu) #mode of binomial PDF usedxinc = ceil((xmax - xmin) / 10)xinc = xinc > 1 ? xinc : 1set key boxunset zeroaxisset xrange [xmin - 1 : xmax + 1]set yrange [0 : ymax]set xlabel "k ->"set ylabel "probability density ->"set xtics xmin + 0.499, ceil(sigma), xmaxset ytics 0, ymax / 10.0, ymaxset format x "%2.0f"set format y "%3.2f"set sample 200set title "binomial PDF using poisson approximation"set arrow from mu + 0.5, 0 to mu + 0.5, normal(mu) noheadset arrow from mu + 0.5, normal(mu + sigma) \ to mu + 0.5 + sigma, normal(mu + sigma) noheadset label "mu" at mu + 1, ymax / 10set label "sigma" at mu + 1 + sigma, normal(mu + sigma)plot binom(x), poisson(x)pause -1 "Hit return to continue"unset arrowunset label# Geometric PDF using gamma approximationp = 0.3mu = (1.0 - p) / psigma = sqrt(mu / p)lambda = prho = 1.0 - pxmin = floor(mu - 4.0 * sigma)xmin = xmin < 0 ? 0 : xminxmax = ceil(mu + 4.0 * sigma)xinc = ceil((xmax - xmin) / 10)xinc = xinc > 1 ? xinc : 1ymax = 1.1 * pset key boxunset zeroaxisset 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), xmaxset ytics 0, ymax / 10.0, ymaxset format x "%2.0f"set format y "%3.2f"set sample 200set title "geometric PDF using gamma approximation"set arrow from mu + 0.5, 0 to mu + 0.5, g(mu) noheadset arrow from mu + 0.5, g(mu + sigma) \ to mu + 0.5 + sigma, g(mu + sigma) noheadset label "mu" at mu + 1, ymax / 10set label "sigma" at mu + 1 + sigma, g(mu + sigma)plot geometric(x), g(x - 0.5)pause -1 "Hit return to continue"unset arrowunset label# Geometric PDF using normal approximationp = 0.3mu = (1.0 - p) / psigma = sqrt(mu / p)xmin = floor(mu - 4.0 * sigma)xmin = xmin < 0 ? 0 : xminxmax = ceil(mu + 4.0 * sigma)xinc = ceil((xmax - xmin) / 10)xinc = xinc > 1 ? xinc : 1ymax = 1.1 * pset key boxunset zeroaxisset 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), xmaxset ytics 0, ymax / 10.0, ymaxset format x "%2.0f"set format y "%3.2f"set sample 200set title "geometric PDF using normal approximation"set arrow from mu + 0.5, 0 to mu + 0.5, normal(mu) noheadset arrow from mu + 0.5, normal(mu + sigma) \ to mu + 0.5 + sigma, normal(mu + sigma) noheadset label "mu" at mu + 1, ymax / 10set label "sigma" at mu + 1 + sigma, normal(mu + sigma)plot geometric(x), normal(x - 0.5)pause -1 "Hit return to continue"unset arrowunset label# Hypergeometric PDF using binomial approximationnn = 75; mm = 25; n = 10p = real(mm) / nnmu = n * psigma = sqrt(real(nn - n) / (nn - 1.0) * n * p * (1.0 - p))xmin = floor(mu - 4.0 * sigma)xmin = xmin < 0 ? 0 : xminxmax = ceil(mu + 4.0 * sigma)xinc = ceil((xmax - xmin) / 10)xinc = xinc > 1 ? xinc : 1ymax = 1.1 * hypgeo(mu) #mode of binom PDF usedset key boxunset zeroaxisset xrange [xmin - 1 : xmax + 1]set yrange [0 : ymax]set xlabel "k ->"set ylabel "probability density ->"set xtics xmin, xinc, xmaxset ytics 0, ymax / 10.0, ymaxset format x "%2.0f"set format y "%3.2f"set sample 200set title "hypergeometric PDF using binomial approximation"set arrow from mu + 0.5, 0 to mu + 0.5, binom(mu) noheadset arrow from mu + 0.5, binom(mu + sigma) \ to mu + 0.5 + sigma, binom(mu + sigma) noheadset label "mu" at mu + 1, ymax / 10set label "sigma" at mu + 1 + sigma, binom(mu + sigma)plot hypgeo(x), binom(x)pause -1 "Hit return to continue"unset arrowunset label# Hypergeometric PDF using normal approximationnn = 75; mm = 25; n = 10p = real(mm) / nnmu = n * psigma = sqrt(real(nn - n) / (nn - 1.0) * n * p * (1.0 - p))xmin = floor(mu - 4.0 * sigma)xmin = xmin < 0 ? 0 : xminxmax = ceil(mu + 4.0 * sigma)xinc = ceil((xmax - xmin) / 10)xinc = xinc > 1 ? xinc : 1ymax = 1.1 * hypgeo(mu) #mode of binom PDF usedset key boxunset zeroaxisset xrange [xmin - 1 : xmax + 1]set yrange [0 : ymax]set xlabel "k, x ->"set ylabel "probability density ->"set xtics xmin, xinc, xmaxset ytics 0, ymax / 10.0, ymaxset format x "%2.0f"set format y "%3.2f"set sample 200set title "hypergeometric PDF using normal approximation"set arrow from mu + 0.5, 0 to mu + 0.5, normal(mu) noheadset arrow from mu + 0.5, normal(mu + sigma) \ to mu + 0.5 + sigma, normal(mu + sigma) noheadset label "mu" at mu + 1, ymax / 10set label "sigma" at mu + 1 + sigma, normal(mu + sigma)plot hypgeo(x), normal(x - 0.5)pause -1 "Hit return to continue"unset arrowunset label# Negative binomial PDF using gamma approximationr = 8; p = 0.6mu = r * (1.0 - p) / psigma = sqrt(mu / p)lambda = prho = r * (1.0 - p)xmin = int(mu - 4.0 * sigma)xmin = xmin < 0 ? 0 : xminxmax = int(mu + 4.0 * sigma)xinc = ceil((xmax - xmin) / 10)xinc = xinc > 1 ? xinc : 1ymax = 1.1 * g((rho - 1) / lambda) #mode of gamma PDF usedset key boxunset zeroaxisset 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), xmaxset ytics 0, ymax / 10.0, ymaxset format x "%2.0f"set format y "%3.2f"set sample 200set title "negative binomial PDF using gamma approximation"set arrow from mu + 0.5, 0 to mu + 0.5, g(mu) noheadset arrow from mu + 0.5, g(mu + sigma) \ to mu + 0.5 + sigma, g(mu + sigma) noheadset label "mu" at mu + 1, ymax / 10set label "sigma" at mu + 1 + sigma, g(mu + sigma)plot negbin(x), g(x - 0.5)pause -1 "Hit return to continue"unset arrowunset label# Negative binomial PDF using normal approximationr = 8; p = 0.4mu = r * (1.0 - p) / psigma = sqrt(mu / p)xmin = floor(mu - 4.0 * sigma)xmin = xmin < 0 ? 0 : xminxmax = ceil(mu + 4.0 * sigma)xinc = ceil((xmax - xmin) / 10)xinc = xinc > 1 ? xinc : 1ymax = 1.1 * negbin(mu - 1/p) #mode of gamma PDF usedset key boxunset zeroaxisset 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), xmaxset ytics 0, ymax / 10.0, ymaxset format x "%2.0f"set format y "%3.2f"set sample 200set title "negative binomial PDF using normal approximation"set arrow from mu + 0.5, 0 to mu + 0.5, normal(mu) noheadset arrow from mu + 0.5, normal(mu + sigma) \ to mu + 0.5 + sigma, normal(mu + sigma) noheadset label "mu" at mu + 1, ymax / 10set label "sigma" at mu + 1 + sigma, normal(mu + sigma)plot negbin(x), normal(x - 0.5)pause -1 "Hit return to continue"unset arrowunset label# Normal PDF using logistic approximationmu = 1.0; sigma = 1.5a = mulambda = pi / (sqrt(3.0) * sigma)xmin = mu - 4.0 * sigmaxmax = mu + 4.0 * sigmaymax = 1.1 * logistic(mu) #mode of logistic PDF usedset key boxunset zeroaxisset xrange [xmin: xmax]set yrange [0 : ymax]set xlabel "x ->"set ylabel "probability density ->"set xtics xmin, (xmax - xmin)/ 10.0, xmaxset ytics 0, ymax / 10.0, ymaxset format x "%.1f"set format y "%.2f"set sample 200set title "normal PDF using logistic approximation"set arrow from mu,0 to mu, normal(mu) noheadset arrow from mu, normal(mu + sigma) \ to mu + sigma, normal(mu + sigma) noheadset label "mu" at mu + 1, ymax / 10set label "sigma" at mu + 1 + sigma, normal(mu + sigma)plot logistic(x), normal(x)pause -1 "Hit return to continue"unset arrowunset label# Poisson PDF using normal approximationmu = 5.0sigma = sqrt(mu)xmin = floor(mu - 4.0 * sigma)xmin = xmin < 0 ? 0 : xminxmax = ceil(mu + 4.0 * sigma)xinc = ceil((xmax - xmin) / 10)xinc = xinc > 1 ? xinc : 1ymax = 1.1 * poisson(mu) #mode of poisson PDF usedset key boxunset zeroaxisset xrange [xmin - 1 : xmax + 1]set yrange [0 : ymax]set xlabel "k, x ->"set ylabel "probability density ->"set xtics xmin, xinc, xmaxset ytics 0, ymax / 10.0, ymaxset format x "%2.0f"set format y "%3.2f"set sample 200set title "poisson PDF using normal approximation"set arrow from mu + 0.5, 0 to mu + 0.5, normal(mu) noheadset arrow from mu + 0.5, normal(mu + sigma) \ to mu + 0.5 + sigma, normal(mu + sigma) noheadset label "mu" at mu + 1, ymax / 10set label "sigma" at mu + 1 + sigma, normal(mu + sigma)plot poisson(x), normal(x - 0.5)pause -1 "Hit return to continue"reset
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -