Last active
September 6, 2017 17:27
-
-
Save Gedevan-Aleksizde/1fb70932d63725b29490edfd54726ff3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# ------ common part ---- | |
require(ggplot2) | |
require(dplyr) | |
require(tidyr) | |
require(dlm) # 1.1-4 | |
require(KFAS) # 1.2.9 | |
require(bsts) # 0.7.1 | |
# calculate the reference price | |
calc_RP <- function(RP, p, a){ | |
for( i in 2:length(RP)){ | |
RP[i] <- a * RP[i-1] + (1-a) *p[i-1] | |
} | |
return(RP) | |
} | |
# calculate Z | |
calc_Z <- function(RP, p){ | |
z_1<-0 | |
z_2<-0 | |
v_wk<- p - RP | |
n <- length(RP) | |
for (i in 1:n){ | |
if (v_wk[i]>=0) { | |
z_1[i] <- v_wk[i]/100 | |
} else { | |
z_1[i] <- 0 | |
} | |
if (v_wk[i] < 0) { | |
z_2[i] <- -v_wk[i]/100 | |
} else { | |
z_2[i] <- 0 | |
} | |
} | |
return(list(z1=z_1, z2=z_2)) | |
} | |
# read the data | |
#ID_W:週ID | |
#end:エンド陳列の有無 | |
#logPI:点数PIの対数 | |
#AP:売価 | |
#RP095:参照価格(繰越パラメータ0.95:RP_t=0.95*RP_{t-1}+(1-0.95)*AP_{t-1}) | |
df <- read.csv("data/test.csv") | |
ggplot(gather(df, key=series, value=value, -ID_W)) + | |
geom_line(aes(x=ID_W, y=value, group=series), color="grey") + | |
facet_wrap(~series, scales = "free") + labs(x="week", y="") + | |
scale_color_discrete(guide=F) + expand_limits(y=0) + theme_bw() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment