Hi,
I've got a similar problem, but I would like to estimate the random walk with drift through a linear combination-specification to obtain the posterior marginal. The reason for this is that later on I will add other latent factors, so I can't get the posterior marginal from the linear predictor.
Below I've attached some sample code that contains my current attempt. In this attempt, the posterior marginal for the random walk with drift is not what I expected, when compared with the marginal of the random walk itself. The marginal of the random walk jumps up and down, but the marginal of the linear combination contains straight lines. The jumps we observe in the marginal of the random walk mode I would expect to observe as well in the marginal of the linear combination. Can some point me to what I'm doing wrong?
Your help is kindly appreciated.
Regards,
Frank van Berkum
___________________________________________________________
require(INLA)
iN <- 100
x <- cumsum( rnorm( n=iN, mean= -1, sd=3) )
y <- x + rnorm( n=iN, mean=0, sd=3 )
# Indices
i.rw <- 1:iN # random walk part
i.dr <- 1:iN # drift part through linear effect
# Formula for random walk with drift
f.rwd <- y ~ f(i.dr, model="linear", mean.linear = 0, prec.linear=0.1) +
f(i.rw, model="rw1") - 1
# Define data frame
d.rwd <- data.frame(i.dr=i.dr, i.rw=i.rw, y=y)
# Linear combination(s) to combine rw and drift
lc.rwd <- inla.make.lincombs(i.dr=i.dr, i.rw=rep(1, iN))
# lc.rwd <- inla.make.lincombs(i.dr=i.dr, i.rw=i.rw)
# Estimate the model
r.rwd <- inla(f.rwd, data=d.rwd, lincomb=lc.rwd, control.inla=list(lincomb.derived.only=TRUE))
# Marginal of linear combination (supposedly random walk with drift)
rwd <- matrix(data=NA, nrow=iN, ncol=4)
rwd[,1] <- as.numeric(summary(r.rwd)$lincomb.derived[,"mean"])
rwd[,2] <- as.numeric(summary(r.rwd)$lincomb.derived[,"0.025quant"])
rwd[,3] <- as.numeric(summary(r.rwd)$lincomb.derived[,"0.975quant"])
rwd[,4] <- as.numeric(summary(r.rwd)$lincomb.derived[,"0.5quant"])
ylims.rwd <- c(min(rwd), max(rwd))
# Marginals of rw
rw <- matrix(data=NA, nrow=iN, ncol=4)
rw[,1] <- as.numeric(r.rwd$summary.random$i.rw[,"mean"])
rw[,2] <- as.numeric(r.rwd$summary.random$i.rw[,"0.025quant"])
rw[,3] <- as.numeric(r.rwd$summary.random$i.rw[,"0.975quant"])
rw[,4] <- as.numeric(r.rwd$summary.random$i.rw[,"0.5quant"])
ylims.rw <- c(min(rw), max(rw))
# Compare both marginals
par(mfrow=c(1,2))
plot(rwd[,1], ylim=ylims.rwd, type="l")
for(i in 2:4) lines(rwd[,i], lty=2)
plot(rw[,1], ylim=ylims.rw, type="l")
for(i in 2:4) lines(rw[,i], lty=2)______________________________________________________-
Op maandag 20 mei 2013 22:27:51 UTC+2 schreef ximing: