« View all new features in
Mathematica
9
◄
previous
|
next
►
New in
Mathematica
9
›
Enhanced Probability & Statistics
Fit Nonparametric and Parametric Distributions to Weighted Data
Generate random reals from
to
and weight them according to the
PDF
of a
NormalDistribution
using
WeightedData
.
In[1]:=
X
data = RandomReal[{-5, 5}, 10^4]; wts = PDF[NormalDistribution[], data];
Create a
WeightedData
object and compute its mean and variance.
In[2]:=
X
\[ScriptCapitalW] = WeightedData[data, wts]; {Mean[\[ScriptCapitalW]], Variance[\[ScriptCapitalW]]}
Out[2]=
Fit to a
NormalDistribution
using maximum likelihood estimation.
In[3]:=
X
\[ScriptCapitalD] = EstimatedDistribution[\[ScriptCapitalW], NormalDistribution[\[Mu], \[Sigma]]]; {Mean[\[ScriptCapitalD]], Variance[\[ScriptCapitalD]]}
Out[3]=
Use
HistogramDistribution
to create a weighted histogram.
In[4]:=
X
\[ScriptCapitalD]NP = HistogramDistribution[\[ScriptCapitalW]]; {Mean[\[ScriptCapitalD]], Variance[\[ScriptCapitalD]]}
Out[4]=