linking | R Documentation |
Function link()
links a new index series (x.new
) to an existing one (x
) using the overlap periods in t.overlap
. In the resulting linked index series, the new index series starts after the existing one.
Function lsf()
computes the level-shift factors for linking via the overlap periods in t.overlap
in comparison to the one-month overlap method using December of year t-1
. The level-shift factors can then be used to shift the index level of a HICP index series.
link(x, x.new, t, t.overlap=NULL, settings=list())
lsf(x, x.new, t, t.overlap=NULL, settings=list())
x , x.new |
numeric vector of index values. |
t |
date vector in format |
t.overlap |
character specifying the overlap period either in format |
settings |
list of control settings to be used. The following settings are supported:
|
Function link()
returns a numeric vector or a matrix of the same length as t
, while lsf()
provides a named numeric vector of the same length as t.overlap
.
Sebastian Weinand
chain
# input data:
set.seed(1)
t <- seq.Date(from=as.Date("2015-01-01"), to=as.Date("2024-05-01"), by="1 month")
x.new <- rnorm(n=length(t), mean=100, sd=5)
x.new <- rebase(x=x.new, t=t, t.ref="2019-12")
x.old <- x.new + rnorm(n=length(x.new), sd=5)
x.old <- rebase(x=x.old, t=t, t.ref="2015")
x.old[t>as.Date("2021-12-01")] <- NA # current index discontinues in 2021
x.new[t<as.Date("2020-01-01")] <- NA # new index starts in 2019-12
# linking in new index in different periods:
matplot(x=t,
y=link(x=x.old, x.new=x.new, t=t, t.overlap=c("2021-12","2020","2021")),
col=c("red","blue","green"), type="l", lty=1,
xlab=NA, ylab="Index", ylim=c(80,120))
lines(x=t, y=x.old, col="black")
abline(v=as.Date("2021-12-01"), lty="dashed")
legend(x="topleft",
legend=c("One-month overlap using December 2021",
"Annual overlap using 2021",
"Annual overlap using 2020"),
fill=c("red","green","blue"), bty = "n")
# compute level-shift factors:
lsf(x=x.old, x.new=x.new, t=t, t.overlap=c("2020","2021"))
# level-shift factors can be applied to already chain-linked index series
# to obtain linked series using another overlap period:
x.new.chained <- link(x=x.old, x.new=x.new, t=t, t.overlap="2021-12")
# level-shift adjustment:
x.new.adj <- ifelse(test=t>as.Date("2021-12-01"),
yes=x.new.chained*lsf(x=x.old, x.new=x.new, t=t, t.overlap="2020"),
no=x.new.chained)
# compare:
all.equal(x.new.adj, link(x=x.old, x.new=x.new, t=t, t.overlap="2020"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.