diff --git a/NEWS.md b/NEWS.md index 0422639..fe203f9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ * Estimation of dynamic multivariate panel models with multiple imputation is now available via the function `dynamice()` which uses the `mice` package. * `predict` and `fitted` functions no longer permutes the posterior samples when all samples are used i.e. when `n_draws = NULL` (default). This also corrects the standard error estimates of `loo`, which were not correct earlier due to the mixing of chains. - * Added an argument `thin` for the `loo`, `lfo`, `predict` and `fitted` method. + * Added an argument `thin` for the `loo`, `predict` and `fitted` method. * Print method now only prints the run time for fastest and slowest chain instead of all chains. # dynamite 1.4.11 diff --git a/R/dynamice.R b/R/dynamice.R index fdc6424..553998f 100644 --- a/R/dynamice.R +++ b/R/dynamice.R @@ -444,10 +444,12 @@ parse_predictors_wide <- function(dformula, value_vars, idx_time, group_var) { #' Compute Lagging Values of an Imputed Response #' +#' Function for computing the lagged values of an imputed response in `mice`. +#' #' @inheritParams mice::mice.impute.norm #' @param group_var \[`character(1)`]\cr Name of the grouping variable. #' @param resp \[`character(1)`]\cr Name of the response variable. -#' @noRd +#' @keywords internal #' @export mice.impute.lag <- function(y, ry, x, wy = NULL, group_var, resp, ...) { @@ -464,10 +466,12 @@ mice.impute.lag <- function(y, ry, x, wy = NULL, #' Compute Leading Values of an Imputed Response #' +#' Function for computing the leading values of an imputed response in `mice`. +#' #' @inheritParams mice::mice.impute.norm #' @param group_var \[`character(1)`]\cr Name of the grouping variable. #' @param resp \[`character(1)`]\cr Name of the response variable. -#' @noRd +#' @keywords internal #' @export mice.impute.lead <- function(y, ry, x, wy = NULL, group_var, resp, ...) { diff --git a/R/lfo.R b/R/lfo.R index a538fe3..c44d12f 100644 --- a/R/lfo.R +++ b/R/lfo.R @@ -19,9 +19,6 @@ #' the LFO computations to the console. #' @param k_threshold \[`numeric(1)`]\cr Threshold for the Pareto k estimate #' triggering refit. Default is 0.7. -#' @param thin \[`integer(1)`]\cr Use only every `thin` posterior sample when -#' computing LFO. This can be beneficial with when the model object contains -#' large number of samples. Default is `1` meaning that all samples are used. #' @param ... Additional arguments passed to [rstan::sampling()] or #' [cmdstanr::sample()], such as `chains` and `cores` (`parallel_chains` in #' `cmdstanr`). @@ -54,7 +51,7 @@ #' } #' } #' -lfo <- function(x, L, verbose = TRUE, k_threshold = 0.7, thin = 1, ...) { +lfo <- function(x, L, verbose = TRUE, k_threshold = 0.7, ...) { stopifnot_( is.null(x$imputed), "Leave-future-out cross-validation is not supported for models @@ -76,10 +73,6 @@ lfo <- function(x, L, verbose = TRUE, k_threshold = 0.7, thin = 1, ...) { checkmate::test_number(x = k_threshold), "Argument {.arg k_threshold} must be a single {.cls numeric} value." ) - stopifnot_( - checkmate::test_int(x = thin, lower = 1L, upper = ndraws(x)), - "Argument {.arg thin} must be a single positive {.cls integer}." - ) time_var <- x$time_var group_var <- x$group_var tp <- sort(unique(x$data[[time_var]])) @@ -100,7 +93,7 @@ lfo <- function(x, L, verbose = TRUE, k_threshold = 0.7, thin = 1, ...) { } fit <- update_(x, data = d, refresh = 0, ...) - idx_draws <- seq.int(1, ndraws(x), by = thin) + idx_draws <- seq.int(1, ndraws(fit)) n_draws <- length(idx_draws) # would be faster to use only data # x$data[eval(time) >= tp[L] - x$stan$fixed] diff --git a/man/lfo.Rd b/man/lfo.Rd index d4c10f4..75f3858 100644 --- a/man/lfo.Rd +++ b/man/lfo.Rd @@ -4,7 +4,7 @@ \alias{lfo} \title{Approximate Leave-Future-Out (LFO) Cross-validation} \usage{ -lfo(x, L, verbose = TRUE, k_threshold = 0.7, thin = 1, ...) +lfo(x, L, verbose = TRUE, k_threshold = 0.7, ...) } \arguments{ \item{x}{[\code{dynamitefit}]\cr The model fit object.} @@ -18,10 +18,6 @@ the LFO computations to the console.} \item{k_threshold}{[\code{numeric(1)}]\cr Threshold for the Pareto k estimate triggering refit. Default is 0.7.} -\item{thin}{[\code{integer(1)}]\cr Use only every \code{thin} posterior sample when -computing LFO. This can be beneficial with when the model object contains -large number of samples. Default is \code{1} meaning that all samples are used.} - \item{...}{Additional arguments passed to \code{\link[rstan:stanmodel-method-sampling]{rstan::sampling()}} or \code{\link[cmdstanr:model-method-sample]{cmdstanr::sample()}}, such as \code{chains} and \code{cores} (\code{parallel_chains} in \code{cmdstanr}).}