Bivariate Normal Distribution

Hermann.Singer@FernUni-Hagen.de

@BOOK{Mardia:1979,
	AUTHOR = {Mardia, K.V. and Kent, J.T. and Bibby, J.M.},
	TITLE = {{Multivariate Analysis}},
	PUBLISHER = {Academic Press},
	ADDRESS = {London},
	YEAR = {1979} }  p. 41

f//Clear
f[{x_,y_},mux_,muy_,sx_,sy_,rho_]:=
Module[{sxy,z,Sigma1,lambda},
sxy=sx sy rho;
Sigma={{sx^2,sxy},{sxy,sy^2}};
z={x-mux,y-muy};
Sigma1=Sigma//PseudoInverse;
lambda=Sigma//Eigenvalues;
lambda=Times@@Select[lambda,(#≠0)&];
k=Sigma//MatrixRank;
(2Pi)^(-k/2)/lambda^0.5  Exp[-0.5 z.Sigma1.z]
]

Manipulate[
g1=Plot3D[f[{x,y},mux,muy,sx,sy,rho],{x,-3,3},{y,-3,3},ColorFunction->Hue,
                          PlotRange->All,Mesh->False,PlotPoints->(plotpoints//Ceiling),
                         Background->White];

g2=ContourPlot[f[{x,y},mux,muy,sx,sy,rho],{x,-3,3},{y,-3,3},ColorFunction->Hue,PlotRange->All,PlotPoints->(plotpoints//Ceiling),
                                      PlotLabel->"ρ = "<>ToString@rho<>", rank(Σ) = "<>ToString@k];

sxy=sx sy rho;
eps=$MachineEpsilon;
S={{eps+sx^2,sxy},{sxy,eps+sy^2}}//CholeskyDecomposition//Transpose;
SeedRandom[seed//Ceiling];
data=Map[({mux,muy}+S.#)&,RandomReal[NormalDistribution[0,1],{n=datapoints//Ceiling,2}]];
  g3=data//ListPlot[#,Joined->False,Frame->True,Axes->False,AspectRatio->1,
                                          PlotRange->{{-3,3},{-3,3}},PlotStyle->{Blue,PointSize[.02]},
                                          PlotLabel->"r = "<>ToString@Correlation[data][[1,2]]<>", n = "<>ToString@n]&;

{g1,g2,g3}//GraphicsRow[#,ImageSize->800]&

,{mux,0,1},{muy,0,1},{{sx,1},0,2},{{sy,1},0,2},{{rho,0},-.999,.999},{seed,1,100},
   {{datapoints,100},2,1000},{plotpoints,10,50},SaveDefinitions->True]

Integrate[f[{x,y},0,0,1,1,.5],{x,-Infinity,Infinity},{y,-Infinity,Infinity}]