Skip to content

Commit

Permalink
Merge branch 'issue-109' into develop
Browse files Browse the repository at this point in the history
* issue-109:
  Updated NEWS.md
  Increment version number to 1.1.1.9009
  Fixed domain validation for invgamma and nbinom
  Added domain validation to faster `rtrunc()` (#109)
  • Loading branch information
wleoncio committed Apr 4, 2024
2 parents dbeb77b + d5c492c commit 52125fb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: TruncExpFam
Title: Truncated Exponential Family
Version: 1.1.1.9008
Version: 1.1.1.9009
Date: 2024-02-26
Authors@R:
c(
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Implemented `ptrunc()` for some distributions (issue #54)
* Refactoring (issue #104)
* Fixed bugs related to using the Negative Binomial with `mu` instead of `prob` (issue #107)
* Fixed domain validation on Negative Binomial and Inverse Gamma
* Added domain validation to `rtrunc(..., faster = TRUE)` (issue #109)

# TruncExpFam 1.1.1

Expand Down
4 changes: 3 additions & 1 deletion R/rtrunc_direct.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ rtrunc_direct <- function(n, family = "gaussian", parms, a, b, ...) {
# TODO: fix all code smells: https://www.codefactor.io/repository/github/ocbe-uio/TruncExpFam

Check warning on line 5 in R/rtrunc_direct.R

View workflow job for this annotation

GitHub Actions / lint

file=R/rtrunc_direct.R,line=5,col=3,[todo_comment_linter] TODO comments should be removed.

Check warning on line 5 in R/rtrunc_direct.R

View workflow job for this annotation

GitHub Actions / lint

file=R/rtrunc_direct.R,line=5,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 95 characters.

# Validating ---------------------------------------------------------------
family <- tolower(family)
family <- useStandardFamilyName(tolower(family))
class(family) <- paste0("trunc_", family)
validateFamilyName(family)
validateDomain(family, parms)

# Determining object class -------------------------------------------------
class(n) <- genrtruncClass(n, family, names(parms))
Expand Down
17 changes: 13 additions & 4 deletions R/validateDomain.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ validateDomain.trunc_gamma <- function(n, parms, ...) {
#' @method validateDomain trunc_invgamma
validateDomain.trunc_invgamma <- function(n, parms, ...) {
if (parms$shape <= 0) stop("Invalid parameter domain. shape must be > 0.")
if (parms$scale <= 0) {
stop("Invalid parameter domain. rate/scale must be > 0.")
if (!is.null(parms$rate)) {
if (parms$rate <= 0) {
stop("Invalid parameter domain. rate must be > 0.")
}
}
if (!is.null(parms$scale)) {
if (parms$scale <= 0) {
stop("Invalid parameter domain. scale must be > 0.")
}
}
}

Expand All @@ -86,8 +93,10 @@ validateDomain.trunc_nbinom <- function(n, parms, ...) {
if (parms$size != as.integer(parms$size) || parms$size < 0) {
stop("Invalid parameter domain. size must be a natural number.")
}
if (parms$prob != "" && (parms$prob < 0 || parms$prob > 1)) {
stop("Invalid parameter domain. prob must be [0, 1].")
if (!is.na(match("prob", names(parms)))) {
if (parms$prob < 0 || parms$prob > 1) {
stop("Invalid parameter domain. prob must be [0, 1].")
}
}
}

Expand Down

0 comments on commit 52125fb

Please sign in to comment.