滚动的均值 window R2 是回归的总 R2 吗?
Is mean of rolling window R2 is the total R2 of regression?
这里是快速问题。
我必须计算 60 天滚动的平均值 window R2 时间序列。我的时间序列有 4680 个观察值。
我想知道,R2 的系列的平均值是回归的总 R2 吗?
示例:
均值(r2 系列)= 所有样本数据回归的 R2
试试吧。我们展示了在这种情况下定义 R 平方的两种等效方法:
library(zoo)
set.seed(123)
n <- 4680
w <- 60
x <- rnorm(4680)
r2 <- function(x) summary(lm(x ~ seq_along(x)))$r.squared
# r2 <- function(x) cor(x, seq_along(x))^2 # this is equivalent
mean(rollapplyr(x, w, r2))
## [1] 0.4992133
r2(x)
## [1] 0.0001151601
这里是快速问题。
我必须计算 60 天滚动的平均值 window R2 时间序列。我的时间序列有 4680 个观察值。
我想知道,R2 的系列的平均值是回归的总 R2 吗?
示例:
均值(r2 系列)= 所有样本数据回归的 R2
试试吧。我们展示了在这种情况下定义 R 平方的两种等效方法:
library(zoo)
set.seed(123)
n <- 4680
w <- 60
x <- rnorm(4680)
r2 <- function(x) summary(lm(x ~ seq_along(x)))$r.squared
# r2 <- function(x) cor(x, seq_along(x))^2 # this is equivalent
mean(rollapplyr(x, w, r2))
## [1] 0.4992133
r2(x)
## [1] 0.0001151601