if (FALSE) ## Generate some data.
d <- GAMart()
## Model formula.
f <- list(
num ~ s(x1) + s(x2) + s(x3) + te(lon,lat),
sigma ~ s(x1) + s(x2) + s(x3) + te(lon,lat)
)
## Estimate model.
b <- bamlss(f, data = d)
## Predictions.
p <- predict(b)
str(b)
## Prediction for "mu" model and term "s(x2)".
p <- predict(b, model = "mu", term = "s(x2)")
## Plot effect
plot2d(p ~ x2, data = d)
## Same for "sigma" model.
p <- predict(b, model = "sigma", term = "s(x2)")
plot2d(p ~ x2, data = d)
## Prediction for "mu" model and term "s(x1)" + "s(x2)"
## without intercept.
p <- predict(b, model = "mu", term = c("s(x1)", "s(x2)"),
intercept = FALSE)
## Prediction based on quantiles.
p <- predict(b, model = "mu", term = "s(x2)", FUN = c95)
plot2d(p ~ x2, data = d)
## Extract samples of predictor for "s(x2)".
p <- predict(b, model = "mu", term = "s(x2)",
intercept = FALSE, FUN = function(x) { x })
print(dim(p))
plot2d(p ~ x2, data = d, col.lines = rgb(0.1, 0.1, 0.1, alpha = 0.1))
## Or using specific combinations of terms.
p <- predict(b, model = "mu", term = c("s(x2)", "te(lon,lat)"),
intercept = FALSE, FUN = function(x) { x })
head(p)
## Prediction using new data.
## Only need x3 data when predicting
## for s(x3).
nd <- data.frame("x3" = seq(0, 1, length = 100))
nd <- cbind(nd, predict(b, newdata = nd, term = "s(x3)"))
print(head(nd))
plot2d(mu ~ x3, data = nd)
plot2d(sigma ~ x3, data = nd)
Run the code above in your browser using DataLab