diff --git a/DESCRIPTION b/DESCRIPTION index 82e8f95..d89938d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,42 +1,44 @@ -Package: trngl Type: Package +Package: trngl Title: Bootstrap Simulations for Claims Reserving Models Version: 0.1.0 -Date: 2023-02-08 -Authors@R: c( +Authors@R: person("Othman", "El Hammouchi", , "othman.el.hammouchi@protonmail.com", role = c("aut", "cph", "cre")) - ) -Description: Check the assumptions of popular actuarial reserving models against a given claims triangle using - efficient parallel bootstrap simulations. Various simulation configurations are supported for the Mack and ODP models. - Facilities are provided for visualising the results and flagging suspicious observations. +Description: Check the assumptions of popular actuarial reserving models + against a given claims triangle using efficient parallel bootstrap + simulations. Various simulation configurations are supported for the + Mack and overdispersed Poisson models. Facilities are provided for visualising the + results and flagging suspicious observations. License: MIT + file LICENSE -Depends: R (>= 3.5.0) +Depends: + R (>= 3.5.0) Imports: - rTRNG (>= 4.23.1.2), ChainLadder (>= 0.2.18), + cli (>= 3.6.2), ggplot2 (>= 3.5.1), ggrepel (>= 0.9.5), reshape2 (>= 1.4.4), rlang (>= 1.1.3), - cli (>= 3.6.2) -LinkingTo: - Rcpp (>= 0.11.0), - RcppArmadillo (>= 0.12.8.2.1), - BH (>= 1.84.0.0), - rTRNG (>= 4.23.1.2), - RcppProgress (>= 0.4.2) + rTRNG (>= 4.23.1.2) Suggests: covr, testthat (>= 3.0.0), withr (>= 3.0.0) -LazyData: true +LinkingTo: + BH (>= 1.84.0.0), + Rcpp (>= 0.11.0), + RcppArmadillo (>= 0.12.8.2.1), + RcppProgress (>= 0.4.2), + rTRNG (>= 4.23.1.2) +Config/testthat/edition: 3 +Config/testthat/parallel: true Encoding: UTF-8 -RoxygenNote: 7.2.3 -Roxygen: list(load = "source", old_usage = TRUE, markdown = TRUE) +LazyData: true NeedsCompilation: yes Packaged: 2023-02-26 18:07:38 UTC; othman -Config/testthat/edition: 3 -Config/testthat/parallel: true +Roxygen: list(load = "source", old_usage = TRUE, markdown = TRUE) +RoxygenNote: 7.2.3 +SystemRequirements: Fortran 2003 Collate: 'RcppExports.R' 'boot_res.R' diff --git a/NAMESPACE b/NAMESPACE index 96a53d9..5ec16bd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,12 +13,6 @@ S3method(plot,single) S3method(print,mack) S3method(print,odp) S3method(print,trngl) -export(.mackPairsBoot) -export(.mackPairsSim) -export(.mackParamBoot) -export(.mackParamSim) -export(.mackResidBoot) -export(.mackResidSim) export(UKMotor) export(as.trngl) export(cum2incr) diff --git a/R/RcppExports.R b/R/RcppExports.R index 009d9d1..8bb17be 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -32,32 +32,26 @@ getTrnglSeed <- function() { .Call('_trngl_getTrnglSeed', PACKAGE = 'trngl') } -#' @export .mackParamBoot <- function(trngl, dist, cond, n_boot = 1e3L, n_sim = 1e3L, progress = TRUE) { .Call('_trngl_mackParamBoot', PACKAGE = 'trngl', trngl, dist, cond, n_boot, n_sim, progress) } -#' @export .mackResidBoot <- function(trngl, resid_type, cond, n_boot = 1e3L, n_sim = 1e3L, progress = TRUE) { .Call('_trngl_mackResidBoot', PACKAGE = 'trngl', trngl, resid_type, cond, n_boot, n_sim, progress) } -#' @export .mackPairsBoot <- function(trngl, n_boot = 1e3L, n_sim = 1e3L, progress = TRUE) { .Call('_trngl_mackPairsBoot', PACKAGE = 'trngl', trngl, n_boot, n_sim, progress) } -#' @export .mackPairsSim <- function(trngl, sim_type, n_boot, n_sim, progress) { .Call('_trngl_mackPairsSim', PACKAGE = 'trngl', trngl, sim_type, n_boot, n_sim, progress) } -#' @export .mackParamSim <- function(trngl, sim_type, cond, dist, n_boot, n_sim, progress) { .Call('_trngl_mackParamSim', PACKAGE = 'trngl', trngl, sim_type, cond, dist, n_boot, n_sim, progress) } -#' @export .mackResidSim <- function(trngl, sim_type, cond, resid_type, n_boot, n_sim, progress) { .Call('_trngl_mackResidSim', PACKAGE = 'trngl', trngl, sim_type, cond, resid_type, n_boot, n_sim, progress) } diff --git a/configure b/configure new file mode 100755 index 0000000..3f9a8d4 --- /dev/null +++ b/configure @@ -0,0 +1,42 @@ +#!/usr/bin/env sh + +cat < test-f03.f90 +module mod_test + implicit none + + type t_test + integer :: test_field + + contains + procedure :: set_test_field + end type t_test + +contains + subroutine set_test_field(this, val) + class(t_test) :: this + integer :: val + this%test_field = val + end subroutine set_test_field +end module mod_test + +program test + use mod_test + implicit none + + type(t_test) :: test_var + + call test_var%set_test_field(0) +end program test +EOF + +if ! "${R_HOME}"/bin/R CMD SHLIB test-f03.f90; then + echo "*********************************************************************************" + echo "Your Fortran compiler does not appear to support all features of the 2003" + echo "standard. Please install a compatible compiler, set this in your ~/.R/Makevars" + echo "and try again." + echo "*********************************************************************************" + + exit 1 +fi + +rm -f test-f03.* mod_test.* diff --git a/cran-comments.md b/cran-comments.md index 858617d..68c026f 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,3 +1,16 @@ +## Resubmission + +* Spelled out "ODP" as "overdispersed Poisson". + +* Removed erroneous export of internal package functions. + +* Removed the "Date" field in DESCRIPTION. + +* Added Fortran 2003 to "SystemRequirements" as well as a configure script that + checks whether the compiler supports this standard. + +* Remove erroneously included "Rplots.pdf". + ## R CMD check results 0 errors | 0 warnings | 1 note diff --git a/inst/include/mask.h b/inst/include/mask.h index a8f0744..1ecc871 100644 --- a/inst/include/mask.h +++ b/inst/include/mask.h @@ -6,6 +6,7 @@ class Mask { Mask(int n_row, int n_col) : n_row_(n_row), n_col_(n_col) { data_ = new bool[n_row * n_col]; + // column major for (int i = 0; i < n_row; i++) { for (int j = 0; j < n_col; j++) { if (j >= n_col - i) { @@ -16,15 +17,17 @@ class Mask { } } }; + Mask(int n_dev) : Mask(n_dev, n_dev){}; ~Mask() { delete[] data_; } bool* begin() { return data_; } - int n_row() { return n_row_; } - int n_col() { return n_col_; } - int size() { return n_row_ * n_col_; } + int n_row() const { return n_row_; } + int n_col() const { return n_col_; } + int size() const { return n_row_ * n_col_; } bool& operator()(int i, int j) { return data_[i + j * n_row_]; } + bool get(int i, int j) const { return data_[i + j * n_row_]; } class RowProxy { public: @@ -70,10 +73,10 @@ class Mask { } } - friend std::ostream& operator<<(std::ostream& os, Mask& mask) { + friend std::ostream& operator<<(std::ostream& os, const Mask& mask) { for (int i = 0; i < mask.n_row(); i++) { for (int j = 0; j < mask.n_col(); j++) { - os << (mask(i, j) ? "T" : "F") << " "; + os << (mask.get(i, j) ? "T" : "F") << " "; } os << std::endl; } diff --git a/src/mack.cpp b/src/mack.cpp index 459ed94..ad8bcd0 100644 --- a/src/mack.cpp +++ b/src/mack.cpp @@ -23,7 +23,6 @@ void mack_pairs_boot_cpp(int n_dev, double* triangle, int n_boot, int n_sim, bool* mask, double* reserve, void* pgb); } -//' @export // [[Rcpp::export(.mackParamBoot)]] Rcpp::List mackParamBoot(Rcpp::NumericMatrix trngl, Rcpp::String dist, bool cond, int n_boot = 1e3, int n_sim = 1e3, @@ -60,7 +59,6 @@ Rcpp::List mackParamBoot(Rcpp::NumericMatrix trngl, Rcpp::String dist, return res; }; -//' @export // [[Rcpp::export(.mackResidBoot)]] Rcpp::List mackResidBoot(Rcpp::NumericMatrix trngl, Rcpp::String resid_type, bool cond, int n_boot = 1e3, int n_sim = 1e3, @@ -96,7 +94,6 @@ Rcpp::List mackResidBoot(Rcpp::NumericMatrix trngl, Rcpp::String resid_type, return res; }; -//' @export // [[Rcpp::export(.mackPairsBoot)]] Rcpp::List mackPairsBoot(Rcpp::NumericMatrix trngl, int n_boot = 1e3, int n_sim = 1e3, bool progress = true) { @@ -305,20 +302,20 @@ Rcpp::List mackSim(arma::mat triangle, options::SimType sim_type, int n_boot, case options::ORIGIN: { if (progress) { pb = new CliProgressBar; - pgb = new Progress(n_dev * n_boot * n_sim, true, *pb); + pgb = new Progress((n_dev - 1) * n_boot * n_sim, true, *pb); } else { pb = nullptr; pgb = nullptr; } - reserves = arma::mat(n_boot * n_sim, n_dev); + reserves = arma::mat(n_boot * n_sim, n_dev - 1); // clang-format off #pragma omp parallel for num_threads(n_threads) default(none) \ shared(reserves, pgb, col_mapping_) \ firstprivate(boot_type, mask, triangle, n_boot, n_sim, n_dev) \ firstprivate(dist_type, resid_type, cond, progress) // clang-format on - for (int i = 0; i < n_dev; i++) { + for (int i = 0; i < n_dev - 1; i++) { bool abort_check; if (progress) { abort_check = !Progress::check_abort(); @@ -335,6 +332,7 @@ Rcpp::List mackSim(arma::mat triangle, options::SimType sim_type, int n_boot, Mask mask_in = mask; mask_in.row(i) = false; mask_in(i, 0) = true; + if (boot_type == options::PAIRS || boot_type == options::PARAM) mask_in(0, n_dev - 1) = true; @@ -387,7 +385,6 @@ Rcpp::List mackSim(arma::mat triangle, options::SimType sim_type, int n_boot, return res; }; -//' @export // [[Rcpp::export(.mackPairsSim)]] Rcpp::List mackPairsSim(Rcpp::NumericMatrix trngl, Rcpp::String sim_type, int n_boot, int n_sim, bool progress) { @@ -397,7 +394,6 @@ Rcpp::List mackPairsSim(Rcpp::NumericMatrix trngl, Rcpp::String sim_type, options::Dist::NORMAL, options::STANDARD); } -//' @export // [[Rcpp::export(.mackParamSim)]] Rcpp::List mackParamSim(Rcpp::NumericMatrix trngl, Rcpp::String sim_type, bool cond, Rcpp::String dist, int n_boot, int n_sim, @@ -408,7 +404,6 @@ Rcpp::List mackParamSim(Rcpp::NumericMatrix trngl, Rcpp::String sim_type, options::dist_mapping.at(dist), options::STANDARD); } -//' @export // [[Rcpp::export(.mackResidSim)]] Rcpp::List mackResidSim(Rcpp::NumericMatrix trngl, Rcpp::String sim_type, bool cond, Rcpp::String resid_type, int n_boot, diff --git a/tests/testthat/_snaps/calendar/sim_calendar.png b/tests/testthat/_snaps/calendar/sim_calendar.png index cc8b7f8..2876ded 100644 Binary files a/tests/testthat/_snaps/calendar/sim_calendar.png and b/tests/testthat/_snaps/calendar/sim_calendar.png differ diff --git a/tests/testthat/_snaps/origin/sim_origin.png b/tests/testthat/_snaps/origin/sim_origin.png index 3a2a998..4e501e7 100644 Binary files a/tests/testthat/_snaps/origin/sim_origin.png and b/tests/testthat/_snaps/origin/sim_origin.png differ diff --git a/tests/testthat/_snaps/single/sim_single.png b/tests/testthat/_snaps/single/sim_single.png index 4d522fb..9454150 100644 Binary files a/tests/testthat/_snaps/single/sim_single.png and b/tests/testthat/_snaps/single/sim_single.png differ