# NOT RUN {
## Simulate data.
set.seed(123)
n <- 300
x <- runif(n, -3, 3)
fsigma <- -2 + cos(x)
y <- sin(x) + rnorm(n, sd = exp(fsigma))
## Setup model formula.
f <- list(
y ~ x,
sigma ~ x
)
## Fit neural network.
library("keras")
b <- dl.bamlss(f)
## Plot estimated functions.
par(mfrow = c(1, 2))
plot(x, y)
plot2d(fitted(b)$mu ~ x, add = TRUE)
plot2d(fitted(b)$sigma ~ x,
ylim = range(c(fitted(b)$sigma, fsigma)))
plot2d(fsigma ~ x, add = TRUE, col.lines = "red")
## Another example identifying structures that are
## not captured by the initial model.
set.seed(123)
d <- GAMart()
b1 <- bamlss(num ~ s(x1) + s(x2) + s(x3), data = d, sampler = FALSE)
b2 <- dl.bamlss(num ~ lon + lat, data = d, offset = fitted(b1))
p <- predict(b2, model = "mu")
par(mfrow = c(1, 1))
plot3d(p ~ lon + lat, data = d, symmetric = FALSE)
# }
Run the code above in your browser using DataLab