Description Usage Arguments Value Note Examples
View source: R/symbolicMoments.R
Compute the moments of a multivariate variable X = X[1], ..., X[n] and return the formula as quoted expression.
1 2  symbolicMoments(distribution, missingOrders, mean = NA, cov = NA,
var = NA, simplify = TRUE)

distribution 
string specifying the (multivariate) distribution of X. The following values are possible:

missingOrders 
numeric vector or matrix. Each row gives the order of a moment that shall be calculated. 
mean 
vector or list with expected values. Entry 
cov 
matrix or nested list. Entry 
var 
optional. If 
simplify 
bool indiciating if the resulting expressions should be simplified.
Function 
A list where each element is a quoted expression.
The ith element of this list gives a formula for the
moment whose order is given in the ith row of missingOrders
.
If simplify = TRUE
, the returned value may as well be a vector or number.
The calculation of the central moments of a multivariate normal distribution
is based on function callmultmoments
of package symmoments.
If the calculation for a multivariate gamma distribution leads to NaNs,
then the values of cov and mean do not fit to a gamma distribution.
All entries of cov should be positive and the diagonals should be large
with respect to the other entries. More specifically, the inequations
mean[i] > sum_(k != i) mean[k]*cov[i,k]/cov[i,i]
should be satisfied for all i in 1:n.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  # raw moments of a one dimensional gamma distribution
symbolicMoments(distribution = "gamma", missingOrders = as.matrix(1:3, ncol = 1),
mean = "μ", var = "σ")
# raw moments of a one dimensional lognormal distribution
symbolicMoments(distribution = "lognormal", missingOrders = as.matrix(1:2, ncol = 1),
mean = 2, var = 1, simplify = FALSE)
# evaluate the result
symbolicMoments(distribution = "lognormal", missingOrders = as.matrix(1:2, ncol = 1),
mean = 2, var = 1, simplify = TRUE)
#### central moments of a four dimensional normal distribution ####
missingOrders < matrix(c(4, 0, 0, 0,
3, 1, 0, 0,
2, 2, 0, 0,
2, 1, 1, 0,
1, 1, 1, 1), ncol = 4, byrow = TRUE)
cov < matrix(c("σ11", "σ12", "σ13", "σ14",
"σ12", "σ22", "σ23", "σ24",
"σ13", "σ23", "σ33", "σ34",
"σ14", "σ24", "σ34", "σ44"), ncol = 4, byrow = TRUE)
symbolicMoments("normal", missingOrders, mean = "μ", cov = cov)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.