set.seed (1111)
n <- 200
p <- 5
X <- matrix (rnorm (n * p), ncol = p)
X[,2] <- X[,1] + rnorm (n, sd = 0.1)
X[,3] <- X[,1] + rnorm (n, sd = 0.1)
true.beta <- c (1, 2, 0, 0, -1)
y <- drop (X %*% true.beta) + rnorm (n)
cv.obj1 <- cv.lqa (y, X, intercept = TRUE, lambda.candidates =
list (c (0.001, 0.05, 1, 5, 10), c (0.1, 0.5, 1)), family = gaussian (),
penalty.family = fused.lasso, loss.func = "gcv.loss")
cv.obj1
beta0.hat <- coef (cv.obj1$best.obj)[1] # extracts the estimated intercept
pred.obj <- predict.lqa (cv.obj1$best.obj, new.x = c (beta0.hat, 1, 2, 3, 4, 5))
pred.obj
cv.obj2 <- cv.lqa (y, X, intercept = TRUE, lambda.candidates =
list (c (0.001, 0.05, 1, 5, 10), c (0.1, 0.5, 1)), family = gaussian (),
penalty.family = fused.lasso, n.fold = 5, loss.func = "squared.loss")
cv.obj2
beta0.hat <- coef (cv.obj2$best.obj)[1] # extracts the estimated intercept
predict.lqa (cv.obj2$best.obj, new.x = cbind (beta0.hat, matrix (1 : 10, nrow = 2)))
Run the code above in your browser using DataLab