Skip to main content
added 3D visualization
Source Link
Karsten7
  • 27.6k
  • 5
  • 74
  • 135

A visualization of the PDF together with a red line at the mean point and a blue line at the maximum point

Module[{dist = SmoothKernelDistribution[Transpose[{xValues, yValues}]], 
   meanPoint = Mean[ed2D], maxPoint}, 
  maxPoint = ArgMax[PDF[dist, {x, y}], {x, y}]; 
  Show[Plot3D[Evaluate[PDF[dist, {x, y}]], 
    {x, Min[xValues] - 2 First@dist["Bandwidth"], Max[xValues] + 2 First@dist["Bandwidth"]}, 
    {y, Min[yValues] - 2 Last@dist["Bandwidth"], Max[yValues] + 2 Last@dist["Bandwidth"]}, 
    PlotRange -> All], 
   Graphics3D[{Darker@Red, Thickness[.02], 
    Line[{Append[meanPoint, 0], Append[meanPoint, 0.13]}]}],
   Graphics3D[{Darker@Blue, Thickness[.02], 
    Line[{Append[maxPoint, 0], Append[maxPoint, 0.18]}]}] ]]

3D_PDF

A visualization of the PDF together with a red line at the mean point and a blue line at the maximum point

Module[{dist = SmoothKernelDistribution[Transpose[{xValues, yValues}]], 
   meanPoint = Mean[ed2D], maxPoint}, 
  maxPoint = ArgMax[PDF[dist, {x, y}], {x, y}]; 
  Show[Plot3D[Evaluate[PDF[dist, {x, y}]], 
    {x, Min[xValues] - 2 First@dist["Bandwidth"], Max[xValues] + 2 First@dist["Bandwidth"]}, 
    {y, Min[yValues] - 2 Last@dist["Bandwidth"], Max[yValues] + 2 Last@dist["Bandwidth"]}, 
    PlotRange -> All], 
   Graphics3D[{Darker@Red, Thickness[.02], 
    Line[{Append[meanPoint, 0], Append[meanPoint, 0.13]}]}],
   Graphics3D[{Darker@Blue, Thickness[.02], 
    Line[{Append[maxPoint, 0], Append[maxPoint, 0.18]}]}] ]]

3D_PDF

added "another" POV
Source Link
Karsten7
  • 27.6k
  • 5
  • 74
  • 135

from your link.
There a two possible interpretations for these data points.

Interpretation as univariate distribution

Interpreting the yValues as weights and finding the most probable xValue as the objective.
One can create a WeightedData object using

PDF

Interpretation as multivariate distribution

Interpreting the xValues and yValues as 2D data points and with "finding the most probable {x,y} data point" as the objective.
One can create an EmpiricalDistribution object

ed2D = EmpiricalDistribution[Transpose[{xValues, yValues}]]

and then calculate its mean with

Mean[ed2D]

{-0.227361, 1.88819}

from your link.
One can create a WeightedData object using

PDF

from your link.
There a two possible interpretations for these data points.

Interpretation as univariate distribution

Interpreting the yValues as weights and finding the most probable xValue as the objective.
One can create a WeightedData object using

PDF

Interpretation as multivariate distribution

Interpreting the xValues and yValues as 2D data points and with "finding the most probable {x,y} data point" as the objective.
One can create an EmpiricalDistribution object

ed2D = EmpiricalDistribution[Transpose[{xValues, yValues}]]

and then calculate its mean with

Mean[ed2D]

{-0.227361, 1.88819}

Source Link
Karsten7
  • 27.6k
  • 5
  • 74
  • 135

With

xValues={-1.27,-3.65,-0.64,8.65,-1.52,-1.65,-3.9,-2.21,-0.07,-1.62,1.5,-2.71,3.37,-8.29,16.16,-31.27,3.07,2.97,9,-2.63,16.03,-24.49,-0.35,-13.36,-2.57,5.08,4.53,-4.47,0.34,1.66,2.32,0.23,-1.77,-0.86,5.46,-0.84,-1.6,1.54,-3.69,-5.87,-2.09,-10.86,-1.33,0.64,0.84,3.96,1.57,2.07,5.87,-2.09,-1.57,-3.65,1.67,-10.23,-1.94,-0.38,1.45,-0.85,1.87,-3.71,0.4,-2.26,-1.66,0.77,1.9,-0.56,7.53,31.38,0.23,0.06,-5.05,9.04}
yValues={2.18,1.14,1.37,2.18,2.16,1.27,2.2,1.78,1.81,0.86,1.32,1.67,1.63,1.55,1.57,2,2.14,1.45,1.7,2.09,2.11,2.09,2.06,2.08,1.79,1.95,1.93,2.03,2.11,1.04,2.12,2.19,1.32,1.88,2.15,2.1,2.16,1.97,1.47,2.02,1.4,1.65,2.15,1.57,2.14,2.12,2.14,2.15,2.06,1.98,2.18,2.14,1.67,1.82,1.71,2.18,2.15,1.93,2.01,1.75,2.11,1.86,2.16,2.11,1.91,2.2,1.79,2.16,2.08,1.82,2.07,2.14}

from your link.
One can create a WeightedData object using

wData = WeightedData[xValues, yValues]

and then calculate the mean with

Mean[wData]

-0.153426

and other statistics, like the standard deviation with

StandardDeviation[wData]

It is even possible to plot a PDF for the data

With[{dist = SmoothKernelDistribution[wData]}, 
 Plot[Evaluate[PDF[dist, \[FormalT]]], {\[FormalT], 
  Min[wData["InputData"]] - 2 dist["Bandwidth"], 
  Max[wData["InputData"]] + 2 dist["Bandwidth"]}, PlotRange -> All]]

PDF