Probability Distribution Function and Shape
The Uniform Distribution
A random variable X has a uniform distribution if and only if its probability density is given by
for < x <
f ( x ) =
0 elsewhere
where are real numbers.
The following code will draw the density function for the Unif( ) distribution for your choices of .
> restart:
> with(plots):
> alpha:=0; beta:=1;
> f(x):=piecewise(x>alpha and x<beta,1/(beta-alpha));
> plot(f(x),x=alpha..beta,title="Uniform(0,1) PDF");
To see the effect of on the shape of the Uniform( , ) distribution, the following animation will draw a series of probability density functions as varies from 0 to 2.1 by increments of 0.1 while holding constant at 3. Do you see why is a "shape" parameter?
> alpha:=0; initial:=0; alpha_step:=0.1; beta:=3;
> f(x):=piecewise(x>alpha and x<beta,1/(beta-alpha));
> for n from 0 to 21 do
> density[n]:=plot(f(x),x=0..3):
> num:=convert(alpha,string):
> tracker[n]:=textplot([2.2,0.8,"alpha is ".num],color=blue);
> P[n]:=display({density[n],tracker[n]}):
> alpha:=initial+n*alpha_step:
> f(x):=piecewise(x>alpha and x<beta,1/(beta-alpha)):
> od:
> display([seq(P[n],n=0..21)],insequence=true, title="Changing alpha");
This next bit of code will animate a Uniform( , ) with a dynamic , holding constant at 0. will
vary from 1 to 3 at intervals of 0.1.
> alpha:=0; beta:=1; initial:=1; beta_step:=0.1;
> f(x):=piecewise(x>alpha and x<beta,1/(beta-alpha));
> for n from 0 to 21 do
> density[n]:=plot(f(x),x=0..3):
> num:=convert(beta,string):
> tracker[n]:=textplot([2.2,0.8,"beta is ".num],color=blue);
> P[n]:=display({density[n],tracker[n]}):
> beta:=initial+n*beta_step:
> f(x):=piecewise(x>alpha and x<beta,1/(beta-alpha)):
> od:
> display([seq(P[n],n=0..21)],insequence=true, title="Changing beta");
Can you anticipate what happens if and both increase at the same rate? In the following animation, they both increase at a step size of 0.1 After you examine this animation, feel free to change the code so that they increase at different rates. If you'd like, you can change it so one is decreasing while the other is increasing.
> alpha:=0; ainitial:=0; alpha_step:=0.1; beta:=1; binitial:=1; beta_step:=0.1;
> f(x):=piecewise(x>alpha and x<beta,1/(beta-alpha));
> for n from 0 to 21 do
> numa:=convert(alpha,string):
> tracka[n]:=textplot([2.2,0.8,"alpha is ".numa],color=blue);
> numb:=convert(beta,string):
> trackb[n]:=textplot([2.2,0.5,"beta is ".numb],color=blue);
> density[n]:=plot(f(x),x=0..3):
> P[n]:=display({density[n],tracka[n],trackb[n]}):
> alpha:=ainitial+n*alpha_step:
> beta:=binitial+n*beta_step:
> f(x):=piecewise(x>alpha and x<beta,1/(beta-alpha)):
> od:
> display([seq(P[n], n=0..21)],insequence=true,title="Changing alpha and beta, with beta - alpha fixed.");
>
>