deeptrafo {deeptrafo} | R Documentation |
Deep Conditional Transformation Models
Description
Deep Conditional Transformation Models
Usage
deeptrafo(
formula,
data,
response_type = get_response_type(data[[all.vars(fml)[1]]]),
order = get_order(response_type, data[[all.vars(fml)[1]]]),
addconst_interaction = 0,
latent_distr = "logistic",
loss = "nll",
loss_args = NULL,
monitor_metrics = NULL,
trafo_options = trafo_control(order_bsp = order, response_type = response_type),
return_data = FALSE,
engine = "tf",
...
)
Arguments
formula |
Formula specifying the response, interaction, shift terms
as |
data |
Named |
response_type |
Character; type of response. One of |
order |
Integer; order of the response basis. Default 10 for Bernstein basis or number of levels minus one for ordinal responses. |
addconst_interaction |
Positive constant;
a constant added to the additive predictor of the interaction term.
If |
latent_distr |
A |
loss |
Character; specifies the loss function used. The default is
|
loss_args |
Further additional arguments to |
monitor_metrics |
See |
trafo_options |
Options for transformation models such as the basis
function used, see |
return_data |
Include full data in the returned object. Defaults to
|
engine |
Ignored; for compatibility with package |
... |
Additional arguments passed to |
Details
deeptrafo
is the main function for setting up neural network
transformation models and is called by all aliases for the more special
cases (see e.g. ColrNN
). The naming convention
of the aliases follow the 'tram' package (see e.g. Colr
)
and add the suffix "NN" to the function name.
Value
An object of class c("deeptrafo", "deepregression")
References
Kook, L., Baumann, P. F., Dürr, O., Sick, B., & Rügamer, D. (2024). Estimating conditional distributions with neural networks using R package deeptrafo. Journal of Statistical Software. doi:10.18637/jss.v111.i10.
Examples
if (.Platform$OS.type != "windows" &&
reticulate::py_available() &&
reticulate::py_module_available("tensorflow") &&
reticulate::py_module_available("keras") &&
reticulate::py_module_available("tensorflow_probability")) {
data("wine", package = "ordinal")
wine$z <- rnorm(nrow(wine))
wine$x <- rnorm(nrow(wine))
nn <- \(x) x |>
layer_dense(input_shape = 1L, units = 2L, activation = "relu") |>
layer_dense(1L)
fml <- rating ~ 0 + temp + contact + s(z, df = 3) + nn(x)
m <- deeptrafo(fml, wine,
latent_distr = "logistic", monitor_metric = NULL,
return_data = TRUE, list_of_deep_models = list(nn = nn)
)
print(m)
m %>% fit(epochs = 10, batch_size = nrow(wine))
coef(m, which_param = "interacting")
coef(m, which_param = "shifting")
fitted(m)
predict(m, type = "pdf")
predict(m, type = "pdf", newdata = wine[, -2])
logLik(m)
logLik(m, newdata = wine[1:10, ])
plot(m)
mcv <- cv(m, cv_folds = 3)
ens <- ensemble(m, n_ensemble = 3)
coef(ens)
}