rollcor: Calculate the rolling window correlations

Description Usage Arguments Value Examples

View source: R/rollcor.R

Description

Calculate the rolling window correlations.

Usage

1
2
3
4
5
6
7
rollcor(x, y, ...)

## Default S3 method:
rollcor(x, y, width, show = TRUE, ...)

## S3 method for class 'zoo'
rollcor(x, y, width, show = TRUE, ...)

Arguments

x, y

Two vectors or two zoo objects. For zoo objects, if their time ranges is different, intersection will be used.

...

Other arguments for function cor.

width

The width of the sliding window, which must be odd number.

show

If TRUE, the result will be plotted.

Value

rollcor.default return a vector, and rollcor.zoo return a "zoo" object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
x <- 1 : 100
y <- 2 * x + rnorm(100, 0, 10)
rollcor(x, y, width = 21)

xz <- zoo(x)
yz <- zoo(y)
rollcor(xz, yz, width = 21)

rollcor(xz, yz, width = 21, show = FALSE)

x <- 1 : 100
y <- 2 * x  + rnorm(100, 0, 10)
x <- zoo(x, order.by = 10 : 109)
y <- zoo(y, order.by = -3 : 96)
rollcor(x, y, width = 21, method = 'kendall')

ran-ran/zoocat documentation built on July 5, 2017, 8:41 p.m.