Title: | Fitting Deep Conditional Transformation Models |
---|---|
Description: | Allows for the specification of deep conditional transformation models (DCTMs) and ordinal neural network transformation models, as described in Baumann et al (2021) <doi:10.1007/978-3-030-86523-8_1> and Kook et al (2022) <doi:10.1016/j.patcog.2021.108263>. Extensions such as autoregressive DCTMs (Ruegamer et al, 2022, <doi:10.48550/arXiv.2110.08248>) and transformation ensembles (Kook et al, 2022, <doi:10.48550/arXiv.2205.12729>) are implemented. |
Authors: | Lucas Kook [aut, cre], Philipp Baumann [aut], David Ruegamer [aut] |
Maintainer: | Lucas Kook <[email protected]> |
License: | GPL-3 |
Version: | 0.1-1 |
Built: | 2024-11-11 04:15:09 UTC |
Source: | https://github.com/cran/deeptrafo |
Initializes the Processed Additive Predictor for ATMs
atm_init(atmnr, h1nr)
atm_init(atmnr, h1nr)
atmnr , h1nr
|
positions of the atm and h1 formula |
returns a subnetwork_init function with pre-defined arguments
BoxCox-type neural network transformation models
BoxCoxNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "normal", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
BoxCoxNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "normal", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
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 |
monitor_metrics |
See |
trafo_options |
Options for transformation models such as the basis
function used, see |
... |
Additional arguments passed to |
See return statement of deeptrafo
df <- data.frame(y = rnorm(50), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- BoxCoxNN(y ~ x, data = df) coef(m) }
df <- data.frame(y = rnorm(50), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- BoxCoxNN(y ~ x, data = df) coef(m) }
Deep continuous outcome logistic regression
ColrNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "logistic", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
ColrNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "logistic", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
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 |
monitor_metrics |
See |
trafo_options |
Options for transformation models such as the basis
function used, see |
... |
Additional arguments passed to |
See return statement of deeptrafo
df <- data.frame(y = rnorm(50), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- ColrNN(y ~ x, data = df) coef(m) }
df <- data.frame(y = rnorm(50), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- ColrNN(y ~ x, data = df) coef(m) }
Deep distribution-free count regression
cotramNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "logistic", monitor_metrics = NULL, ... )
cotramNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "logistic", monitor_metrics = NULL, ... )
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 |
monitor_metrics |
See |
... |
Additional arguments passed to |
See return statement of deeptrafo
set.seed(1) df <- data.frame(y = as.integer(abs(1 + rnorm(50, sd = 10))), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- cotramNN(y ~ 0 + x, data = df, order = 6) optimizer <- optimizer_adam(learning_rate = 0.1, decay = 4e-4) m <- cotramNN(y ~ 0 + x, data = df, optimizer = optimizer, order = 6) library(cotram) fit(m, epochs = 800L, validation_split = 0) logLik(mm <- cotram(y ~ x, data = df, method = "logit")); logLik(m) coef(mm, with_baseline = TRUE); unlist(c(coef(m, which = "interacting"), coef(m, which = "shifting"))) }
set.seed(1) df <- data.frame(y = as.integer(abs(1 + rnorm(50, sd = 10))), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- cotramNN(y ~ 0 + x, data = df, order = 6) optimizer <- optimizer_adam(learning_rate = 0.1, decay = 4e-4) m <- cotramNN(y ~ 0 + x, data = df, optimizer = optimizer, order = 6) library(cotram) fit(m, epochs = 800L, validation_split = 0) logLik(mm <- cotram(y ~ x, data = df, method = "logit")); logLik(m) coef(mm, with_baseline = TRUE); unlist(c(coef(m, which = "interacting"), coef(m, which = "shifting"))) }
Cox proportional hazards type neural network transformation models
CoxphNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "gompertz", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
CoxphNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "gompertz", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
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 |
monitor_metrics |
See |
trafo_options |
Options for transformation models such as the basis
function used, see |
... |
Additional arguments passed to |
See return statement of deeptrafo
df <- data.frame(y = rnorm(50), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- CoxphNN(y ~ x, data = df) coef(m) }
df <- data.frame(y = rnorm(50), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- CoxphNN(y ~ x, data = df) coef(m) }
Deep conditional transformation models with alternative formula interface
dctm( response, intercept = NULL, shift = NULL, shared = NULL, data, response_type = get_response_type(data[[all.vars(response)[1]]]), order = get_order(response_type, data[[all.vars(response)[1]]]), addconst_interaction = 0, latent_distr = "logistic", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
dctm( response, intercept = NULL, shift = NULL, shared = NULL, data, response_type = get_response_type(data[[all.vars(response)[1]]]), order = get_order(response_type, data[[all.vars(response)[1]]]), addconst_interaction = 0, latent_distr = "logistic", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
response |
Formula for the response; e.g. |
intercept |
Formula for the intercept function; e.g., |
shift |
Formula for the shift part of the model; e.g., |
shared |
Formula for sharing weights between predictors in the intercept and shift part of the model |
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 |
monitor_metrics |
See |
trafo_options |
Options for transformation models such as the basis
function used, see |
... |
Additional arguments passed to |
See return statement of deeptrafo
df <- data.frame(y = rnorm(50), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- dctm(response = ~ y, shift = ~ 0 + x, data = df) coef(m) }
df <- data.frame(y = rnorm(50), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- dctm(response = ~ y, shift = ~ 0 + x, data = df) coef(m) }
Deep Conditional Transformation Models
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", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), return_data = FALSE, ... )
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", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), return_data = FALSE, ... )
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 |
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
|
... |
Additional arguments passed to |
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.
An object of class c("deeptrafo", "deepregression")
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) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { 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) }
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) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { 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) }
Deep ensembling for neural network transformation models
## S3 method for class 'deeptrafo' ensemble( x, n_ensemble = 5, reinitialize = TRUE, mylapply = lapply, verbose = FALSE, patience = 20, plot = TRUE, print_members = TRUE, stop_if_nan = TRUE, save_weights = TRUE, callbacks = list(), save_fun = NULL, ... )
## S3 method for class 'deeptrafo' ensemble( x, n_ensemble = 5, reinitialize = TRUE, mylapply = lapply, verbose = FALSE, patience = 20, plot = TRUE, print_members = TRUE, stop_if_nan = TRUE, save_weights = TRUE, callbacks = list(), save_fun = NULL, ... )
x |
Object of class |
n_ensemble |
Numeric; number of ensemble members to fit. |
reinitialize |
Logical; if |
mylapply |
Function; |
verbose |
Logical; whether to print training in each fold. |
patience |
Integer; number of patience for early stopping. |
plot |
Logical; whether to plot the resulting losses in each fold. |
print_members |
Logical; print results for each member. |
stop_if_nan |
Logical; whether to stop ensembling if |
save_weights |
Logical; whether to save the ensemble weights. |
callbacks |
List; callbacks used for fitting. |
save_fun |
Function; function to be applied to each member to be stored in the final result. |
... |
Further arguments passed to |
Ensemble of "deeptrafo"
models with list of training histories
and fitted weights included in ensemble_results
. For details see
the return statment in ensemble
.
Define Predictor of Transformation Model
from_preds_to_trafo( atm_toplayer = function(x) layer_dense(x, units = 1L, name = "atm_toplayer"), const_ia = NULL )
from_preds_to_trafo( atm_toplayer = function(x) layer_dense(x, units = 1L, name = "atm_toplayer"), const_ia = NULL )
atm_toplayer |
Function to be applied on top of the transformed lags. |
const_ia |
See |
Not intended to be used directly by the end user.
A function of list_pred_param
returning a list of output tensors
that is passed to model_fun
of deepregression
Initializes the Processed Additive Predictor for TM's Interaction
h1_init(yterms, h1pred, add_const_positiv = 0)
h1_init(yterms, h1pred, add_const_positiv = 0)
yterms |
Terms for the response |
h1pred |
Interacting predictor |
add_const_positiv |
Shift basis for the predictors to be strictly positive |
returns a subnetwork_init function with pre-defined arguments
Lehmann-type neural network transformation models
LehmanNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "gumbel", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
LehmanNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "gumbel", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
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 |
monitor_metrics |
See |
trafo_options |
Options for transformation models such as the basis
function used, see |
... |
Additional arguments passed to |
See return statement of deeptrafo
df <- data.frame(y = rnorm(50), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- LehmanNN(y ~ 0 + x, data = df) coef(m) }
df <- data.frame(y = rnorm(50), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- LehmanNN(y ~ 0 + x, data = df) coef(m) }
Deep normal linear regression
LmNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "normal", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = 1L, response_type = response_type, y_basis_fun = eval_lin, y_basis_fun_lower = .empty_fun(eval_lin), y_basis_fun_prime = eval_lin_prime, basis = "shiftscale"), ... )
LmNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "normal", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = 1L, response_type = response_type, y_basis_fun = eval_lin, y_basis_fun_lower = .empty_fun(eval_lin), y_basis_fun_prime = eval_lin_prime, basis = "shiftscale"), ... )
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 |
monitor_metrics |
See |
trafo_options |
Options for transformation models such as the basis
function used, see |
... |
Additional arguments passed to |
See return statement of deeptrafo
set.seed(1) df <- data.frame(y = 10 + rnorm(50), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- LmNN(y ~ 0 + x, data = df) optimizer <- optimizer_adam(learning_rate = 0.01, decay = 4e-4) m <- LmNN(y ~ 0 + x, data = df, optimizer = optimizer) library(tram) fit(m, epochs = 900L, validation_split = 0) logLik(mm <- Lm(y ~ x, data = df)); logLik(m) coef(mm, with_baseline = TRUE); unlist(c(coef(m, which = "interacting"), coef(m, which = "shifting"))) }
set.seed(1) df <- data.frame(y = 10 + rnorm(50), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- LmNN(y ~ 0 + x, data = df) optimizer <- optimizer_adam(learning_rate = 0.01, decay = 4e-4) m <- LmNN(y ~ 0 + x, data = df, optimizer = optimizer) library(tram) fit(m, epochs = 900L, validation_split = 0) logLik(mm <- Lm(y ~ x, data = df)); logLik(m) coef(mm, with_baseline = TRUE); unlist(c(coef(m, which = "interacting"), coef(m, which = "shifting"))) }
Generic negative log-likelihood for transformation models
nll(base_distribution)
nll(base_distribution)
base_distribution |
Target distribution, character or
|
A function for computing the negative log-likelihood of a neural network transformation model with generic response.
Ordinal neural network transformation models
ontram( response, intercept = NULL, shift = NULL, shared = NULL, data, response_type = "ordered", order = get_order(response_type, data[[all.vars(response)[1]]]), addconst_interaction = 0, latent_distr = "logistic", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
ontram( response, intercept = NULL, shift = NULL, shared = NULL, data, response_type = "ordered", order = get_order(response_type, data[[all.vars(response)[1]]]), addconst_interaction = 0, latent_distr = "logistic", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
response |
Formula for the response; e.g., |
intercept |
Formula for the intercept function; e.g., |
shift |
Formula for the shift part of the model; e.g., |
shared |
Formula for sharing weights between predictors in the intercept and shift part of the model |
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 |
monitor_metrics |
See |
trafo_options |
Options for transformation models such as the basis
function used, see |
... |
Additional arguments passed to |
See return statement of deeptrafo
Kook, L. & Herzog, L., Hothorn, T., Dürr, O., & Sick, B. (2022). Deep and interpretable regression models for ordinal outcomes. Pattern Recognition, 122, 108263. DOI 10.1016/j.patcog.2021.108263
df <- data.frame(y = ordered(sample.int(6, 50, TRUE)), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- ontram(response = ~ y, shift = ~ x, data = df) coef(m) }
df <- data.frame(y = ordered(sample.int(6, 50, TRUE)), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- ontram(response = ~ y, shift = ~ x, data = df) coef(m) }
Generic methods for neural network transformation models
## S3 method for class 'deeptrafo' plot( x, which = NULL, type = c("smooth", "trafo", "pdf", "cdf"), newdata = NULL, which_param = c("shifting", "interacting"), only_data = FALSE, K = 40, q = NULL, ... ) ## S3 method for class 'deeptrafo' coef( object, which_param = c("shifting", "interacting", "autoregressive"), type = NULL, ... ) ## S3 method for class 'deeptrafo' predict( object, newdata = NULL, type = c("trafo", "pdf", "cdf", "interaction", "shift", "terms"), batch_size = NULL, K = 100, q = NULL, ... ) ## S3 method for class 'deeptrafo' fitted(object, newdata = NULL, batch_size = NULL, convert_fun = as.matrix, ...) ## S3 method for class 'deeptrafo' logLik( object, newdata = NULL, convert_fun = function(x, ...) -sum(x, ...), ... ) ## S3 method for class 'deeptrafo' simulate(object, nsim = 1, seed = NULL, newdata = NULL, ...) ## S3 method for class 'deeptrafo' print(x, print_model = FALSE, print_coefs = TRUE, with_baseline = FALSE, ...) ## S3 method for class 'deeptrafo' summary(object, ...)
## S3 method for class 'deeptrafo' plot( x, which = NULL, type = c("smooth", "trafo", "pdf", "cdf"), newdata = NULL, which_param = c("shifting", "interacting"), only_data = FALSE, K = 40, q = NULL, ... ) ## S3 method for class 'deeptrafo' coef( object, which_param = c("shifting", "interacting", "autoregressive"), type = NULL, ... ) ## S3 method for class 'deeptrafo' predict( object, newdata = NULL, type = c("trafo", "pdf", "cdf", "interaction", "shift", "terms"), batch_size = NULL, K = 100, q = NULL, ... ) ## S3 method for class 'deeptrafo' fitted(object, newdata = NULL, batch_size = NULL, convert_fun = as.matrix, ...) ## S3 method for class 'deeptrafo' logLik( object, newdata = NULL, convert_fun = function(x, ...) -sum(x, ...), ... ) ## S3 method for class 'deeptrafo' simulate(object, nsim = 1, seed = NULL, newdata = NULL, ...) ## S3 method for class 'deeptrafo' print(x, print_model = FALSE, print_coefs = TRUE, with_baseline = FALSE, ...) ## S3 method for class 'deeptrafo' summary(object, ...)
x |
Object of class |
which |
Which effect to plot, default selects all smooth effects in the shift term. |
type |
Either NULL (all types of coefficients are returned),
"linear" for linear coefficients or "smooth" for coefficients of;
Note that |
newdata |
Named |
which_param |
Character; either |
only_data |
Logical, if |
K |
Integer; grid length for the response to evaluate predictions at,
if |
q |
Numeric or factor; user-supplied grid of response values to evaluate
the predictions. Defaults to |
... |
Further arguments supplied to |
object |
Object of class |
batch_size |
Integer; optional, useful if data is too large. |
convert_fun |
Function; applied to the log-likelihood values of all observations. |
nsim |
Integer; number of simulations; defaults to 1. |
seed |
Seed for generating samples; defaults to |
print_model |
Logical; print keras model. |
print_coefs |
Logical; print coefficients. |
with_baseline |
Logical; print baseline coefs. |
If no new data is supplied, predictions are computed on the training
data (i.e. in-sample). If new data is supplied without a response,
predictions are evaluated on a grid of length K
.
Returns vector or matrix of predictions, depending on the supplied
type
.
Returns matrix of fitted values.
Deep (proportional odds) logistic regression
PolrNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "logistic", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
PolrNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "logistic", monitor_metrics = NULL, trafo_options = trafo_control(order_bsp = order, response_type = response_type), ... )
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 |
monitor_metrics |
See |
trafo_options |
Options for transformation models such as the basis
function used, see |
... |
Additional arguments passed to |
See return statement of deeptrafo
df <- data.frame(y = ordered(sample.int(5, 50, replace = TRUE)), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- PolrNN(y ~ x, data = df) coef(m) }
df <- data.frame(y = ordered(sample.int(5, 50, replace = TRUE)), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- PolrNN(y ~ x, data = df) coef(m) }
Deep parametric survival regression
SurvregNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "gompertz", monitor_metrics = NULL, trafo_options = NULL, ... )
SurvregNN( formula, data, response_type = get_response_type(data[[all.vars(formula)[1]]]), order = get_order(response_type, data[[all.vars(formula)[1]]]), addconst_interaction = 0, latent_distr = "gompertz", monitor_metrics = NULL, trafo_options = NULL, ... )
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 |
monitor_metrics |
See |
trafo_options |
Options for transformation models such as the basis
function used, see |
... |
Additional arguments passed to |
See return statement of deeptrafo
set.seed(1) df <- data.frame(y = abs(1 + rnorm(50)), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- SurvregNN(y ~ 0 + x, data = df) optimizer <- optimizer_adam(learning_rate = 0.01, decay = 4e-4) m <- SurvregNN(y ~ 0 + x, data = df, optimizer = optimizer) library(tram) fit(m, epochs = 500L, validation_split = 0) logLik(mm <- Survreg(y ~ x, data = df, dist = "loglogistic")); logLik(m) coef(mm, with_baseline = TRUE); unlist(c(coef(m, which = "interacting"), coef(m, which = "shifting"))) }
set.seed(1) df <- data.frame(y = abs(1 + rnorm(50)), x = rnorm(50)) if (reticulate::py_module_available("tensorflow") & reticulate::py_module_available("keras") & reticulate::py_module_available("tensorflow_probability")) { m <- SurvregNN(y ~ 0 + x, data = df) optimizer <- optimizer_adam(learning_rate = 0.01, decay = 4e-4) m <- SurvregNN(y ~ 0 + x, data = df, optimizer = optimizer) library(tram) fit(m, epochs = 500L, validation_split = 0) logLik(mm <- Survreg(y ~ x, data = df, dist = "loglogistic")); logLik(m) coef(mm, with_baseline = TRUE); unlist(c(coef(m, which = "interacting"), coef(m, which = "shifting"))) }
Options for transformation models
trafo_control( order_bsp = 10L, support = function(y) range(y), y_basis_fun = NULL, y_basis_fun_lower = NULL, y_basis_fun_prime = NULL, penalize_bsp = 0, order_bsp_penalty = 2, tf_bsps = FALSE, response_type = c("continuous", "ordered", "survival", "count"), atm_toplayer = function(x) layer_dense(x, units = 1L, name = "atm_toplayer", use_bias = FALSE), basis = c("bernstein", "ordered", "shiftscale") )
trafo_control( order_bsp = 10L, support = function(y) range(y), y_basis_fun = NULL, y_basis_fun_lower = NULL, y_basis_fun_prime = NULL, penalize_bsp = 0, order_bsp_penalty = 2, tf_bsps = FALSE, response_type = c("continuous", "ordered", "survival", "count"), atm_toplayer = function(x) layer_dense(x, units = 1L, name = "atm_toplayer", use_bias = FALSE), basis = c("bernstein", "ordered", "shiftscale") )
order_bsp |
The order of Bernstein polynomials in case |
support |
A function returning a vector with two elements, namely the support for the basis of y. |
y_basis_fun |
Function; basis function for Y |
y_basis_fun_lower |
Function; basis function for lower bound of interval censored response |
y_basis_fun_prime |
Function; basis function derivative |
penalize_bsp |
Scalar value > 0; controls amount of penalization of Bernstein polynomials. |
order_bsp_penalty |
Integer; order of Bernstein polynomial penalty. 0 results in a penalty based on integrated squared second order derivatives, values >= 1 in difference penalties. |
tf_bsps |
Logical; whether to use a TensorFlow implementation of the Bernstein polynomial functions. |
response_type |
Character; type of response can be continuous, ordered, survival, or count. |
atm_toplayer |
Function; a function specifying the layer on top of ATM lags. |
basis |
Character or function; implemented options are
|
Returns a named list
with all options, basis functions,
support, and penalties.