【发布时间】:2021-04-30 11:51:03
【问题描述】:
在这里快速提问。
我必须计算 60 天滚动窗口 R2 时间序列的平均值。我的时间序列有 4680 个观测值。
我想知道,R2 系列的平均值是回归的总 R2 吗?
例子:
Mean(series of r2) = 所有样本数据回归的 R2
【问题讨论】:
标签: python r statistics regression data-science
在这里快速提问。
我必须计算 60 天滚动窗口 R2 时间序列的平均值。我的时间序列有 4680 个观测值。
我想知道,R2 系列的平均值是回归的总 R2 吗?
例子:
Mean(series of r2) = 所有样本数据回归的 R2
【问题讨论】:
标签: python r statistics regression data-science
试试吧。我们展示了在这种情况下定义 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
【讨论】: