# NOT RUN {
##Calculation of confidence intervals for a TVLM model
##Generation of time-varying coefficients linear model
set.seed(42)
tau <- seq(1:200)/200
beta <- data.frame(beta1 = sin(2*pi*tau), beta2= 2*tau)
X1 <- rnorm(200)
X2 <- rchisq(200, df = 4)
error <- rt(200, df = 10)
y <- apply(cbind(X1, X2)*beta, 1, sum) + error
data <- data.frame(y = y, X1 = X1, X2 = X2)
##Fitting the model and confidence interval calculation
model.tvlm <- tvLM(y ~ 0 + X1 + X2, data = data, bw = 0.29)
tvci <- confint(model.tvlm, level = 0.95, runs = 20)
##If a second confidence interval on the "same" object is calculated,
##for example with a different level, the calculation is faster
tvci.80 <- confint(tvci, level = 0.8)
# }
Run the code above in your browser using DataLab