Created
April 20, 2016 11:44
-
-
Save slarge/219a408177cc912c2569d9f5bc6c2f4f to your computer and use it in GitHub Desktop.
Rolling window linear model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tt <- data.frame(YEAR = seq(1981, 2010, by = 1), | |
INDICATOR = rnorm(n = 30)) | |
library(zoo) | |
dolm <- function(x) { | |
SE <- summary(lm(INDICATOR ~ ., data = as.data.frame(x)))$sigma | |
SLOPE <- summary(lm(INDICATOR ~ ., data = as.data.frame(x)))$coefficients[1] | |
return(list(standard.error = SE, slope = SLOPE)) | |
} | |
rollapplyr(tt, width = 5, dolm, by.column = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment