Description Usage Arguments Details Value Author(s) See Also Examples
Calcuate the maximum likelihood estimators of covariance and standard deviation.
1 2 |
x |
a numeric vector, matrix, or data frame. |
mean |
the mean, or vector of means, with respect to which covariance should be calculated. |
simplify |
logical; if |
The standard R functions cov
, var
, and sd
return unbiased estimators of (co)variance and standard deviation, which are not equal to the maximum likelihood estimator (MLE). The functions given here return MLEs instead. For example, if x
is a vector consisting of elements x_1, …, x_N with mean mu, then the MLE of the variance is
sigmasq.hat = (1/N) sum_n (x_n - mu)^2
while the unbiased estimator is
sigmasq.hat = {1/(N-1)} sum_n (x_n - mu)^2.
mleVar
is an alias for mleCov
.
For mleCov
, the estimated variance if x
is a vector, or the esitmated covariance matrix of the columns of x
if x
is a matrix or data frame. If simplify
is FALSE
, then a matrix will always be returned even if x
is a vector.
For mleSd
, the estimated standard deviation if x
is a vector, or the vector of estimated column standard deviations if x
is a matrix or a data frame.
Daniel Dvorkin
thetahat.norm
, thetahat.mvnorm
for weighted parameter estimation; cov
, var
, sd
in package stats
.
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 27 | set.seed(123)
x <- rnorm(10)
mleCov(x)
# [1] 0.8187336
var(x)
# [1] 0.909704
mleSd(x)
# [1] 0.904839
sd(x)
# [1] 0.953784
x <- matrix(rnorm(30), ncol=3)
mleCov(x)
# [,1] [,2] [,3]
# [1,] 0.9698367 -0.4933797 0.1336627
# [2,] -0.4933797 0.7797652 -0.1931557
# [3,] 0.1336627 -0.1931557 0.2502430
cov(x)
# [,1] [,2] [,3]
# [1,] 1.0775964 -0.5481997 0.1485141
# [2,] -0.5481997 0.8664058 -0.2146175
# [3,] 0.1485141 -0.2146175 0.2780478
mleSd(x)
# [1] 0.9848029 0.8830432 0.5002430
apply(x, 2, sd) # sd(x) is deprecated
# [1] 1.0380734 0.9308092 0.5273024
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.