Description Usage Arguments References Examples

View source: R/deepregression.R

Fitting Semi-Structured Deep Distributional Regression

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ```
deepregression(
y,
list_of_formulas,
list_of_deep_models = NULL,
family = "normal",
data,
tf_seed = as.integer(1991 - 5 - 4),
return_prepoc = FALSE,
subnetwork_builder = subnetwork_init,
model_builder = keras_dr,
fitting_function = utils::getFromNamespace("fit.keras.engine.training.Model",
"keras"),
additional_processors = list(),
penalty_options = penalty_control(),
orthog_options = orthog_control(),
verbose = FALSE,
...
)
``` |

`y` |
response variable |

`list_of_formulas` |
a named list of right hand side formulas,
one for each parameter of the distribution specified in |

`list_of_deep_models` |
a named list of functions specifying a keras model. See the examples for more details. |

`family` |
a character specifying the distribution. For information on
possible distribution and parameters, see |

`data` |
data.frame or named list with input features |

`tf_seed` |
a seed for TensorFlow (only works with R version >= 2.2.0) |

`return_prepoc` |
logical; if TRUE only the pre-processed data and layers are returned (default FALSE). |

`subnetwork_builder` |
function to build each subnetwork (network for each distribution parameter;
per default |

`model_builder` |
function to build the model based on additive predictors (per default |

`fitting_function` |
function to fit the instantiated model when calling |

`additional_processors` |
a named list with additional processors to convert the formula(s).
Can have an attribute |

`penalty_options` |
options for smoothing and penalty terms defined by |

`orthog_options` |
options for the orthgonalization defined by |

`verbose` |
logical; whether to print progress of model initialization to console |

`...` |
further arguments passed to the |

Ruegamer, D. et al. (2021): deepregression: a Flexible Neural Network Framework for Semi-Structured Deep Distributional Regression. https://arxiv.org/abs/2104.02705.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | ```
library(deepregression)
n <- 1000
data = data.frame(matrix(rnorm(4*n), c(n,4)))
colnames(data) <- c("x1","x2","x3","xa")
formula <- ~ 1 + deep_model(x1,x2,x3) + s(xa) + x1
deep_model <- function(x) x %>%
layer_dense(units = 32, activation = "relu", use_bias = FALSE) %>%
layer_dropout(rate = 0.2) %>%
layer_dense(units = 8, activation = "relu") %>%
layer_dense(units = 1, activation = "linear")
y <- rnorm(n) + data$xa^2 + data$x1
mod <- deepregression(
list_of_formulas = list(loc = formula, scale = ~ 1),
data = data, y = y,
list_of_deep_models = list(deep_model = deep_model)
)
if(!is.null(mod)){
# train for more than 10 epochs to get a better model
mod %>% fit(epochs = 10, early_stopping = TRUE)
mod %>% fitted() %>% head()
cvres <- mod %>% cv()
mod %>% get_partial_effect(name = "s(xa)")
mod %>% coef()
mod %>% plot()
}
mod <- deepregression(
list_of_formulas = list(loc = ~ 1 + s(xa) + x1, scale = ~ 1,
dummy = ~ -1 + deep_model(x1,x2,x3) %OZ% 1),
data = data, y = y,
list_of_deep_models = list(deep_model = deep_model),
mapping = list(1,2,1:2)
)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.