expectation_data: Function used for computing expectations given data (e.g.,...

View source: R/utils.R

expectation_dataR Documentation

Function used for computing expectations given data (e.g., from an MC simulation or bootstrap). it expects a matrix, or something that can be coerced to a matrix (e.g., a data frame). it also expects a function g to apply to each row of the data, and returns the expectation of g under the empirical distribution of the data. it also returns a confidence interval for the expectation, and the number of samples used to compute the expectation.

Description

example: expectation_data(D, function(x) (x-colMeans(D)) %*% t(x-colMeans(D))) computes the covariance of the data D, except the matrix structure is lost (it's just a vector, which can be coerced back to a matrix if needed).

Usage

expectation_data(
  data,
  g = function(x) x,
  ...,
  compute_stats = TRUE,
  alpha = 0.05
)

Arguments

data

a matrix of data

g

a function to apply to each row of the data

...

additional arguments to pass to g

compute_stats

whether to compute CIs for the expectations

alpha

the confidence level for the confidence interval for each component of the expectation (if compute_stats is TRUE)

Value

if compute_stats is TRUE, then a list with the following components: value - The estimate of the expectation ci - The confidence intervals for each component of the expectation n - The number of samples otherwise, just the value of the expectation.


queelius/algebraic.dist documentation built on Jan. 27, 2025, 8:46 a.m.