View source: R/cv_estimate_rt.R
cv_estimate_rt | R Documentation |
Leave-kth-out cross validation for choosing a optimal parameter lambda
cv_estimate_rt(
observed_counts,
korder = 3L,
dist_gamma = c(2.5, 2.5),
nfold = 3L,
error_measure = c("deviance", "mse", "mae"),
x = 1:n,
lambda = NULL,
maxiter = 1000000L,
delay_distn = NULL,
delay_distn_periodicity = NULL,
regular_splits = FALSE,
invert_splits = FALSE,
...
)
observed_counts |
vector of the observed daily infection counts |
korder |
Integer. Degree of the piecewise polynomial curve to be
estimated. For example, |
dist_gamma |
Vector of length 2. These are the shape and scale for the assumed serial interval distribution. Roughly, this distribution describes the probability of an infectious individual infecting someone else after some period of time after having become infectious. As in most literature, we assume that this interval follows a gamma distribution with some shape and scale. |
nfold |
Integer. This number of folds to conduct the leave-kth-out
cross validation. For leave-kth-out cross validation, every kth
observed_counts and their corresponding position (evenly or unevenly
spaced) are placed into the same fold. The first and last observed_counts are
not assigned to any folds. Smallest allowable value is |
error_measure |
Metric used to calculate cross validation scores.
Must be choose from |
x |
a vector of positions at which the counts have been observed. In an ideal case, we would observe data at regular intervals (e.g. daily or weekly) but this may not always be the case. May be numeric or Date. |
lambda |
Vector. A user supplied sequence of tuning parameters which
determines the balance between data fidelity and
smoothness of the estimated Rt; larger |
maxiter |
Integer. Maximum number of iterations for the estimation algorithm. |
delay_distn |
in the case of a non-gamma delay distribution,
a vector or matrix (or |
delay_distn_periodicity |
Controls the relationship between the spacing
of the computed delay distribution and the spacing of |
regular_splits |
Logical.
If
where 0 indicates no assignment.
Therefore, the folds are not random and running |
invert_splits |
Logical.
Typical K-fold CV would use K-1 folds for the training
set while reserving 1 fold for evaluation (repeating the split K times).
Setting this to true inverts this process, using a much smaller training
set with a larger evaluation set. This tends to result in larger values
of |
... |
additional parameters passed to |
An object with S3 class "cv_poisson_rt"
. Among the list components:
full_fit
An object with S3 class "poisson_rt"
, fitted with all
observed_counts
and lambda
cv_scores
leave-kth-out cross validation scores
cv_se
leave-kth-out cross validation standard error
lambda.min
lambda which achieved the optimal cross validation score
lambda.1se
lambda that gives the optimal cross validation score
within one standard error.
lambda
the value of lambda
used in the algorithm.
y <- c(1, rpois(100, dnorm(1:100, 50, 15) * 500 + 1))
cv <- cv_estimate_rt(y, korder = 3, nfold = 3, nsol = 30)
cv
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.