Computes the location and dispersion statistics under flexible probabilities.

fp_moments(x, p = NULL)

# S3 method for default
fp_moments(x, p = NULL)

# S3 method for numeric
fp_moments(x, p = NULL)

# S3 method for matrix
fp_moments(x, p = NULL)

# S3 method for xts
fp_moments(x, p = NULL)

# S3 method for data.frame
fp_moments(x, p = NULL)

# S3 method for tbl
fp_moments(x, p = NULL)

Arguments

x

A tabular (non-tidy) data structure.

p

A probability vector.

Value

A list with 2 elements: mu and sigma.

Examples

x <- matrix(diff(log(EuStockMarkets)), ncol = 4)
colnames(x) <- colnames(EuStockMarkets)
p <- stats::runif(nrow(x))
p <- p / sum(p)

fp_moments(x = x, p = p)
#> $mu
#>              [,1]
#> DAX  0.0006751288
#> SMI  0.0008353638
#> CAC  0.0003655397
#> FTSE 0.0004503562
#> 
#> $sigma
#>               DAX          SMI          CAC         FTSE
#> DAX  9.822636e-05 6.085806e-05 7.530010e-05 4.830497e-05
#> SMI  6.085806e-05 8.056351e-05 5.796333e-05 4.046637e-05
#> CAC  7.530010e-05 5.796333e-05 1.150288e-04 5.413416e-05
#> FTSE 4.830497e-05 4.046637e-05 5.413416e-05 6.206972e-05
#> 

# compare with the standard approach
colMeans(x)
#>          DAX          SMI          CAC         FTSE 
#> 0.0006520417 0.0008178997 0.0004370540 0.0004319851 
cov(x)
#>               DAX          SMI          CAC         FTSE
#> DAX  1.061072e-04 6.699564e-05 8.345130e-05 5.241794e-05
#> SMI  6.699564e-05 8.556317e-05 6.285881e-05 4.304517e-05
#> CAC  8.345130e-05 6.285881e-05 1.216802e-04 5.693174e-05
#> FTSE 5.241794e-05 4.304517e-05 5.693174e-05 6.332543e-05