Skip to content

Commit

Permalink
version 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MFaymon authored and cran-robot committed Apr 9, 2024
1 parent 9cfd8ce commit e69ddd1
Show file tree
Hide file tree
Showing 20 changed files with 1,262 additions and 63 deletions.
19 changes: 13 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: spINAR
Type: Package
Title: (Semi)Parametric Estimation and Bootstrapping of INAR Models
Version: 0.1.0
Date: 2023-03-22
Version: 0.2.0
Date: 2024-04-08
Authors@R: c(person(given = "Maxime",
family = "Faymonville",
role = c("aut", "cre"),
Expand All @@ -22,7 +22,12 @@ Authors@R: c(person(given = "Maxime",
family = "Jentsch",
role = "aut",
email = "jentsch@statistik.tu-dortmund.de",
comment = c(ORCID = "0000-0001-7824-1697")))
comment = c(ORCID = "0000-0001-7824-1697")),
person(given = "Christian H.",
family = "Weiß",
role = "ctb",
email = "weissc@hsu-hh.de",
comment = c(ORCID = "0000-0001-8739-6631")))
Maintainer: Maxime Faymonville <faymonville@statistik.tu-dortmund.de>
Description: Semiparametric and parametric estimation of INAR models including a finite sample refinement (Faymonville et al. (2022) <doi:10.1007/s10260-022-00655-0>) for the semiparametric setting introduced in Drost et al. (2009) <doi:10.1111/j.1467-9868.2008.00687.x>, different procedures to bootstrap INAR data (Jentsch, C. and Weiß, C.H. (2017) <doi:10.3150/18-BEJ1057>) and flexible simulation of INAR data.
License: GPL (>= 3)
Expand All @@ -34,11 +39,13 @@ URL: https://github.com/MFaymon/spINAR
BugReports: https://github.com/MFaymon/spINAR/issues
Suggests: knitr, rmarkdown, testthat (>= 3.0.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2023-03-24 15:08:04 UTC; faymonville
Packaged: 2024-04-08 13:32:13 UTC; faymonville
Author: Maxime Faymonville [aut, cre] (<https://orcid.org/0000-0001-5565-0711>),
Javiera Riffo [aut] (<https://orcid.org/0000-0002-5372-7196>),
Jonas Rieger [aut] (<https://orcid.org/0000-0002-0007-4478>),
Carsten Jentsch [aut] (<https://orcid.org/0000-0001-7824-1697>)
Carsten Jentsch [aut] (<https://orcid.org/0000-0001-7824-1697>),
Christian H. Weiß [ctb] (<https://orcid.org/0000-0001-8739-6631>)
Repository: CRAN
Date/Publication: 2023-03-26 19:10:02 UTC
Date/Publication: 2024-04-08 14:00:02 UTC
32 changes: 19 additions & 13 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
625a9223fddbc36dcd5b838cf2189b2b *DESCRIPTION
7802f73bde797f15a357818157732535 *DESCRIPTION
521e416b3c8d71439de3ecdfa46b9e34 *NAMESPACE
147bb4886da91830fc5e26d3aa5bb796 *R/helper.R
6e4a0dbb9bbf0df63af78bd320f52d0e *R/helper_geo.R
Expand All @@ -9,18 +9,22 @@ f53a3bf3e86e8280886565c990ef9728 *R/llpinar_geo.R
e5825266f0e4110552950a52a70fa1b3 *R/llpinar_poi.R
79440ccc744b95b296e02f623914404c *R/llspinar.R
9d1b7e4a45c6487947432424b7b71a1a *R/llspinar_penal.R
d6b30310b37b6db52464e6cf62bf0307 *R/spINAR-package.R
ab1f9bdf4ce3b4f6cae5d4a998aeae8c *R/spinar_boot.R
8de9726017b52a90637fb6bc8c895b66 *R/spinar_est.R
d0795d6e955fb6fd638acf5dd0cc8ea5 *R/spinar_est_param.R
ba863da4c0caced1f67ad121b24b9e7e *R/spinar_penal.R
fc12844891d5072c790f309514c9cecb *R/spinar_penal_val.R
7b52a2751f5b7ee4d01df5e6e6b9ce54 *R/spinar_sim.R
6fb2b28c486d8210aa8b835626be00a7 *README.md
50bdb30e13a175471b36ac172b006773 *R/spINAR-package.R
15f0ca2bbecadcd0319c522e9c59f057 *R/spinar_boot.R
0b3379cc828c474a8ef608e759ef3f6d *R/spinar_est.R
ec56c4bc6b28934c8505d5bc3c58c74f *R/spinar_est_param.R
7d4493378930ac44db443ea8864e9338 *R/spinar_penal.R
256be8d4a26a85e1cd898d9503f83423 *R/spinar_penal_val.R
bb983129f6cc7c348ba6631ec156195c *R/spinar_sim.R
63ac0a7e8c6a48b24efce2d4be5682e0 *README.md
cb4924f3573383fca290a0a8e2ca5294 *build/partial.rdb
63acb560a7149aef28f7e4d3d2ca1742 *inst/CITATION
37b47ffc27856fcd97613b6bf93487b4 *man/spINAR-package.Rd
1ff74f70dbc05168413e55436af25803 *man/spinar_boot.Rd
bd47dd25c18d0c924cacea0cc0babcd9 *build/vignette.rds
5b32945dc26158813b56cdbc4d96bb0c *inst/CITATION
37255b1f270e64c5510e31d63a235069 *inst/doc/Replicate_literature_results_using_spINAR.R
8f94b9fb65a5e7f892ffb06064979913 *inst/doc/Replicate_literature_results_using_spINAR.Rmd
784bcd69254d8a4964b8fd7a4fb22ab4 *inst/doc/Replicate_literature_results_using_spINAR.html
9957b6ea142468bfb813dae9c010f006 *man/spINAR-package.Rd
71ea23785b5e121d6532120f541997b6 *man/spinar_boot.Rd
7e141f281c3fb7090f0fcb608684eb2e *man/spinar_est.Rd
4b3b6108902efae7bc152e30ba1c811c *man/spinar_est_param.Rd
f9d11e5295c1854c3924f35bd40b3efb *man/spinar_penal.Rd
Expand All @@ -32,4 +36,6 @@ efb41e8ff1ea02800c8d26eefd38e750 *tests/testthat/test_spinar_boot.R
f006cddbc473f6a5bdf98125cb79bd0e *tests/testthat/test_spinar_est_param.R
98786eb5d0f252fc910fcc2d4dd3c5dd *tests/testthat/test_spinar_penal.R
f70d321411693251e958aa65c17cf923 *tests/testthat/test_spinar_penal_val.R
2e0653b0e66c8bfd6229206f73826218 *tests/testthat/test_spinar_sim.R
0233ad6f957d6c1fd1c28ac0ba00166d *tests/testthat/test_spinar_sim.R
8f94b9fb65a5e7f892ffb06064979913 *vignettes/Replicate_literature_results_using_spINAR.Rmd
e1b42d3b16765f810aacc0ed80194e46 *vignettes/barplots.png
2 changes: 1 addition & 1 deletion R/spINAR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#'
#' @references
#' Faymonville, M., Jentsch, C., Weiß, C.H. and Aleksandrov, B. (2022).
#' Semiparametric Estimation of INAR Models using Roughness Penalization.
#' "Semiparametric Estimation of INAR Models using Roughness Penalization".
#' Statistical Methods & Applications. \doi{10.1007/s10260-022-00655-0}.
#'
#' Jentsch, C. and Weiß, C. H. (2017), “Bootstrapping INAR Models”.
Expand Down
24 changes: 13 additions & 11 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 All @@ -42,10 +42,10 @@
#' coefficients \eqn{\code{alpha}_1,...,\code{alpha}_p} and the estimated
#' parameter(s) of the innovation distribution.}
#' \item{\code{bs_ci_percentile}}{[\code{named matrix}] with the lower and
#' upper bounds of Hall's bootstrap percentile confidence intervals for each
#' upper bounds of the bootstrap percentile confidence intervals for each
#' parameter in \code{parameters_star}.}
#' \item{\code{bs_ci_hall}}{[\code{named matrix}] with the lower and
#' upper bounds of the bootstrap percentile confidence intervals for each
#' upper bounds of Hall's bootstrap percentile confidence intervals for each
#' parameter in \code{parameters_star}.}
#' }
#'
Expand All @@ -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 Expand Up @@ -136,7 +136,8 @@ spinar_boot <- function(x, p, B, setting, type = NA, distr = NA, M = 100, level
bs$bs_ci_percentile[1,i] <- srt[B*level/2]
bs$bs_ci_percentile[2,i] <- srt[B*(1-level/2)]
} else{
K <- ceiling((B+1)*level/2)
K <- floor((B+1)*level/2)
if(K == 0){K <- 1}
bs$bs_ci_percentile[1,i] <- srt[K]
bs$bs_ci_percentile[2,i] <- srt[B+1-K]
}
Expand All @@ -152,7 +153,8 @@ spinar_boot <- function(x, p, B, setting, type = NA, distr = NA, M = 100, level
bs$bs_ci_hall[1,i] <- parameters[i] - srt[B*(1-level/2)]
bs$bs_ci_hall[2,i] <- parameters[i] - srt[B*level/2]
} else{
K <- ceiling((B+1)*level/2)
K <- floor((B+1)*level/2)
if(K == 0){K <- 1}
bs$bs_ci_hall[1,i] <- parameters[i] - srt[B+1-K]
bs$bs_ci_hall[2,i] <- parameters[i] - srt[K]
}
Expand Down
2 changes: 1 addition & 1 deletion R/spinar_est.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#'
#' @export spinar_est
spinar_est <- function(x, p) {
assert_integerish(p, lower = 1, upper = 2, len = 1)
assert_integerish(p, lower = 1, upper = 2, len = 1, any.missing = FALSE)
assert_integerish(x, min.len = p+1, lower = 0)
xmax <- max(x)
if(p==1){
Expand Down
8 changes: 5 additions & 3 deletions R/spinar_est_param.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#'
#' @export spinar_est_param
spinar_est_param <- function(x, p, type, distr){
assert_integerish(p, lower = 1, upper = 2, len = 1)
assert_integerish(p, lower = 1, upper = 2, len = 1, any.missing = FALSE)
assert_integerish(x, min.len = p+1, lower = 0)
assert(checkChoice(type, c("mom", "ml")))
assert(checkChoice(distr, c("poi", "geo", "nb")))
Expand Down Expand Up @@ -163,11 +163,13 @@ spinar_est_param <- function(x, p, type, distr){
else {
if(p==1){
prob <- max(min(mean(x)/(var(x)*(1+eacf1)-eacf1*mean(x)),0.99),0)
theta <- c(max(eacf1, 1e-5), round((mean(x)*prob*(1-eacf1))/(1-prob)), prob)
rs <- ifelse(round((mean(x)*prob*(1-eacf1))/(1-prob)) == 0, 1, round((mean(x)*prob*(1-eacf1))/(1-prob)))
theta <- c(max(eacf1, 1e-5), rs, prob)
}
if(p==2){
prob <- max(min(mean(x)/(var(x)*(1+ealpha1+ealpha2)-(ealpha1+ealpha2)*mean(x)),0.99),0)
theta <- c(max(ealpha1, 1e-5), max(ealpha2, 1e-5), round((mean(x)*prob*(1-ealpha1-ealpha2))/(1-prob)), prob)
rs <- ifelse(round((mean(x)*prob*(1-ealpha1-ealpha2))/(1-prob)) == 0, 1, round((mean(x)*prob*(1-ealpha1-ealpha2))/(1-prob)))
theta <- c(max(ealpha1, 1e-5), max(ealpha2, 1e-5), rs, prob)
}
est <- suppressWarnings(constrOptim(
theta = theta,
Expand Down
2 changes: 1 addition & 1 deletion R/spinar_penal.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#'
#' @export spinar_penal
spinar_penal <- function(x, p, penal1 = 0, penal2 = 0) {
assert_integerish(p, lower = 1, upper = 2, len = 1)
assert_integerish(p, lower = 1, upper = 2, len = 1, any.missing = FALSE)
assert_integerish(x, lower = 0, min.len = p+1)
assert_numeric(penal1, len = 1)
assert_numeric(penal2, len = 1)
Expand Down
4 changes: 2 additions & 2 deletions R/spinar_penal_val.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@
#'
#' @export spinar_penal_val
spinar_penal_val <- function(x, p, validation, penal1 = NA, penal2 = NA, over = NA, folds = 10, init1 = 1, init2 = 1, progress = TRUE){
assert_integerish(p, lower = 1, len = 1, upper = 2)
assert_integerish(p, lower = 1, len = 1, upper = 2, any.missing = FALSE)
assert_integerish(x, lower = 0, min.len = p+1)
assert_logical(validation, any.missing = FALSE)
assert_numeric(penal1, len = 1)
assert_numeric(penal2, len = 1)

Expand All @@ -64,7 +65,6 @@ spinar_penal_val <- function(x, p, validation, penal1 = NA, penal2 = NA, over =
if(is.na(penal2)){penal2 <- 0}
parameters <- spinar_penal(x, p, penal1, penal2)
} else{
assert_logical(validation)
assert(checkChoice(over, c("L1", "L2", "both")))
assert_integerish(folds, lower = 2, upper = floor((length(x)/(p+1))), len = 1)
assert_numeric(init1, len = 1)
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("Sum of n and prerun must be greater than 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)
}
}

16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# spINAR
[![status](https://joss.theoj.org/papers/6fcfcc77635fdd18153b35d5986fe2aa/status.svg)](https://github.com/openjournals/joss-reviews/issues/5152)
[![status](https://joss.theoj.org/papers/6fcfcc77635fdd18153b35d5986fe2aa/status.svg)](https://github.com/openjournals/joss-reviews/issues/5386)
[![CRAN](https://www.r-pkg.org/badges/version/spINAR)](https://cran.r-project.org/package=spINAR)
[![R build status](https://github.com/MFaymon/spINAR/workflows/R-CMD-check/badge.svg)](https://github.com/MFaymon/spINAR/actions)
[![codecov](https://codecov.io/gh/MFaymon/spINAR/branch/main/graph/badge.svg?token=U5KPFSY3XN)](https://app.codecov.io/gh/MFaymon/spINAR)
[![DOI](https://zenodo.org/badge/520425653.svg)](https://zenodo.org/badge/latestdoi/520425653)
Expand All @@ -10,10 +11,15 @@ The package provides flexible simulation of INAR data using a general pmf to def

## References (related to the methodology)

* Faymonville, M., Jentsch, C., Weiß, C.H. und Aleksandrov, B. (2022). Semiparametric Estimation of INAR Models using Roughness Penalization. Statistical Methods & Applications. [DOI](https://doi.org/10.1007/s10260-022-00655-0)
* Faymonville, M., Jentsch, C., Weiß, C.H. and Aleksandrov, B. (2022). "Semiparametric Estimation of INAR Models using Roughness Penalization". Statistical Methods & Applications. [DOI](https://doi.org/10.1007/s10260-022-00655-0)
* Jentsch, C. and Weiß, C.H. (2017), “Bootstrapping INAR Models”. Bernoulli 25(3), pp. 2359-2408. [DOI](https://doi.org/10.3150/18-BEJ1057)
* Drost, F., Van den Akker, R. and Werker, B. (2009), “Efficient estimation of auto-regression parameters and inovation distributions for semiparametric integer-valued AR(p) models”. Journal of the Royal Statistical Society. Series B 71(2), pp. 467-485. [DOI](https://doi.org/10.1111/j.1467-9868.2008.00687.x)

## Contribution
This R package is licensed under the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html).
For bug reports (lack of documentation, misleading or wrong documentation, unexpected behaviour, ...) and feature requests please use the [issue tracker](https://github.com/MFaymon/spINAR/issues).
Pull requests are welcome and will be included at the discretion of the author.

## Installation

For installation of the development version use [devtools](https://cran.r-project.org/package=devtools):
Expand Down Expand Up @@ -73,3 +79,9 @@ spinar_boot(dat1, 1, 500, setting = "sp")
spinar_boot(dat1, 1, 500, setting = "p", type = "mom", distr = "poi")
```

## Application
The file vignette.md provides reproduced results from the literature for each provided functionality of the spINAR package.

## Outlook

A possible extension of the spINAR package is to not only cover INAR models but also the extension to GINAR (generalized INAR) models, see [Latour (1997)](https://doi.org/10.1017/s0001867800027865). This model class does not only cover the binomial thinning but also allows for other thinning operations, e.g. thinning using geometrically distributed random variables.
Binary file added build/vignette.rds
Binary file not shown.
21 changes: 8 additions & 13 deletions inst/CITATION
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
citHeader("To cite spINAR in publications use:")

year = sub(".*(2[[:digit:]]{3})-.*", "\\1", meta$Date)
vers = paste("R package version", meta$Version)

bibentry(bibtype = "Manual",
title = "{spINAR}: Semiparametric and Parametric Estimation and Bootstrapping of Integer-Valued Autoregressive (INAR) Models",
bibentry(bibtype = "Article",
title = "{spINAR}: An {R} Package for Semiparametric and Parametric Estimation and Bootstrapping of Integer-Valued Autoregressive ({INAR}) Models",
author = "Maxime Faymonville and Javiera Riffo and Jonas Rieger and Carsten Jentsch",
year = year,
doi = "10.5281/zenodo.7611601",
year = "2024",
journal = "Journal of Open Source Software",
url = "https://github.com/MFaymon/spINAR",
note = vers,
textVersion =
paste("Faymonville et al. (", year, "). ",
"spINAR: Semiparametric and Parametric Estimation and Bootstrapping of Integer-Valued Autoregressive (INAR) Models. ",
vers, ". ",
"DOI: 10.5281/zenodo.7611601.", sep = "")
)
paste("Faymonville et al. (2024).",
"{spINAR}: An {R} Package for Semiparametric and Parametric Estimation and Bootstrapping of Integer-Valued Autoregressive ({INAR}) Models.",
"Journal of Open Source Software")
)

0 comments on commit e69ddd1

Please sign in to comment.