Skip to content

Commit

Permalink
fix estimate_truncation example
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Jan 12, 2024
1 parent 3fe524f commit 05f3d71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions R/estimate_truncation.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
#' )
#' )
#' )
#' cmf <- cmf / cmf[dist$max + 1]
#' cmf <- cmf / cmf[max(dist) + 1]
#' cmf <- rev(cmf)[-1]
#' trunc_cases <- data.table::copy(cases)[1:(.N - index)]
#' trunc_cases[
Expand Down Expand Up @@ -217,13 +217,13 @@ estimate_truncation <- function(obs, max_truncation, trunc_max = 10,
if (construct_trunc) {
params_mean <- c(0, 1)
params_sd <- c(1, 1)
parameters <- lapply(seq_along(params_mean), function (id) {
parameters <- lapply(seq_along(params_mean), function(id) {
Normal(params_mean, params_sd)
})
names(parameters) <- natural_params(trunc_dist)
parameters$max <- trunc_max
truncation <- new_dist_spec(
parameters = parameters,
params = parameters,
distribution = trunc_dist
)
}
Expand Down Expand Up @@ -278,18 +278,18 @@ estimate_truncation <- function(obs, max_truncation, trunc_max = 10,

out <- list()
# Summarise fit truncation distribution for downstream usage
params_mean <- round(
params_mean <- unname(round(
rstan::summary(fit, pars = "delay_params")$summary[, 1], 3
)
params_sd <- round(
))
params_sd <- unname(round(
rstan::summary(fit, pars = "delay_params")$summary[, 3], 3
)
))
parameters <- lapply(seq_along(params_mean), function (id) {
Normal(params_mean[id], params_sd[id])
})
names(parameters) <- natural_params(truncation[[1]]$distribution)
out$dist <- truncation
out$dist$parameters <- parameters
out$dist[[1]]$parameters <- parameters

# summarise reconstructed observations
recon_obs <- extract_stan_param(fit, "recon_obs",
Expand Down
2 changes: 1 addition & 1 deletion man/estimate_truncation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 05f3d71

Please sign in to comment.