weightedStats: Computes mean and variance for weighted reference measures

View source: R/integration.R

weightedStatsR Documentation

Computes mean and variance for weighted reference measures

Description

The function computes the expectation and variance of 'X' for the probability distribution given by the density f with respect to the measure. The method supports lists even if the individual measure does not.

Usage

weightedStats(
  measure,
  X,
  f,
  method = c("default", "sample", "MonteCarlo", "integration"),
  tol = 0.01
)

## S3 method for class 'ReferenceMeasure'
weightedStats(
  measure,
  X,
  f,
  method = c("default", "sample", "MonteCarlo", "integration"),
  ...
)

## S3 method for class 'ReferenceMeasureDiscrete'
weightedStats(measure, X, f, method, tol)

Arguments

measure

should be a reference measure. Other classes can implement the method.

X

a function (or list of functions) providing the statistics

f

a function providing the density with respect to X

method

a method to be selected. Typical methods are "sample", "MonteCarlo" and "integrate", but only sample is availabel for all reference measures. "sample" uses the prestored sample, "MonteCarlo" uses the simulated function of the reference measure, and "integrate" uses numerical integration. Typically the prestored integration sample performs well with derivatives measures derived ReferenceMeasureUniform, ReferenceMeasusureTransformed, where it proves a dense grid in the area of measure, and ReferenceMeasure discrete where it uses precise computation using a weighted sample. For Cartesian products involving more than one continues measure due to the curse of dimensionality typically only MonteCarlo is expected to work reasonably well.

tol

the absolute or relative tolerance (whichever is larger). accepted for methods with tolerance control.

...

further arguments to integration methods e.g. tol.

Details

The default method for reference measures used [getSample] and Monte Carlo integration with respect to this sample to perform the computation. More advanced methods e.g. using numerical integration might be implemented for certain subclasses.

Value

a list with the elements E for the computed expectation and V for the computed variance.

Methods (by class)

  • weightedStats(ReferenceMeasure): method for ReferenceMeasure

  • weightedStats(ReferenceMeasureDiscrete): method for ReferenceMeasureDiscrete exact computation based on X and w of the measure.

See Also

[getSample]

Examples

weightedStats(ReferenceMeasureUniform(0,1),function(x) x, function(x) x^2)
weightedStats(ReferenceMeasureUniform(0,1),as.function(B2Unif01Basis5), function(x) x^2)

DistributionalDDA documentation built on Oct. 20, 2026, 5:06 p.m.