Created
September 5, 2017 14:26
-
-
Save Gedevan-Aleksizde/b1637eebee64b17ec255bfcacc8062f1 to your computer and use it in GitHub Desktop.
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
source("common.R", encoding = "utf-8") | |
df$RP <- calc_RP(df$RP095, df$AP, .95) | |
z <- calc_Z(RP = df$RP, p = df$AP) | |
df <- mutate(df, z1=z$z1, z2=z$z2) | |
df <- mutate(df, z1E=z1*end, z2E=z2*end) | |
ss <- AddLocalLevel(list(), y = df$logPI) # c | |
ss <- AddAr(ss, lags=2, y = df$logPI) # AR(2) | |
# time-varying regression | |
ss <- AddDynamicRegression(ss, formula = logPI ~ z1 + z1E + z2 + z2E, data=df) | |
# calculate | |
model <- bsts(formula=df$logPI, | |
state.specification = ss, | |
niter = 500, seed=42) | |
plot(model) # it returns error if observed data contains NA value because `ylim` is specified incorrectly. | |
plot(model, "residuals") | |
plot(model, "prediction.errors") | |
plot(model, "components") | |
plot(model, "dynamic") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment