Example 7: Relationships Between Random Variables
by Zavan Karian
> restart: with(plots, display): libname:="C:/mylib/statistics",libname: with(stat):
> Z1 := NormalS(0,1,500):
> Z1H := Histogram(Z1, -4..4, 9):
> N01 := plot(NormalPDF(0,1,x), x=-4..4):
> display({Z1H, N01});
> Y := [seq(Z1[i]^2, i=1..500)]:
> YH := Histogram(Y, 0..12, 16):
> CH1 := plot(ChisquarePDF(1,x), x=0..12):
> #interface(plotdevice=postscript, plotoutput=Fig7a);
> display({YH, CH1});
>
> Z2 := NormalS(0,1,500):
> Z3 := NormalS(0,1,500):
> Y := [seq(Z1[i]^2+Z2[i]^2+Z3[i]^2, i=1..500)]:
> YH := Histogram(Y, 0..18, 24):
> CH3 := plot(ChisquarePDF(3,x), x=0..12):
> #interface(plotdevice=postscript, plotoutput=Fig7b);
> display({YH, CH3});
>
> Z := [seq(NormalS(37, 16, 3), i=1..200)]:
> S := [seq(sum( (Z[i][j]-37)^2/16, j=1..3), i=1..200)]:
> T := [seq(sum( (Z[i][j]-Mean(Z[i]))^2/16, j=1..3), i=1..200)]:
> SH := Histogram(S, 0..20, 16):
> TH := Histogram(T, 0..20, 16):
> CH2 := plot(ChisquarePDF(2,x), x=0..20):
> CH3 := plot(ChisquarePDF(3,x), x=0..20):
> #interface(plotdevice=postscript, plotoutput=Fig8a);
> display({CH3, SH});
> #interface(plotdevice=postscript, plotoutput=Fig8b);
> display({CH2, TH});