Description Usage Arguments Examples
This function obtains Bayesian and Frequentist confidence bands for models fit with the ADMMl1 function
1 |
model |
output from l1ADMM with cv = FALSE |
alpha |
confidence level |
newData |
new dataset at which to get the predicted values and confidence intervals |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | library(psplinesl1)
data(simData)
# setup p-spline matrices
X <- list(ps(x = "x", data = simData,
norder = 2, k = 1, width = 0.05,
center = TRUE))
# setup random effect matrices
rand <- re(x = "x", id = "id", data = simData,
randomCurves = FALSE)
# run cross validation and view paths
cvOut <- cv(y = "y", id = "id", X = X, rand = rand,
K = 5,
pathLength = 20,
data = simData)
plot(cvOut)
# fit model with all data
a1 <- admm(y = "y", X, Z = rand$Z, S = rand$S,
tau = cvOut$smoothOpt[1],
lambda = cvOut$smoothOpt[2:(length(X)+1)],
rho = min(5, max(cvOut$smoothOpt)),
data = simData)
# get and plot fitted model with confidence bands
CI <- ci(model = a1, alpha = 0.05)
plot(CI)
# extract values from ci object for custom plotting
CIpoly <- data.frame(x = c(CI[[1]]$x, rev(CI[[1]]$x)),
y = c(CI[[1]]$lower,
rev(CI[[1]]$upper)))
ggplot(aes(x = x, y = y), data = newDat)+
geom_polygon(data = CIpoly, fill = "grey")+
geom_line(aes(x = CI[[1]]$x, y = CI[[1]]$smooth))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.