## Generate some data.
set.seed(111)
n <- 500
## Regressor.
d <- data.frame(x = runif(n, -3, 3))
## Response.
d$y <- with(d, 10 + sin(x) + rnorm(n, sd = 0.6))
## Not run: ------------------------------------
# ## Estimate model.
# b <- bamlss(y ~ s(x), data = d)
# summary(b)
#
# ## Plot estimated effect.
# plot(b)
# plot(b, rug = FALSE)
#
# ## Extract fitted values.
# f <- fitted(b, model = "mu", term = "s(x)")
# f <- cbind(d["x"], f)
#
# ## Now use plot2d.
# plot2d(f)
# plot2d(f, fill.select = c(0, 1, 0, 1))
# plot2d(f, fill.select = c(0, 1, 0, 1), lty = c(2, 1, 2))
# plot2d(f, fill.select = c(0, 1, 0, 1), lty = c(2, 1, 2),
# scheme = 2)
#
# ## Variations.
# plot2d(sin(x) ~ x, data = d)
# d$f <- with(d, sin(d$x))
# plot2d(f ~ x, data = d)
# d$f1 <- with(d, f + 0.1)
# d$f2 <- with(d, f - 0.1)
# plot2d(f1 + f2 ~ x, data = d)
# plot2d(f1 + f2 ~ x, data = d, fill.select = c(0, 1, 1), lty = 0)
# plot2d(f1 + f2 ~ x, data = d, fill.select = c(0, 1, 1), lty = 0,
# density = 20, poly.lty = 1, poly.lwd = 2)
# plot2d(f1 + f + f2 ~ x, data = d, fill.select = c(0, 1, 0, 1),
# lty = c(0, 1, 0), density = 20, poly.lty = 1, poly.lwd = 2)
## ---------------------------------------------
Run the code above in your browser using DataCamp Workspace