/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/ /* [ Created with wxMaxima version 12.04.0 ] */ /* [wxMaxima: comment start ] Eryk Wdowiak 10 July 2016 wxMaxima notebook to plot: * normal distribution (univariate) * bivariate normal distribution * conditional distribution [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] normal distribution (univariate): [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ f(x,mu,sigma) := (1/ sqrt(2 * %pi * sigma^2) ) * exp( (1/-2) * ( (((x - mu)/sigma)^2) )) $ print("the normal distribution: ","f(x,",mu,",",sigma^2,")"," = ",f(x,mu,sigma))$ print("")$ print("the standard normal: ",mu," = 0, ",sigma," = 1")$ wxplot2d( f(x,0,1), [x,-3,3], [xlabel,"x"], [ylabel,"relative frequency"])$ print("")$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] bivariate normal distribution mean(x) = 0, mean(y) = 0, sd(x) = 1, sd(y) = 1, rho = -0.75 [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ g(x,y,mx,my,sx,sy,rho) := (1/ ( 2 * %pi * sx * sy * (( 1 - (rho)^2 )^(1/2)) )) * exp( (1/(-2*(1-rho^2))) * ( (((x - mx)/sx)^2) - 2*rho*((x-my)/sx)*((y-my)/sy) + (((y - my)/sy)^2) ) ) $ print("")$ print("the bivariate normal distribution: ")$ print("g(x,y,mx,my,sx,sy,rho)"," = ",g(x,y,mx,my,sx,sy,rho))$ print("")$ wxplot3d( g(x,y,0,0,1,1,-0.75) , [x,-2,2],[y,-2,2])$ plot3d( g(x,y,0,0,1,1,-0.75) , [x,-2,2],[y,-2,2])$ print("The long \"ridge\" represents the correlation between X and Y.")$ print("")$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The conditional distribution is a cross-section of the bivariate distribution. It's the distribution of Y, conditional upon a given value of X [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ /* take the cross section at: x = 0 */ h(y,mx,my,sx,sy,rho) := ''( g(0,y,mx,my,sx,sy,rho) ) $ print("")$ print("the conditional distribution: ")$ print("h(y,mx,my,sx,sy,rho)"," = ",h(y,mx,my,sx,sy,rho))$ print("")$ wxplot2d( h(y,0,0,1,1,-0.75), [y,-2,2], [xlabel,"y"], [ylabel,"relative frequency"])$ print("")$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The conditional distribution looks very similar to the univariate, but it is not the same. The area beneath the conditional distribution is LESS than one. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ print("")$ print("the area under the normal distrib is: ", ''(float(integrate(f(x,0,1), x, -99, 99))) )$ print("the area under this cross section is: ", float(integrate(h(y,0,0,1,1,-0.75), y, -99, 99) ))$ print("")$ /* [wxMaxima: input end ] */ /* Maxima can't load/batch files which end with a comment! */ "Created with wxMaxima"$