methodDR: Generic functions for deepregression models

Description Usage Arguments Value

Description

Generic functions for deepregression models

Predict based on a deepregression object

Function to extract fitted distribution

Fit a deepregression model (pendant to fit for keras)

Extract layer weights / coefficients from model

Print function for deepregression model

Cross-validation for deepgression objects

mean of model fit

Standard deviation of fit distribution

Calculate the distribution quantiles

Usage

 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
## S3 method for class 'deepregression'
plot(
  x,
  which = NULL,
  which_param = 1,
  only_data = FALSE,
  grid_length = 40,
  type = "b",
  ...
)

## S3 method for class 'deepregression'
predict(
  object,
  newdata = NULL,
  batch_size = NULL,
  apply_fun = tfd_mean,
  convert_fun = as.matrix,
  ...
)

## S3 method for class 'deepregression'
fitted(object, apply_fun = tfd_mean, ...)

## S3 method for class 'deepregression'
fit(
  object,
  batch_size = 32,
  epochs = 10,
  early_stopping = FALSE,
  early_stopping_metric = "val_loss",
  verbose = TRUE,
  view_metrics = FALSE,
  patience = 20,
  save_weights = FALSE,
  validation_data = NULL,
  validation_split = ifelse(is.null(validation_data), 0.1, 0),
  callbacks = list(),
  convertfun = function(x) tf$constant(x, dtype = "float32"),
  ...
)

## S3 method for class 'deepregression'
coef(object, which_param = 1, type = NULL, ...)

## S3 method for class 'deepregression'
print(x, ...)

## S3 method for class 'deepregression'
cv(
  x,
  verbose = FALSE,
  patience = 20,
  plot = TRUE,
  print_folds = TRUE,
  cv_folds = 5,
  stop_if_nan = TRUE,
  mylapply = lapply,
  save_weights = FALSE,
  callbacks = list(),
  save_fun = NULL,
  ...
)

## S3 method for class 'deepregression'
mean(x, data = NULL, ...)

## S3 method for class 'deepregression'
stddev(x, data = NULL, ...)

## S3 method for class 'deepregression'
quant(x, data = NULL, probs, ...)

Arguments

x

a deepregression object

which

character vector or number(s) identifying the effect to plot; default plots all effects

which_param

integer, indicating for which distribution parameter coefficients should be returned (default is first parameter)

only_data

logical, if TRUE, only the data for plotting is returned

grid_length

the length of an equidistant grid at which a two-dimensional function is evaluated for plotting.

type

either NULL (all types of coefficients are returned), "linear" for linear coefficients or "smooth" for coefficients of smooth terms

...

arguments passed to the predict function

object

a deepregression model

newdata

optional new data, either data.frame or list

batch_size

integer, the batch size used for mini-batch training

apply_fun

function applied to fitted distribution, per default tfd_mean

convert_fun

how should the resulting tensor be converted, per default as.matrix

epochs

integer, the number of epochs to fit the model

early_stopping

logical, whether early stopping should be user.

early_stopping_metric

character, based on which metric should early stopping be trigged (default: "val_loss")

verbose

whether to print training in each fold

view_metrics

logical, whether to trigger the Viewer in RStudio / Browser.

patience

number of patience for early stopping

save_weights

logical, whether to save weights in each epoch.

validation_data

optional specified validation data

validation_split

float in [0,1] defining the amount of data used for validation

callbacks

a list of callbacks used for fitting

convertfun

function to convert R into Tensor object

plot

whether to plot the resulting losses in each fold

print_folds

whether to print the current fold

cv_folds

an integer if list with train and test data sets

stop_if_nan

logical; whether to stop CV if NaN values occur

mylapply

lapply function to be used; defaults to lapply

save_fun

function applied to the model in each fold to be stored in the final result

data

either NULL or a new data set

probs

the quantile value(s)

Value

Returns an object drCV, a list, one list element for each fold containing the model fit and the weighthistory.


deepregression documentation built on Oct. 5, 2021, 1:06 a.m.