WeightedData[{x1,x2,…},{w1,w2,…}]
represents observations xi with weights wi.
WeightedData[{x1,x2,…},fn]
represents observations xi with weighting function fn.
WeightedData
WeightedData[{x1,x2,…},{w1,w2,…}]
represents observations xi with weights wi.
WeightedData[{x1,x2,…},fn]
represents observations xi with weighting function fn.
Details
- WeightedData augments data with weights for each data point.
- The data {x1,x2,…} and weights {w1,w2,…} should be lists of equal length.
- The weight function fn is applied to the list {x1,x2,…} and should return an explicit list of weights {w1,w2,…}.
- WeightedData can be used in statistics functions including:
-
Mean,Variance,… descriptive statistics functions EmpiricalDistribution,… nonparametric distribution estimation EstimatedDistribution,… parametric distribution estimation - WeightedData[{x1,x2,…}] gives data with equal weights.
- Properties of WeightedData can be obtained by specifying WeightedData[…]["property"].
- A list of available properties can be obtained using WeightedData[…]["Properties"].
- WeightedData has the following properties:
-
"EmpiricalPDF" data values and estimated weights "InputData" unweighted input data values "MetaInformation" a list containing meta-information rules "Weights" a list containing the data weights
Examples
open all close allBasic Examples (1)
data = {8, 3, 5, 4, 9, 0, 4, 2, 2, 3};
w = {0.15, 0.09, 0.12, 0.10, 0.16, 0., 0.11, 0.08, 0.08, 0.09};𝒜 = WeightedData[data, w]Compute a weighted Mean and StandardDeviation:
Mean[𝒜]StandardDeviation[𝒜]Scope (10)
Create weighted univariate data:
data = {8, 3, 5, 4, 9, 0, 4, 2, 2, 3};
w = {0.15, 0.09, 0.12, 0.10, 0.16, 0., 0.11, 0.08, 0.08, 0.09};𝒜 = WeightedData[data, w];Some weighted descriptive statistics:
Table[{i, i[𝒜]}, {i, {Mean, Median, Variance, StandardDeviation, Kurtosis, Skewness, InterquartileRange}}]//GridAdd weights to a set of multivariate values:
x = {{1, 2}, {4, 5}, {5, 6}, {7, 3}};
w = {.5, .25, .1, 1};𝒜 = WeightedData[x, w]A set of weighted multivariate descriptive statistics:
Mean[𝒜]Covariance[𝒜]Correlation[𝒜]Use a pure function to create weighted data values:
x = RandomInteger[{1, 25}, 5000];𝒜 = Table[WeightedData[x, Function@@{t, t^i}], {i, Range[0, 4]}];N[Mean /@ 𝒜]N[Variance /@ 𝒜]Visualize the impact of the various weighting schemes:
Plot[Evaluate@Table[PDF[SmoothKernelDistribution[w], a], {w, 𝒜}], {a, -3, 30}, PlotRange -> All, PlotLegends -> Map[Row[{"t --> ", #}]&, t ^ Range[0, 4]]]Fit nonparametric distributions to weighted data:
data = RandomVariate[NormalDistribution[0, 1], 50];
w = data ^ 2;𝒜 = WeightedData[data, w]dists = Table[𝒟[𝒜], {𝒟, {EmpiricalDistribution, HistogramDistribution, SmoothKernelDistribution}}];Table[Plot[CDF[i, x], {x, -3, 3}, PlotLabel -> Row[{"Mean: ", Mean[i]}], Exclusions -> None], {i, dists}]Fit parametric distributions to weighted data:
data = RandomReal[{0, 100}, 1000];
w = PDF[ExponentialDistribution[1 / 20], #]&;𝒜 = WeightedData[data, w]𝒟1 = EstimatedDistribution[𝒜, ExponentialDistribution[a]]Compare the estimated and empirical distributions:
𝒟2 = EmpiricalDistribution[𝒜];Plot[{CDF[𝒟1, x], CDF[𝒟2, x]}, {x, 0, 50}, Exclusions -> None, PlotStyle -> {Thick, Automatic}, PlotLegends -> {"𝒟1", "𝒟2"}]Extract the input data from a WeightedData object:
𝒜 = WeightedData[Automatic, {{4.3424867371049345, 84.95915906432668, 54.62083275189872,
60.351715598529864, 74.13571604649297, 60.94262726482822, 66.51118636065769, 64.48764263803247,
71.21344855673459, 82.3471338515244, 99.98746459746363, 17.1 ... 584268284, 0.004700837378501972,
0.008097966826215594, 0.0027249292830005016, 0.029142913216900736, 0.005685347349364164,
0.02694522380487357, 0.013049595682933283, 0.0005752644284236291, 0.0013256312483065082,
0.0004190555990108067}}];d = 𝒜["InputData"];Compare the distributions of the unweighted and weighted data:
𝒟1 = HistogramDistribution[d];𝒟2 = HistogramDistribution[𝒜];Table[Plot[PDF[𝒟, x], {x, 0, 100}, Filling -> Axis, Exclusions -> None, PlotRange -> {0, .04}], {𝒟, {𝒟1, 𝒟2}}]Obtain the weights from a WeightedData object:
𝒜 = WeightedData[Automatic, {{4.3424867371049345, 84.95915906432668, 54.62083275189872,
60.351715598529864, 74.13571604649297, 60.94262726482822, 66.51118636065769, 64.48764263803247,
71.21344855673459, 82.3471338515244, 99.98746459746363, 17.1 ... 584268284, 0.004700837378501972,
0.008097966826215594, 0.0027249292830005016, 0.029142913216900736, 0.005685347349364164,
0.02694522380487357, 0.013049595682933283, 0.0005752644284236291, 0.0013256312483065082,
0.0004190555990108067}}];w = 𝒜["Weights"];Visually inspect the effect of the weights on the data values:
ListLinePlot[Sort@Transpose[{𝒜["InputData"], w}]]Compute a weighted mean from the empirical PDF:
𝒜 = WeightedData[Automatic, {{4.3424867371049345, 84.95915906432668, 54.62083275189872,
60.351715598529864, 74.13571604649297, 60.94262726482822, 66.51118636065769, 64.48764263803247,
71.21344855673459, 82.3471338515244, 99.98746459746363, 17.1 ... 584268284, 0.004700837378501972,
0.008097966826215594, 0.0027249292830005016, 0.029142913216900736, 0.005685347349364164,
0.02694522380487357, 0.013049595682933283, 0.0005752644284236291, 0.0013256312483065082,
0.0004190555990108067}}];{d, pdf} = 𝒜["EmpiricalPDF"];d.pdfThe weighted mean can be computed directly using Mean:
Mean[𝒜]Find the weighted average of an irregularly sampled TimeSeries:
ts = TimeSeries[Table[{t, 2t + RandomVariate[NormalDistribution[0, 0.3]]}, {t, {0., 0.15, 0.2, 0.5, 0.75, 1., 1.5, 2}}]]wm = Mean[WeightedData[ts]]Compare with the average of values:
vm = Mean[ts]ListLinePlot[ts, Frame -> True, PlotMarkers -> {Automatic, Tiny},
GridLines -> {None, {{vm, Dashed}, {wm, Dotted}}},
FrameTicks -> {{Automatic, {{vm, " value mean"}, {wm, " weighted mean"}}}, {Automatic, Automatic}}]Create weighted data involving quantities:
data = Quantity[{7, 3, 5, 4, 9, 0, 4, 2, 2, 3}, "Meters"];
w = {0.12, 0.09, 0.12, 0.10, 0.16, 0., 0.11, 0.08, 0.08, 0.09};𝒜 = WeightedData[data, w];Some weighted descriptive statistics:
Table[{i, i[𝒜]}, {i, {Mean, Median, Variance, StandardDeviation, Kurtosis, Skewness, InterquartileRange}}]//TableFormApplications (2)
data = RandomReal[{-5, 5}, 10 ^ 4];𝒜 = WeightedData[data, PDF[NormalDistribution[], #]&];𝒟 = HistogramDistribution[𝒜, 50];m = Mean[𝒜];
sd = StandardDeviation[𝒜];
Plot[PDF[𝒟, x], {x, -4, 4}, Exclusions -> None, Filling -> Axis, Epilog -> Inset[TableForm[{{"Mean:", m}, {"SD:", sd}}], {Right, Top}, {Right, Top}]]Estimate confidence interval for maximum likelihood estimates of distribution parameters:
BlockRandom[SeedRandom[40];
data = RandomVariate[WeibullDistribution[2.3, 0.8], 30]];mleP = {α, β} /. FindDistributionParameters[data, WeibullDistribution[α, β]]Apply fractional random weight bootstrap to estimate confidence interval, by repeating weighted estimation with weights sampled from a DirichletDistribution with unit parameters:
weightSample[n_Integer] := RandomVariate[DirichletDistribution[ConstantArray[1, n + 1]]]frwData[data_] := WeightedData[data, weightSample[Length[data]]]Generate one thousand estimates of the distribution parameters:
frwPs = Table[{α, β} /. FindDistributionParameters[frwData[data], WeibullDistribution[α, β]], 1000];Visualize bootstrap estimates:
ListPlot[frwPs, Epilog -> {Directive[PointSize[Large], Orange], Point[mleP]}]Fit joint Gaussian distribution to the bootstrapped parameters:
EstimatedDistribution[frwPs, BinormalDistribution[{αμ, βm}, {αv, βv}, ρ]]Properties & Relations (3)
WeightedData with equal weights:
data = {8, 3, 5, 4, 9, 0, 4, 2, 2, 3};
wd = WeightedData[data]The underlying empirical distributions are the same:
EmpiricalDistribution[data] === EmpiricalDistribution[wd]Descriptive statistics are based on the underlying EmpiricalDistribution:
𝒜 = WeightedData[{{-30, -30}, {10, 10}, {20, 20}}, {1, 7, 2}];𝒟 = EmpiricalDistribution[𝒜];{Mean[𝒜], Mean[𝒟]}Sample estimates are given when they differ from population estimates:
{Variance[𝒜], Variance[𝒟]}WeightedData works for TimeSeries objects:
ts = TimeSeries[vals = {x1, x2, x3, x4}, {times = {0, 1 / 3, 1 / 2, 1}}];
wm = Mean[WeightedData[ts]]For
, the weights are proportional to
:
weights = MovingAverage[ArrayPad[Differences[times], {1, 1}, "Fixed"], 2]Normalize[weights, Total].valsCompare with bin‐sampled time average:
evals = ArrayPad[vals, {1, 1}, "Fixed"]etimes = ArrayPad[times, {1, 1}, "ReflectedDifferences"]if = Interpolation[Transpose[{etimes, evals}], InterpolationOrder -> 1];{tmin, tmax} = {Mean[Take[etimes, 2]], Mean[Take[etimes, -2]]}(1/tmax - tmin)Integrate[if[t], {t, tmin, tmax}]//ExpandRelated Guides
History
Text
Wolfram Research (2012), WeightedData, Wolfram Language function, https://reference.wolfram.com/language/ref/WeightedData.html.
CMS
Wolfram Language. 2012. "WeightedData." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/WeightedData.html.
APA
Wolfram Language. (2012). WeightedData. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/WeightedData.html
BibTeX
@misc{reference.wolfram_2026_weighteddata, author="Wolfram Research", title="{WeightedData}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/WeightedData.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_weighteddata, organization={Wolfram Research}, title={WeightedData}, year={2012}, url={https://reference.wolfram.com/language/ref/WeightedData.html}, note=[Accessed: 13-June-2026]}