Learn R Programming

madness (version 0.1.0)

twomoments: Estimate the mean and covariance of values.

Description

Given rows of observations of some vector (or multidimensional data), estimates the mean and covariance of the values, returning two madness objects. These have a common covariance and 'xtag', so can be combined together.

Usage

twomoments(X, vcov.func=vcov, xtag=NULL, df=NULL)

Arguments

X
a multidimensional array (or a data frame) of observed values.
vcov.func
a function which takes an object of class lm, and computes a variance-covariance matrix. If equal to the string "normal", we assume multivariate normal returns.
xtag
an optional string tag giving the name of the input data. defaults to figuring it out from the input expression.
df
the number of degrees of freedom to subtract from the sample size in the denominator of the covariance matrix estimate. The default value is the number of elements in the mean, the so-called Bessel's correction.

Value

  • A two element list. The first is the 'mu', representing the mean, a madness object, the second is 'Sigma', representing the covariance, also a madness object.

Details

Given a $n\times k_1 \times k_2 \times ... \times k_l$ array whose 'rows' are independent observations of $X$, computes the $k_1 \times k_2 \times ... \times k_l$ array of the mean of $X$ and the $k_1 \times k_2 \times ... \times k_l \times k_1 \times k_2 ... k_l$ array of the covariance, based on $n$ observations, returned as two madness objects. The variance-covariance of each is estimated. The two objects have the same 'xtag', and so may be combined together.

One may use the default method for computing covariance, via the vcov function, or via a 'fancy' estimator, like sandwich:vcovHAC, sandwich:vcovHC, etc.

See Also

theta

Examples

Run this code
set.seed(123)
X <- matrix(rnorm(1000*8),ncol=8)
alst <- twomoments(X)
markowitz <- solve(alst$Sigma,alst$mu)
vcov(markowitz)

Run the code above in your browser using DataLab