From fbe1aca07db5edd2b127ba988eafe4e4dfecc205 Mon Sep 17 00:00:00 2001 From: Georgi Boshnakov Date: Sun, 14 Jan 2024 19:30:48 +0000 Subject: [PATCH] v3.5.8 --- .Rbuildignore | 1 + DESCRIPTION | 13 ++++-- NAMESPACE | 8 +++- NEWS.md | 80 +++++++++++++++++++++------------- R/Countr-package.R | 38 +++++++++++----- R/RcppExports.R | 11 +++-- R/coefnames.R | 7 ++- R/probpredict.R | 60 +++++++++++++++++++++++++ R/renewal_methods.R | 47 ++++++++++---------- inst/REFERENCES.bib | 29 ++++++------ man/Countr-package.Rd | 11 ++--- man/addBootSampleObject.Rd | 2 +- man/chiSq_gof.Rd | 4 +- man/chiSq_pearson.Rd | 4 +- man/dCount_dePril_bi.Rd | 2 - man/dCount_naive_bi.Rd | 21 ++++++++- man/prob_predict.Rd | 25 +++++++++++ man/renewalCoef.Rd | 2 +- man/renewalCoefList.Rd | 3 ++ man/renewalNames.Rd | 3 ++ man/renewal_methods.Rd | 6 +-- man/residuals_plot.Rd | 2 +- man/se.coef.Rd | 6 +-- man/surv.Rd | 8 ++-- src/RcppExports.cpp | 33 ++++++++------ src/built_in_distributions.cpp | 8 ++-- src/conv_dePril.cpp | 1 - src/conv_naive.cpp | 2 +- 28 files changed, 295 insertions(+), 142 deletions(-) create mode 100644 R/probpredict.R create mode 100644 man/prob_predict.Rd diff --git a/.Rbuildignore b/.Rbuildignore index db62df0..59e0a57 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -13,3 +13,4 @@ README_devel.md ^sav[0-9]*[.]Rhistory ^\.github$ ^codecov\.yml$ +.rsync_exclude diff --git a/DESCRIPTION b/DESCRIPTION index 5ed16b0..ffede39 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: Countr Type: Package Title: Flexible Univariate Count Models Based on Renewal Processes -Version: 3.5.6.9000 +Version: 3.5.8 Authors@R: c( person(given = "Tarak", family = "Kharrat", role = c("aut"), email = "tarak@realanalytics.co.uk"), @@ -13,6 +13,10 @@ Description: Flexible univariate count models based on renewal processes. The syntax as in glm() and package 'flexsurv'. The methodology is described by Kharrat et all (2019) (included as vignette 'Countr_guide' in the package). + If the suggested package 'pscl' is not available from CRAN, it can be + installed with 'remotes::install_github("cran/pscl")'. It is no longer used + by the functions in this package but is needed for some of the extended + examples. License: GPL (>= 2) URL: https://geobosh.github.io/Countr/ (doc), https://github.com/GeoBosh/Countr (devel) BugReports: https://github.com/GeoBosh/Countr/issues @@ -35,17 +39,17 @@ Imports: RColorBrewer, dplyr, standardize, - pscl, lmtest, xtable LinkingTo: Rcpp, RcppArmadillo Suggests: testthat, - knitr + knitr, + pscl RdMacros: Rdpack VignetteBuilder: knitr LazyData: true -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 NeedsCompilation: yes Collate: 'Countr-package.R' @@ -58,6 +62,7 @@ Collate: 'dWeibull.R' 'dWeibullgamma.R' 'data.R' + 'probpredict.R' 'renewal_IV.R' 'renewal_tools.R' 'renewal_cstr.R' diff --git a/NAMESPACE b/NAMESPACE index be123b6..969b49e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,6 +17,7 @@ S3method(nobs,renewal) S3method(predict,renewal) S3method(print,renewal) S3method(print,summary.renewal) +S3method(prob_predict,glm) S3method(renewalCoef,default) S3method(renewalCoef,glm) S3method(renewalCoef,renewalCoefList) @@ -49,6 +50,7 @@ export(evWeibullCount) export(evWeibullgammaCount) export(frequency_plot) export(getParNames) +export(prob_predict) export(renewal) export(renewal.control) export(renewal.convPars) @@ -64,7 +66,6 @@ export(surv) import(Formula) import(Matrix) import(Rcpp) -import(dplyr) import(flexsurv) import(optimx) importFrom(MASS,ginv) @@ -76,13 +77,15 @@ importFrom(VGAM,logit) importFrom(VGAM,probit) importFrom(boot,boot) importFrom(car,Boot) +importFrom(dplyr,contains) +importFrom(dplyr,groups) +importFrom(dplyr,left_join) importFrom(graphics,par) importFrom(graphics,plot) importFrom(lattice,barchart) importFrom(lmtest,lrtest) importFrom(numDeriv,hessian) importFrom(numDeriv,jacobian) -importFrom(pscl,predprob) importFrom(standardize,standardize) importFrom(stats,AIC) importFrom(stats,as.formula) @@ -92,6 +95,7 @@ importFrom(stats,confint.default) importFrom(stats,density) importFrom(stats,dnbinom) importFrom(stats,dpois) +importFrom(stats,family) importFrom(stats,formula) importFrom(stats,getCall) importFrom(stats,glm.fit) diff --git a/NEWS.md b/NEWS.md index cb47e0b..7ca44d4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,22 @@ -# Countr 3.5.6 (CRAN) +# Countr 3.5.8 + +- This is an emergency release to keep the package on CRAN in case the scheduled + archival of package 'pscl' happens. + +# Countr 3.5.7 + +- a missing '@' symbol had caused roxygen to generate items for 'inheritParams' + in the arguments section of a couple of Rd files. + +- fixed new warnings from the C++ compiler like ' RcppExports.cpp:528:18: + warning: format string is not a string literal (potentially insecure) + [-Wformat-security]'. + +- now import selectively from 'dplyr'. Also, see the 'todo' note in + 'Countr-package.R'. + + +# Countr 3.5.6 - several documentation files had duplicated descriptions of some arguments. @@ -10,21 +28,21 @@ - switched from travisci to github actions. -# Countr 3.5.5 (CRAN) +# Countr 3.5.5 - changed maintainer. - fixed a doi reference in DESCRIPTION to be in proper format. -# Countr 3.5.4 (CRAN) +# Countr 3.5.4 - fixed wrong links in inst/doc/index.html. -# Countr 3.5.3 +# Countr 3.5.3 (not on CRAN) -- consolidation after the refactoring of the reposotory. +- consolidation after the refactoring of the repository. - created pkgdown website. @@ -36,7 +54,7 @@ JSS paper. -# Countr 3.5.2 (CRAN) +# Countr 3.5.2 - small adjustments before submission. @@ -45,31 +63,31 @@ - updated the main vignette with the accepted version of the JSS paper. -# Countr 3.5.0 +# Countr 3.5.0 (not on CRAN) - now covariates for ancilliary parameters for the renewal regression model can be specified as part of argument 'formula'. This uses the extended formulas provided by package `Formula`. The syntax with argument `anc` remains available. -# Countr 3.4.3 +# Countr 3.4.3 (not on CRAN) - dealt with warnigs from the compiler about unused variables (and a few others). - When there is no precomputed bootstrap sample in the object, `se.coef.renewal()` now prints a slightly more informative message without raising a warning. -# Countr 3.4.2 +# Countr 3.4.2 (not on CRAN) - fixed the url's in the references for the vignettes in REFERENCES.bib. -# Countr 3.4.1 (2017-11-20) +# Countr 3.4.1 (CRAN 2017-11-20) - bugs fixed in convolution methods. - option added to rescale covariates (standardise, standardise_scale). - new vignettes added + many examples with different datasets fitted. - Bibtex entries for citation of the vignettes added to REFERENCES.bib. - numerous small improvements throughout the package. -# Countr 3.3.1 +# Countr 3.3.1 (not on CRAN) - new `type = "prob"` for residuals - changes in `residuals.renewal`, `.objectiveFunction` and `renewal()`. Comments and asome examples are temporarily put in the documentation of `renewal()`. @@ -77,10 +95,10 @@ probability computing functions to specify whether logged values are required when `summa = FALSE`. -# Countr 3.3.0 +# Countr 3.3.0 (not on CRAN) - first changes on bitbucket. -# Countr 3.2.8 (2016-12-20) +# Countr 3.2.8 (CRAN 2016-12-20) - the call in the printout of renewal objects (and `summary()`) could be very wide (annoying in Sweave output), now `print.renewal()` and `print.summary.renewal()` obey 'width' when possible (see helper function @@ -88,62 +106,62 @@ - bugs corrected in `print.summary.renewal()` when failure to compute variance or residuals. -# Countr 3.2.7 (2016-10-06) +# Countr 3.2.7 (CRAN 2016-10-06) - fixed some bugs in printing methods. - added a jss_paper vignette. -# Countr 3.2.6 (2016-09-14) +# Countr 3.2.6 (CRAN 2016-09-14) -# Countr 3.2.4 +# Countr 3.2.4 (not on CRAN) - merged changes done separately by T. and G. to Version 3.2.2. - fixed some bugs introduced in 3.2.3. -# Countr 3.2.3 +# Countr 3.2.3 (not on CRAN) - all count functions vectorized in c++. - likelihood functions improved. -# Countr 3.2.2 +# Countr 3.2.2 (not on CRAN) - minor bug fixed in `.checkInitialValues` in the anc parameters. - all bivariate functionalities removed. - fertility dataset now exported with data(). -# Countr 3.2.1 +# Countr 3.2.1 (not on CRAN) - minor bugs fixed in `.objectiveFunction` and predict with std.error. - last location "/..." vectorial parameters returned. - sign in the Frank Copula package changed to be more consistent with the intuitive results: theta <0 -> negative dependence. -# Countr 3.2.0 (2016-03-23) +# Countr 3.2.0 (CRAN 2016-03-23) - consolidated the documentation. -- to be first CRAN version. +- first CRAN version. -# Countr 3.1.x +# Countr 3.1.x (not on CRAN) - clean-up for CRAN submission. -# Countr 3.0.0 +# Countr 3.0.0 (not on CRAN) - renewal constructor + formula + methods. - dePril convolution added. - changed the way built in distributions are called. -# Countr 2.0.3 +# Countr 2.0.3 (not on CRAN) - inclusion of covariates using formula. - Burr (weibull-gamma) distribution added. - delayed first arrival included. -# Countr 2.0.1 +# Countr 2.0.1 (not on CRAN) - dePril convolution option added. -# Countr 2.0.0 +# Countr 2.0.0 (not on CRAN) - header files added taking advantage of Rcpp attributes. - `conv_utils.cpp` added (contains the convolution general methods). - weibull, gamma, gengamma counting processes added. - option to add user based inter-arrival times distribution using routines `getProbs_directConv`, `getProbs_minConv`; see tests for examples. -# Countr 1.1.9 +# Countr 1.1.9 (not on CRAN) - incorporated the convolution computations from Tarak's paper. -# Countr 1.1.8 +# Countr 1.1.8 (not on CRAN) - introduced file `.Rbuildignore` in the root directory of the package. - shortened the name of subdirectory 'Euler-van ...' to remove the complaint from 'R CMD build' about long paths. Also, to remove the warning by 'R CMD @@ -153,7 +171,7 @@ - completed the roxigen argument descriptions (in the sense that 'R CMD check' doesn't complain). -# Countr 1.1.7 +# Countr 1.1.7 (not on CRAN) - `gam_weiH` and `gam_weiA` renamed `ccX` and `ccY`. - vectorial version `dWeibullInterArrivalCountInd` and `dWeibullInterArrivalCountFrankCopula` improved. @@ -163,14 +181,14 @@ - tests added for bivariate vectorial functions. - `cRes` object removed from "R/" to free some space. -# Countr 1.1.5 +# Countr 1.1.5 (not on CRAN) - pkg renamed from BivCount to Countr. - `alphagen2` changed to `alphagen`. - oldCpp file removed. - gamma-heterogeneity functions added to the original and fast version. - covariates-heterogeneity functions added to the original and fast version. -# Countr 1.1.0 +# Countr 1.1.0 (not on CRAN) - renamed `alphagen` to `alphagenOrig`. - the signatures of the cpp functions now have namespace prefixes for namespaces other than Rcpp. In this way RcppExports.cpp does not need `using namespace diff --git a/R/Countr-package.R b/R/Countr-package.R index d847019..42d3013 100644 --- a/R/Countr-package.R +++ b/R/Countr-package.R @@ -12,7 +12,8 @@ #' #' @useDynLib Countr #' -#' @import Matrix Rcpp Formula flexsurv dplyr +#' @import Matrix Rcpp Formula flexsurv +#' #' @importFrom stats nobs AIC coef confint confint.default #' @importFrom stats formula as.formula getCall glm.fit logLik model.frame #' @importFrom stats model.matrix model.response model.weights @@ -20,22 +21,27 @@ #' @importFrom stats dnbinom dpois lm pchisq #' @importFrom stats residuals update.formula vcov #' @importFrom stats density predict qqline qqnorm terms.formula +#' #' @importFrom graphics par plot +#' @importFrom utils capture.output +#' +#' @importFrom standardize standardize +#' @importFrom dplyr left_join contains groups #' @importFrom RColorBrewer brewer.pal +#' @importFrom Rdpack reprompt +#' #' @importFrom lattice barchart #' @importFrom car Boot -#' @importFrom Rdpack reprompt -#' @importFrom utils capture.output -#' @importFrom standardize standardize #' @importFrom lmtest lrtest #' @importFrom xtable xtable #' +#' @importFrom stats family +#' #' @details #' -#' The methodology is described in the forthcoming paper -#' \insertCiteOnly{CountrJssArticle}{Countr} -#' in the Journal of Statistical Software (included in the package as vignette -#' \code{vignette('Countr_guide_paper', package = "Countr")}). +#' The methodology is described by +#' \insertCiteOnly{CountrJssArticle;textual}{Countr}. The paper is included in +#' the package as vignette \code{vignette('Countr_guide_paper', package = "Countr")}). #' #' The main function is \code{\link{renewalCount}}, see its documentation for #' examples. @@ -46,16 +52,14 @@ #' #' @references #' -#' \insertRef{CountrJssArticle}{Countr} -#' #' \insertRef{baker2017event}{Countr} #' #' \insertRef{boshnakov2017bivariate}{Countr} #' #' \insertRef{cameron2013regression}{Countr} #' -#' \insertRef{TarakEtAl2018jss}{Countr} -#' +#' \insertRef{CountrJssArticle}{Countr} +#' #' \insertRef{mcshane2008count}{Countr} #' #' \insertRef{winkelmann1995duration}{Countr} @@ -67,3 +71,13 @@ utils::globalVariables( c("Counts", "Actual" # see compareToGLM() ) ) +## (jan 2023) *TODO*: maybe "groups" should be added to utils::globalVariables +## (and not imported from 'dplyr', see the call +## lattice::barchart(preds ~ count_range, data = df, groups = groups, ... +## in frequency_plot(). +## Rcheck doesn't complain about undefined variable 'groups' since there is a +## function groups() in 'dplyr'. However, at first sight at least, it seems that +## in 'group = groups' the right-hand side is the name of the column in the data +## frame as symbol. When checking, note that the above call invokes the formula +## method of lattice::barchart and see also the panel function +## lattice::panel.barchart() diff --git a/R/RcppExports.R b/R/RcppExports.R index fb09afe..02c6459 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -21,9 +21,9 @@ sgengamma <- function(t, distPars) { .Call('_Countr_sgengamma', PACKAGE = 'Countr', t, distPars) } -#' Wrapper to built in survival functions +#' Wrapper to built-in survival functions #' -#' Wrapper to built in survival functions +#' Wrapper to built-in survival functions #' #' The function wraps all builtin-survival distributions. User can choose #' between the \code{weibull}, \code{gamma}, \code{gengamma}(generalized gamma) @@ -43,8 +43,8 @@ sgengamma <- function(t, distPars) { #' @param distPars \code{Rcpp::List} with distribution specific slots, #' see details. #' @param dist character name of the built-in distribution, see details. -#' @return a double giving the value of the survival function at time point -#' \code{t} at the parameters' values. +#' @return a double, giving the value of the survival function at time point +#' \code{t} at the parameters' values. #' #' @examples #' tt <- 2.5 @@ -149,7 +149,6 @@ dCount_allProbs_vec_user <- function(x, distPars, extrapolPars, survR, nsteps = #' Richardson extrapolation if \code{extrap} is \code{TRUE} using the #' algorithm of section 3.2. #' -#' @param inheritParams dCount_naive_bi #' @return vector of probabilities P(x(i)) for i = 1, ..., n where n is #' \code{length} of \code{x}. #' @@ -206,7 +205,7 @@ dCount_dePril_vec_user <- function(x, distPars, extrapolPars, survR, nsteps = 10 #' #' @param cdfout logical if \code{TRUE}, the cdf will be returned instead of #' the count probability. -#' @param inheritParams dCount_allProbs_bi +#' @inheritParams dCount_allProbs_bi #' @return vector of probabilities P(x(i)) for i = 1, ..., n where n is #' \code{length} of \code{x}. #' diff --git a/R/coefnames.R b/R/coefnames.R index 1308403..3abb1f3 100644 --- a/R/coefnames.R +++ b/R/coefnames.R @@ -33,7 +33,7 @@ #' @param object an object, there are methods for several classes, see Details. #' @param ... further arguments to be passed to \code{renewalNames}, usually #' something like \code{target = "weibull"}. -#' @seealso renewalNames +#' @seealso \code{\link{renewalNames}} #' #' @references #' \insertRef{CountrJssArticle}{Countr} @@ -91,6 +91,9 @@ renewalCoef.renewalCoefList <- function(object, ...) { #' this list back to a vector. #' #' @param coef a named vector +#' +#' @seealso \code{\link{renewalNames}}, \code{\link{renewalCoef}} +#' #' @export renewalCoefList <- function(coef) { m <- regexpr("^[^_]+_", names(coef)) @@ -125,6 +128,8 @@ renewalCoefList <- function(coef) { #' #' @param object an object. #' @param ... further arguments. +#' +#' @seealso \code{\link{renewalCoefList}}, \code{\link{renewalCoef}} #' @export renewalNames <- function(object, ...) { UseMethod("renewalNames", object) diff --git a/R/probpredict.R b/R/probpredict.R new file mode 100644 index 0000000..240f756 --- /dev/null +++ b/R/probpredict.R @@ -0,0 +1,60 @@ +## replacement for pscl::predprob() +## only the glm method implemented. + +## TODO: could write a method for class 'renewal' just passing on to predict() +## with type = "prob" + +#' Probability predictions +#' +#' Compute probability predictions for discrete distribution models. +#' +#' This is an emergency replacement for pscl::predprob, since package 'pscl is +#' scheduled for removal from CRAN (in a couple of weeks) at the time of writing +#' this (2024-01-13). +#' +#' The function is exported but currently marked as internal, since the +#' arguments may be changed. When it is stable, it will be documented fully. +#' @param obj object from a supported class. +#' @param ... further arguments for methods +#' @keywords internal +#' @export +prob_predict <- function(obj, ...){ + UseMethod("prob_predict") +} + +#' @method prob_predict glm +#' @export +prob_predict.glm <- function(obj, newdata = NULL, at = NULL, ...){ + if(!inherits(obj, "glm")) + stop("'obj' must inherit from class 'glm'\n") + + yhat <- if(is.null(newdata)) + predict(obj, type = "response") + else + predict(obj, newdata = newdata, type = "response") + + fam <- family(obj)$family + + if(fam == "binomial") { + p <- structure(cbind(1 - yhat, yhat), + dimnames = list(NULL, c("0", "1"))) + } else { + ## y <- obj$y + if(is.null(at)) + at <- 0:max(obj$y) + + p <- structure(matrix(NA_real_, length(yhat), length(at)), + dimnames = list(NULL, at)) + + if(inherits(obj, "negbin")) { + for(i in seq_along(at)) + p[ , i] <- dnbinom(x = at[i], size = obj$theta, mu = yhat) + } else if(fam == "poisson") { + for(i in seq_along(at)) + p[ , i] <- dpois(x = at[i], lambda = yhat) + } else + stop("unsupported glm family '", fam, "'") + } + + p +} diff --git a/R/renewal_methods.R b/R/renewal_methods.R index 01ac42d..d4f1af1 100644 --- a/R/renewal_methods.R +++ b/R/renewal_methods.R @@ -23,10 +23,10 @@ NULL #' Extract Standard Errors of Model Coefficients #' #' Extract standard errors of model coefficients from objects returned by -#' count-modeling functions. +#' count modeling functions. #' -#' @param object object returned by one of the count-modeling functions -#' @param parm parameter's name or index +#' @param object an object returned by one of the count modeling functions. +#' @param parm parameter's name or index. #' @param type type of standard error: asymtotic normal standard errors #' (\code{"asymptotic"}) or bootsrap (\code{"boot"}). #' @param ... further arguments for methods. @@ -50,9 +50,9 @@ se.coef <- function(object, parm, type, ...) { #' for many of the familiar functions for interacting with fitted models. #' #' @param object an object from class \code{"renewal"}. -#' @param ... further arguments for methods +#' @param ... further arguments for methods. #' @param type,parm,level,bootType,x,digits see the corresponding generics and section -#' Details. +#' \sQuote{Details}. #' #' @examples #' fn <- system.file("extdata", "McShane_Wei_results_boot.RDS", package = "Countr") @@ -88,11 +88,11 @@ coef.renewal <- function(object, ...) { #' @rdname renewal_methods #' @method vcov renewal -## #' @param object object from class \code{renewal()} +## #' @param object object from class \code{renewal()}. ## #' @param ... extra parameters to be passed. user can pass parameter -## #' \code{method} with option \code{asymptotic} (numerical hessian) or -## #' \code{boot} (bootsrap). The other parameters will be passed to the \code{boot} -## #' function called inside \code{addBootSampleObject()}. +## #' \code{method} with option \code{asymptotic} (numerical hessian) or +## #' \code{boot} (bootsrap). The other parameters will be passed to the \code{boot} +## #' function called inside \code{addBootSampleObject()}. #' @export vcov.renewal <- function(object, ...) { v <- object$vcov @@ -163,7 +163,7 @@ residuals.renewal <- function (object, type = c("pearson", "response", #' #' A method to visualise the residuals #' -#' @param object object returned by one of the count-modeling functions +#' @param object object returned by one of the count modeling functions. #' @param type character type of residuals to be used. #' @param ... further arguments for methods. #' @@ -355,7 +355,7 @@ print.renewal <- function(x, digits = max(3, getOption("digits") - 3), ...) { #' @rdname renewal_methods #' @method print summary.renewal -#' @param width numeric width length +#' @param width numeric width length. #' @export print.summary.renewal <- function(x, digits = max(3, getOption("digits") - 3), width = getOption("width"), @@ -431,8 +431,8 @@ model.matrix.renewal <- function(object, ...) { } ## \code{logLik} method for class \code{renewal} -## @param object an object from class \code{renewal} -## @param ... not used +## @param object an object from class \code{renewal}. +## @param ... not used. #' @method logLik renewal #' @rdname renewal_methods #' @export @@ -442,8 +442,8 @@ logLik.renewal <- function (object, ...) { } ## \code{nobs} method for class \code{renewal} -## @param object an object from class \code{renewal} -## @param ... not used +## @param object an object from class \code{renewal}. +## @param ... not used. #' @method nobs renewal #' @examples #' ## see renewal_methods @@ -620,7 +620,7 @@ predict.renewal <- function(object, newdata = NULL, type = c("response", "prob") #' The bootstrap sample is stored in \code{object} as component \code{"boot"}. #' Arguments in \code{"..."} can be used customise the \code{boot()} call. #' -#' @param object an object to add boot object to +#' @param object an object to add boot object to. #' @param ... extra parameters to be passed to the \code{boot::boot()} function #' other than \code{data} and \code{statistic}. #' @return \code{object} with additional component \code{"boot"} @@ -739,8 +739,8 @@ update.renewal <- function(object, formula., anc, ..., evaluate = TRUE) { #' to the Pearson's chi-square test statistic is reported. The idea is to check if #' the fitted model has a tendancy to over or under predict some ranges of data #' -#' @param object an object from class \code{renewal} -#' @param ... currently not used +#' @param object an object from class \code{renewal}. +#' @param ... currently not used. #' @return data.frame with 5 columns given the count values (\code{Counts}), #' observed frequencies (\code{Actual}), model's prediction #' (\code{Predicted}), the difference (\code{Diff}) and the contribution to @@ -793,7 +793,6 @@ chiSq_pearson.renewal <- function (object, ...) { #' @rdname chiSq_pearson #' @method chiSq_pearson glm -#' @importFrom pscl predprob #' @export chiSq_pearson.glm <- function (object, ...) { ## compute empirical frequencies @@ -802,7 +801,7 @@ chiSq_pearson.glm <- function (object, ...) { obs_freq <- as.numeric(tab) / length(object$y) ## compute fitted frequncy - pbs <- pscl::predprob(object)[, as.character(count)] + pbs <- prob_predict(object)[, as.character(count)] fitted_freq <- colMeans(pbs) ## error computation @@ -828,11 +827,11 @@ chiSq_pearson.glm <- function (object, ...) { #' Section 5.3.4). We compute the asymptotically equivalent outer product of the #' gradient version which is justified for renewal models (fully parametric + #' parameters based on MLE). -#' @param object an object from class \code{renewal} +#' @param object an object from class \code{renewal}. #' @param breaks integer values at which the breaks shoudl happen. The function #' will compute the observed frequencies in the intervals \code{[breaks[i], #' breaks[i + 1])}. -#' @param ... currently not used +#' @param ... currently not used. #' @return data.frame #' @seealso \code{\link{chiSq_pearson}} #' @references \insertRef{cameron2013regression}{Countr} @@ -911,7 +910,7 @@ chiSq_gof.negbin <- function (object, breaks, ...) { ## compute the d_{ij}(y_i) - p_{ij}(x_i, \theta), for j in 1, ..., J -1 ## --- compute pij - pij <- pscl::predprob(object) + pij <- prob_predict(object) if (!missing(breaks)) pij <- .adjust_breaks(breaks, res, pij) @@ -951,7 +950,7 @@ chiSq_gof.glm <- function (object, breaks, ...) { ## compute the d_{ij}(y_i) - p_{ij}(x_i, \theta), for j in 1, ..., J -1 ## --- compute pij - pij <- pscl::predprob(object) + pij <- prob_predict(object) if (!missing(breaks)) pij <- .adjust_breaks(breaks, res, pij) diff --git a/inst/REFERENCES.bib b/inst/REFERENCES.bib index d24f924..dc3f54a 100644 --- a/inst/REFERENCES.bib +++ b/inst/REFERENCES.bib @@ -9,13 +9,6 @@ @Article{CountrJssArticle doi = {10.18637/jss.v090.i13}, } -@Article{TarakEtAl2018jss, - title = {Flexible regression models for count data based on renewal processes: the Countr package}, - author = {Tarak Kharrat and Georgi N. Boshnakov and McHale, Ian G and Baker, Rose}, - journal = {Journal of Statistical Software (to appear)}, - year = {2018}, -} - @article{winkelmann1995duration, title={Duration dependence and dispersion in count-data models}, author={Winkelmann, Rainer}, @@ -39,19 +32,27 @@ @article{mcshane2008count } @article{baker2017event, - title={Event count distributions from renewal processes: fast computation}, - author={Baker, Rose and Kharrat, Tarak}, - journal={IMA Journal of Management Mathematics}, - year={2017}, - publisher={Oxford University Press} + author = {Baker, Rose and Kharrat, Tarak}, + title = "{Event count distributions from renewal processes: fast computation of probabilities}", + journal = {IMA Journal of Management Mathematics}, + volume = {29}, + number = {4}, + pages = {415-433}, + year = {2017}, + month = {08}, + issn = {1471-678X}, + doi = {10.1093/imaman/dpx008}, + url = {https://doi.org/10.1093/imaman/dpx008}, + eprint = {https://academic.oup.com/imaman/article-pdf/29/4/415/25693854/dpx008.pdf}, } + @book{cameron2013regression, - title={Regression analysis of count data}, + title={Regression Analysis of Count Data}, author={Cameron, A Colin and Trivedi, Pravin K}, volume={53}, year={2013}, - publisher={Cambridge university press} + publisher={Cambridge University Press} } @article{boshnakov2017bivariate, diff --git a/man/Countr-package.Rd b/man/Countr-package.Rd index ed28554..17807c0 100644 --- a/man/Countr-package.Rd +++ b/man/Countr-package.Rd @@ -11,10 +11,9 @@ processes. The models may include covariates and can be specified with familiar formula syntax as in glm() and 'flexsurv'. } \details{ -The methodology is described in the forthcoming paper -\insertCiteOnly{CountrJssArticle}{Countr} -in the Journal of Statistical Software (included in the package as vignette -\code{vignette('Countr_guide_paper', package = "Countr")}). +The methodology is described by +\insertCiteOnly{CountrJssArticle;textual}{Countr}. The paper is included in +the package as vignette \code{vignette('Countr_guide_paper', package = "Countr")}). The main function is \code{\link{renewalCount}}, see its documentation for examples. @@ -24,15 +23,13 @@ count renewal models are implemented in \code{\link{chiSq_gof}} and \code{\link{chiSq_pearson}}. } \references{ -\insertRef{CountrJssArticle}{Countr} - \insertRef{baker2017event}{Countr} \insertRef{boshnakov2017bivariate}{Countr} \insertRef{cameron2013regression}{Countr} -\insertRef{TarakEtAl2018jss}{Countr} +\insertRef{CountrJssArticle}{Countr} \insertRef{mcshane2008count}{Countr} diff --git a/man/addBootSampleObject.Rd b/man/addBootSampleObject.Rd index d3b5d2d..b1d954a 100644 --- a/man/addBootSampleObject.Rd +++ b/man/addBootSampleObject.Rd @@ -7,7 +7,7 @@ addBootSampleObject(object, ...) } \arguments{ -\item{object}{an object to add boot object to} +\item{object}{an object to add boot object to.} \item{...}{extra parameters to be passed to the \code{boot::boot()} function other than \code{data} and \code{statistic}.} diff --git a/man/chiSq_gof.Rd b/man/chiSq_gof.Rd index 2af8d2e..3e62b8c 100644 --- a/man/chiSq_gof.Rd +++ b/man/chiSq_gof.Rd @@ -16,13 +16,13 @@ chiSq_gof(object, breaks, ...) \method{chiSq_gof}{glm}(object, breaks, ...) } \arguments{ -\item{object}{an object from class \code{renewal}} +\item{object}{an object from class \code{renewal}.} \item{breaks}{integer values at which the breaks shoudl happen. The function will compute the observed frequencies in the intervals \code{[breaks[i], breaks[i + 1])}.} -\item{...}{currently not used} +\item{...}{currently not used.} } \value{ data.frame diff --git a/man/chiSq_pearson.Rd b/man/chiSq_pearson.Rd index 732a729..4faed2f 100644 --- a/man/chiSq_pearson.Rd +++ b/man/chiSq_pearson.Rd @@ -13,9 +13,9 @@ chiSq_pearson(object, ...) \method{chiSq_pearson}{glm}(object, ...) } \arguments{ -\item{object}{an object from class \code{renewal}} +\item{object}{an object from class \code{renewal}.} -\item{...}{currently not used} +\item{...}{currently not used.} } \value{ data.frame with 5 columns given the count values (\code{Counts}), diff --git a/man/dCount_dePril_bi.Rd b/man/dCount_dePril_bi.Rd index 777497f..7098364 100644 --- a/man/dCount_dePril_bi.Rd +++ b/man/dCount_dePril_bi.Rd @@ -33,8 +33,6 @@ dCount_dePril_user( signature \code{function(t, distPars)} where \code{t} is a real number (>0) where the survival function is evaluated and \code{distPars} is a list of distribution parameters. It should return a double value.} - -\item{inheritParams}{dCount_naive_bi} } \value{ vector of probabilities P(x(i)) for i = 1, ..., n where n is diff --git a/man/dCount_naive_bi.Rd b/man/dCount_naive_bi.Rd index 5d3e51a..81aaa0c 100644 --- a/man/dCount_naive_bi.Rd +++ b/man/dCount_naive_bi.Rd @@ -29,15 +29,32 @@ dCount_naive_user( ) } \arguments{ +\item{x}{integer (vector), the desired count values.} + +\item{distPars}{\code{Rcpp::List} with distribution specific slots, +see details.} + +\item{dist}{character name of the built-in distribution, see details.} + +\item{nsteps}{unsiged integer number of steps used to compute the integral.} + +\item{time}{double time at wich to compute the probabilities. Set to 1 by +default.} + +\item{extrap}{logical if \code{TRUE}, Richardson extrapolation will be +applied to improve accuracy.} + \item{cdfout}{logical if \code{TRUE}, the cdf will be returned instead of the count probability.} +\item{logFlag}{logical if \code{TRUE} the log-probability will be returned.} + +\item{extrapolPars}{ma::vec of length 2. The extrapolation values.} + \item{survR}{Rcpp::Function user passed survival function; should have the signature \code{function(t, distPars)} where \code{t} is a real number (>0) where the survival function is evaluated and \code{distPars} is a list of distribution parameters. It should return a double value.} - -\item{inheritParams}{dCount_allProbs_bi} } \value{ vector of probabilities P(x(i)) for i = 1, ..., n where n is diff --git a/man/prob_predict.Rd b/man/prob_predict.Rd new file mode 100644 index 0000000..d731e9e --- /dev/null +++ b/man/prob_predict.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/probpredict.R +\name{prob_predict} +\alias{prob_predict} +\title{Probability predictions} +\usage{ +prob_predict(obj, ...) +} +\arguments{ +\item{obj}{object from a supported class.} + +\item{...}{further arguments for methods} +} +\description{ +Compute probability predictions for discrete distribution models. +} +\details{ +This is an emergency replacement for pscl::predprob, since package 'pscl is +scheduled for removal from CRAN (in a couple of weeks) at the time of writing +this (2024-01-13). + +The function is exported but currently marked as internal, since the +arguments may be changed. When it is stable, it will be documented fully. +} +\keyword{internal} diff --git a/man/renewalCoef.Rd b/man/renewalCoef.Rd index 9e2fbdd..b77f929 100644 --- a/man/renewalCoef.Rd +++ b/man/renewalCoef.Rd @@ -48,5 +48,5 @@ simply concatenated in one long vector. \insertRef{CountrJssArticle}{Countr} } \seealso{ -renewalNames +\code{\link{renewalNames}} } diff --git a/man/renewalCoefList.Rd b/man/renewalCoefList.Rd index 55ca742..1ada2f2 100644 --- a/man/renewalCoefList.Rd +++ b/man/renewalCoefList.Rd @@ -23,3 +23,6 @@ This is a convenience function allowing users to manipulate the coefficients related to a parameter more easily. \code{\link{renewalCoef}} can convert this list back to a vector. } +\seealso{ +\code{\link{renewalNames}}, \code{\link{renewalCoef}} +} diff --git a/man/renewalNames.Rd b/man/renewalNames.Rd index d347f6e..1f2e29d 100644 --- a/man/renewalNames.Rd +++ b/man/renewalNames.Rd @@ -26,3 +26,6 @@ is the same that would be used to call \code{renewalCount}. In this case \code{renewalNames} returns the names that would be used by renewalCount for the coefficients of the fitted model. } +\seealso{ +\code{\link{renewalCoefList}}, \code{\link{renewalCoef}} +} diff --git a/man/renewal_methods.Rd b/man/renewal_methods.Rd index 15f169e..937ad9b 100644 --- a/man/renewal_methods.Rd +++ b/man/renewal_methods.Rd @@ -64,12 +64,12 @@ \arguments{ \item{object}{an object from class \code{"renewal"}.} -\item{...}{further arguments for methods} +\item{...}{further arguments for methods.} \item{type, parm, level, bootType, x, digits}{see the corresponding generics and section -Details.} +\sQuote{Details}.} -\item{width}{numeric width length} +\item{width}{numeric width length.} \item{fit, scale, k}{same as in the generic.} } diff --git a/man/residuals_plot.Rd b/man/residuals_plot.Rd index 544fbe8..eb59f4c 100644 --- a/man/residuals_plot.Rd +++ b/man/residuals_plot.Rd @@ -7,7 +7,7 @@ residuals_plot(object, type, ...) } \arguments{ -\item{object}{object returned by one of the count-modeling functions} +\item{object}{object returned by one of the count modeling functions.} \item{type}{character type of residuals to be used.} diff --git a/man/se.coef.Rd b/man/se.coef.Rd index 05fdaee..c94cdf2 100644 --- a/man/se.coef.Rd +++ b/man/se.coef.Rd @@ -10,9 +10,9 @@ se.coef(object, parm, type, ...) \method{se.coef}{renewal}(object, parm, type = c("asymptotic", "boot"), ...) } \arguments{ -\item{object}{object returned by one of the count-modeling functions} +\item{object}{an object returned by one of the count modeling functions.} -\item{parm}{parameter's name or index} +\item{parm}{parameter's name or index.} \item{type}{type of standard error: asymtotic normal standard errors (\code{"asymptotic"}) or bootsrap (\code{"boot"}).} @@ -24,7 +24,7 @@ a named numeric vector } \description{ Extract standard errors of model coefficients from objects returned by -count-modeling functions. +count modeling functions. % Extract Standard Errors of Model Coefficients } diff --git a/man/surv.Rd b/man/surv.Rd index 6b3437d..6f0f93a 100644 --- a/man/surv.Rd +++ b/man/surv.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/RcppExports.R \name{surv} \alias{surv} -\title{Wrapper to built in survival functions} +\title{Wrapper to built-in survival functions} \usage{ surv(t, distPars, dist) } @@ -15,11 +15,11 @@ see details.} \item{dist}{character name of the built-in distribution, see details.} } \value{ -a double giving the value of the survival function at time point -\code{t} at the parameters' values. +a double, giving the value of the survival function at time point + \code{t} at the parameters' values. } \description{ -Wrapper to built in survival functions +Wrapper to built-in survival functions } \details{ The function wraps all builtin-survival distributions. User can choose diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 1c6753f..788634b 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -10,6 +10,11 @@ using namespace Rcpp; +#ifdef RCPP_USE_GLOBAL_ROSTREAM +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); +#endif + // sWeibull double sWeibull(double t, const Rcpp::List distPars); RcppExport SEXP _Countr_sWeibull(SEXP tSEXP, SEXP distParsSEXP) { @@ -525,7 +530,7 @@ RcppExport SEXP _Countr_dWeibullgammaCount_mat(SEXP xSEXP, SEXP shapeSEXP, SEXP if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -565,7 +570,7 @@ RcppExport SEXP _Countr_dWeibullgammaCount_mat_vec(SEXP xSEXP, SEXP shapeSEXP, S if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -607,7 +612,7 @@ RcppExport SEXP _Countr_dWeibullgammaCount_mat_Covariates(SEXP xSEXP, SEXP ccSEX if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -649,7 +654,7 @@ RcppExport SEXP _Countr_dWeibullgammaCount_mat_Covariates_vec(SEXP xSEXP, SEXP c if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -692,7 +697,7 @@ RcppExport SEXP _Countr_dWeibullgammaCount_acc(SEXP xSEXP, SEXP shapeSEXP, SEXP if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -735,7 +740,7 @@ RcppExport SEXP _Countr_dWeibullgammaCount_acc_vec(SEXP xSEXP, SEXP shapeSEXP, S if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -780,7 +785,7 @@ RcppExport SEXP _Countr_dWeibullgammaCount_acc_Covariates(SEXP xSEXP, SEXP ccSEX if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -825,7 +830,7 @@ RcppExport SEXP _Countr_dWeibullgammaCount_acc_Covariates_vec(SEXP xSEXP, SEXP c if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -861,7 +866,7 @@ RcppExport SEXP _Countr_alphagen(SEXP ccSEXP, SEXP jrowSEXP, SEXP ncolSEXP) { if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -900,7 +905,7 @@ RcppExport SEXP _Countr_dWeibullCount_mat(SEXP xSEXP, SEXP shapeSEXP, SEXP scale if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -939,7 +944,7 @@ RcppExport SEXP _Countr_dWeibullCount_mat_scalar(SEXP xSEXP, SEXP shapeSEXP, SEX if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -978,7 +983,7 @@ RcppExport SEXP _Countr_dWeibullCount_mat_vec(SEXP xSEXP, SEXP shapeSEXP, SEXP s if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -1020,7 +1025,7 @@ RcppExport SEXP _Countr_dWeibullCount_acc(SEXP xSEXP, SEXP shapeSEXP, SEXP scale if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; @@ -1062,7 +1067,7 @@ RcppExport SEXP _Countr_dWeibullCount_acc_vec(SEXP xSEXP, SEXP shapeSEXP, SEXP s if (rcpp_isError_gen) { SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen); UNPROTECT(1); - Rf_error(CHAR(rcpp_msgSEXP_gen)); + Rf_error("%s", CHAR(rcpp_msgSEXP_gen)); } UNPROTECT(1); return rcpp_result_gen; diff --git a/src/built_in_distributions.cpp b/src/built_in_distributions.cpp index 644a7ab..6f298bd 100644 --- a/src/built_in_distributions.cpp +++ b/src/built_in_distributions.cpp @@ -117,9 +117,9 @@ double sgengamma(double t, const Rcpp::List distPars) { return out ; } -//' Wrapper to built in survival functions +//' Wrapper to built-in survival functions //' -//' Wrapper to built in survival functions +//' Wrapper to built-in survival functions //' //' The function wraps all builtin-survival distributions. User can choose //' between the \code{weibull}, \code{gamma}, \code{gengamma}(generalized gamma) @@ -139,8 +139,8 @@ double sgengamma(double t, const Rcpp::List distPars) { //' @param distPars \code{Rcpp::List} with distribution specific slots, //' see details. //' @param dist character name of the built-in distribution, see details. -//' @return a double giving the value of the survival function at time point -//' \code{t} at the parameters' values. +//' @return a double, giving the value of the survival function at time point +//' \code{t} at the parameters' values. //' //' @examples //' tt <- 2.5 diff --git a/src/conv_dePril.cpp b/src/conv_dePril.cpp index fc3730e..dd02fe3 100644 --- a/src/conv_dePril.cpp +++ b/src/conv_dePril.cpp @@ -506,7 +506,6 @@ arma::vec getProbs_dePril(unsigned xnum, const Rcpp::List distPars, //' Richardson extrapolation if \code{extrap} is \code{TRUE} using the //' algorithm of section 3.2. //' -//' @param inheritParams dCount_naive_bi //' @return vector of probabilities P(x(i)) for i = 1, ..., n where n is //' \code{length} of \code{x}. //' diff --git a/src/conv_naive.cpp b/src/conv_naive.cpp index 9527aee..c1bbb6d 100644 --- a/src/conv_naive.cpp +++ b/src/conv_naive.cpp @@ -418,7 +418,7 @@ arma::vec getProbs(unsigned xnum, const Rcpp::List distPars, //' //' @param cdfout logical if \code{TRUE}, the cdf will be returned instead of //' the count probability. -//' @param inheritParams dCount_allProbs_bi +//' @inheritParams dCount_allProbs_bi //' @return vector of probabilities P(x(i)) for i = 1, ..., n where n is //' \code{length} of \code{x}. //'