Sample Probability Calculations
Sample Probability Calculations
The cumulative distribution function (CDF) may be used to compute probabilities for uniform distributions.
The next plot depicts the CDFs for a Uniform (0,1), Uniform(0,2), Uniform(0,3), Uniform(1,2), and Uniform(0.5,1). Can you identify which is which? What happens to the Uniform CDF as and change?
> restart: with(plots):
> F[1](x):=piecewise(x<=0,0,x>0 and x<1,x,x>=1,1):
> F[2](x):=piecewise(x<=0,0,x>0 and x<2,x/2,x>=2,1):
> F[3](x):=piecewise(x<=0,0,x>0 and x<3,x/3,x>=3,1):
> F[4](x):=piecewise(x<=1,0,x>1 and x<2,x-1,x>=2,1):
> F[5](x):=piecewise(x<=0.5,0,x>0.5 and x<1,2*x-1,x>=1,1):
> plot([F[1](x),F[2](x),F[3](x),F[4](x),F[5](x)],x=0..3);
> alpha:=0; beta:=1:
> f(x):=piecewise(x>alpha and x<beta,1/(beta-alpha));
> a:=plot(f(x),x=alpha..beta,color=black,title="Uniform(0,1) PDF"):
> b:=plot(f(x),x=alpha..0.4,color=yellow,filled=true):
> display([a,b]);
Find the value of the yellow shaded area, the area under the Unif(0, 1) density to the left of 0.4.
> UniformCDF(alpha..beta,0.4);
Areas can also be found using the integration command.
> evalf(int(f(x),x=alpha..0.4));
> a:=plot(f(x),x=alpha..beta,color=black,title="Uniform(0,1) PDF"):
> b:=plot(f(x),x=0.4..0.6,color=yellow,filled=true):
> display([a,b]);
Find the value of the yellow shaded area, the area between 0.4 and 0.6.
Using the CDF, we find the area to the left of 0.6 and then subtract the area to the left of 0.4.
> area1:=UniformCDF(alpha..beta,0.6);
> area2:=UniformCDF(alpha..beta,0.4);
> area_between:=area1-area2;
Using the integration command, we simply integrate Uni(0,1) PDF from 0.4 to 0.6..
> evalf(int(f(x),x=0.4..0.6));
> a:=plot(f(x),x=alpha..beta,color=black,title="Uniform(0,1) PDF",labels=[" "," "]):
> b:=plot(f(x),x=0.75..beta,color=yellow,filled=true,labels=[" "," "]):
> c:=textplot([0.75,-0.1,"x"],color=blue):
> d:=textplot([0.8,0.2,"0.25"]):
> display([a,b,c,d]);
Find the value of x . x is known as the third quartile for the Uniform(0,1) distribution.
Now we know the area under the curve to the left is 0.75 and we want to solve for x .
> fsolve(UniformCDF(alpha..beta,x)=0.75,x);