Skip to content

Commit

Permalink
update spinar_sim, spinar_boot and help page of spinar_boot
Browse files Browse the repository at this point in the history
  • Loading branch information
MFaymon committed Mar 1, 2024
1 parent 71f646e commit a9de6f3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
14 changes: 7 additions & 7 deletions R/spinar_boot.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#' estimation setting \eqn{\in \code{\{"sp", "p"\}}}, where \code{"sp"} defines a semiparametric setting and
#' \code{"p"} a parametric setting.
#' @param type [\code{string(1)}]\cr
#' type of estimation \eqn{\in \code{\{"mom", "ml"\}}}, where \code{"mom"} performs moment-based estimation and
#' type of estimation \eqn{\in \code{\{"mom", "ml"\}}}, where \code{"mom"} (default) performs moment-based estimation and
#' \code{"ml"} maximum likelihood-based estimation.
#' @param distr [\code{string(1)}]\cr
#' parametric family of innovation distribution \eqn{\in \code{\{"poi", "geo", "nb"\}}}, where \code{"poi"} denotes
#' parametric family of innovation distribution \eqn{\in \code{\{"poi", "geo", "nb"\}}}, where \code{"poi"} (default) denotes
#' Poi(\code{lambda}), \code{"geo"} Geo(\code{prob}) and \code{"nb"} NB(\code{r}, \code{prob}) distributions.
#' @param M [\code{integer(1)}]\cr
#' upper limit for the innovations.
Expand Down Expand Up @@ -64,15 +64,15 @@
#' }
#'
#' @export spinar_boot
spinar_boot <- function(x, p, B, setting, type = NA, distr = NA, M = 100, level = 0.05, progress = TRUE){
assert_integerish(p, lower = 1, upper = 2, len = 1)
spinar_boot <- function(x, p, B, setting, type = "mom", distr = "poi", M = 100, level = 0.05, progress = TRUE){
assert_integerish(p, lower = 1, upper = 2, len = 1, any.missing = FALSE)
assert_integerish(B, lower = 1, len = 1)
assert_integerish(x, lower = 0, min.len = p+1)
assert_choice(setting, c("sp", "p"))
assert_choice(type, c("mom", "ml", NA))
assert_choice(distr, c("poi", "geo", "nb", NA))
assert_choice(type, c("mom", "ml"))
assert_choice(distr, c("poi", "geo", "nb"))
assert_integerish(M, lower = 0, len = 1)
assert_numeric(level, lower = 0, upper = 1, len = 1)
assert_numeric(level, lower = 1e-16, upper = 1, len = 1)

bs <- list(x_star = matrix(NA, length(x), B), parameters_star = matrix(0, B, M+p+1),
bs_ci_percentile = NULL, bs_ci_hall = NULL)
Expand Down
14 changes: 11 additions & 3 deletions R/spinar_sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@
#'
#' @export spinar_sim
spinar_sim <- function(n, p, alpha, pmf, prerun = 500) {
assert_integerish(p, lower = 1, upper = 2, len = 1)
assert_integerish(p, lower = 1, upper = 2, len = 1, any.missing = FALSE)
assert_numeric(alpha, lower = 0, upper = 1, len = p)
assert_numeric(pmf, lower = 0, upper = 1, min.len = p+1)
assert_integerish(n, lower = 0, len = 1)
assert_integerish(n, lower = 0, len = 1, any.missing = FALSE)
assert_integerish(prerun, lower = 0, len = 1)
if (round(sum(pmf), 6) != 1) {
warning("Sum of pmf entries has been standardized to 1.")
}
if (n + prerun <= p) {
stop("n + prerun must be > p.")
}
pmf <- pmf / sum(pmf)
err <-
sample(0:(length(pmf) - 1),
Expand All @@ -62,6 +65,11 @@ spinar_sim <- function(n, p, alpha, pmf, prerun = 500) {
rbinom(1, x[i - 1], alpha1) + rbinom(1, x[i - 2], alpha2) + err[i]
}
}
return(x[-seq_len(prerun)])
if (prerun > 0){
return(x[-seq_len(prerun)])
}
else {
return(x)
}
}

8 changes: 4 additions & 4 deletions man/spinar_boot.Rd

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

0 comments on commit a9de6f3

Please sign in to comment.