[R] 3D plot of a bivariate normal distribution
Rafael Bertola
bertola at fastmail.fm
Sat Aug 30 15:07:27 CEST 2003
Hi,
I've used the Mathematica to produce 3D graphics, contour plots of a
bivariate normal distribution
Now I want make these graphics in R, but i do not know how.
I would like to:
- Plot a 3D graph for some different variance matrix
- Plot the contour plots
- Find and try to plot (in the 3d graph ou contour plot) the (1-a)%
confidence region based in a chi-square(a) with the degrees of freedom
equal a 2 or bigger.
Below is the Mathematica Notebook that i've used until now
<< "Graphics`PlotField`"
NB[x_,y_]:=(1/((2 Pi)*Sqrt[a*b*(1-c^2)]))*Exp[(-1/(2*(1-c^2)))*(
((x-u)/Sqrt[a])^2 + ((y-v)/Sqrt[b])^2
- 2*c(((x-u)/Sqrt[a])((y-v)/Sqrt[b]))
)]
{{a,c}, {c,b}} = {{1,0}, {0,1}}; The covariance Matrix
{u,v} = {0,0}; Mean vector
Plot3D[NB[x,y],{x,-1.5,1.5},{y,-1.5,1.5},
AxesLabel->{x,y,z},
BoxRatios->{1,1,1}];
ContourPlot[NB[x,y],{x,-1,1},{y,-1,1},
Axes->True,
AxesLabel->{x,y}];
3d graph rotation
Do[
Plot3D[NB[x,y],{x,-1.5,1.5},{y,-1.5,1.5},
PlotPoints->20,
Mesh ->False,
SphericalRegion ->True,
Axes ->None,
Boxed ->False,
ViewPoint->{2 Cos[t], 2 Sin[t], 1.3},
BoxRatios->{1,1,1}
],{t, 0, 2Pi-2Pi/36, 2Pi/36}]
Thanks,
Rafael
--
bertola at fastmail.fm
--
love email again
More information about the R-help
mailing list