cov_n: Sample Covariance for Numeric Vectors

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/functions.R

Description

Written in C++, this function should always run faster than cov for numeric vectors. For integer vectors, cov_i should run even faster.

Usage

1
cov_n(x, y)

Arguments

x

Numeric vector.

y

Numeric vector.

Details

NA

Value

Numeric value.

Note

NA

Author(s)

Dane R. Van Domelen

References

Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.

See Also

NA

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# In general, cov_n is much faster than cov
x <- rnorm(1000)
y <- rnorm(1000)
all.equal(cov(x, y), cov_n(x, y))
microbenchmark(cov(x, y),
               cov_n(x, y),
               times = 100)

# For integer vectors, cov_i should be even faster.
x <- rpois(1000, lambda = 5)
y <- rpois(1000, lambda = 5)
all.equal(cov(x, y), cov_i(x, y))
microbenchmark(cov(x, y),
               cov_n(x, y),
               cov_i(x, y),
               times = 100)

dvmisc documentation built on Dec. 29, 2017, 3:01 a.m.