I have empirical data that describes a 2-dimensional Probability Density Function and I want to visualize that data in a meaningful way using Mathematica. My first instinct is to use a 2D Heat map style plot, where high probabilities would be shown in red, and low in blue or white. However I am a novice when it comes to Mathematica's visualization power so I would like some community input. Is there a better way to visualize this data?
Here's an example using defined distributions:
Plot3D[PDF[BinormalDistribution[.3], {x, y}], {x, -3, 3}, {y, -3, 3},
Mesh -> None, PlotStyle -> ColorData[45, 1],
PlotLabel -> "Multinormal",
ColorFunction -> (ColorData["DarkRainbow"][#3] &)]
or:
DensityPlot[
PDF[BinormalDistribution[.3], {x, y}], {x, -3, 3}, {y, -3, 3},
PlotLabel -> "Multinormal", ColorFunction -> "DarkRainbow", PlotLegends->Automatic]
However, with empirical data, you can apply an empirical distribution.
Let's start with some (not very) empirical data:
data = RandomVariate[BinormalDistribution[.3], {2000}];
Now, we can apply a SmoothKernelDistibution
. This will smooth your data. If the population of your samples isn't very large, its smoothing can overwhelm the data--so use some caution.
d = SmoothKernelDistribution[data];
Now, we can plot it as above:
Plot3D[PDF[d, {x, y}], {x, -3, 3}, {y, -3, 3},
PlotLabel -> "Empirical Distribution",
ColorFunction -> "DarkRainbow", PlotLegends -> Automatic]
Other methods include fitting an assumed distribution, e.g. by using EstimatedDistribution
, FindDistributionParameters
or related.
-
$\begingroup$ Note OP is talking about "empirical data", not given functions. $\endgroup$ – Vitaliy Kaurov May 30 '13 at 0:35
-
$\begingroup$ @Vitaliy Kaurov, Yeah, probably should add something about that.... $\endgroup$ – kale May 30 '13 at 0:36
-
2$\begingroup$ If one just wants to do visualization, instead of going through
SmoothKernelDistribution[]
, one could directly useSmoothHistogram3D[]
orSmoothDensityHistogram[]
. $\endgroup$ – J. M.'s ennui♦ May 30 '13 at 2:19
PDF
. There are a couple of 2D examples. $\endgroup$ – geordie May 30 '13 at 0:33