Description Usage Arguments Value Examples
This is a faster version of base R function cov
. For
optimal speed, use integer = TRUE
if x
and y
are integer
vectors and integer = FALSE
otherwise. This function uses a one-pass
covariance calculation that makes it susceptible to precision issues if
x
values are very large.
1 |
x, y |
Integer or numeric vector. |
integer |
Logical value for whether |
Numeric value.
1 2 3 4 5 6 7 8 9 10 11 | # cov2 vs. cov for integer vector
x <- rpois(1000, lambda = 5)
y <- rpois(1000, lambda = 5)
all.equal(cov(x, y), cov2(x, y, integer = TRUE))
benchmark(cov(x, y), cov2(x, y, integer = TRUE), replications = 5000)
# cov2 vs. cov for numeric vector
x <- rnorm(1000)
y <- rnorm(1000)
all.equal(cov(x, y), cov2(x, y))
benchmark(cov(x, y), cov2(x, y), replications = 5000)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.