Learn R Programming

zoocat (version 0.2.0.1)

rollcor: Calculate the rolling window correlations

Description

Calculate the rolling window correlations.

Usage

rollcor(x, y, ...)

# S3 method for default rollcor(x, y, width, show = TRUE, ...)

# S3 method for 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

Run this code
# NOT RUN {
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')

# }

Run the code above in your browser using DataLab