Skip to content

Commit

Permalink
Merge branch 'release-1.2.0' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed Sep 26, 2024
2 parents 61d9743 + 584c35f commit 9838bb2
Show file tree
Hide file tree
Showing 73 changed files with 4,910 additions and 608 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes
steps:
- name: Checking out the repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setting up pandoc
uses: r-lib/actions/setup-pandoc@v2
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checking out the repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setting up R
uses: r-lib/actions/setup-r@v2
Expand All @@ -40,20 +40,22 @@ jobs:
run: |
library(lintr)
excluded_files <- list(
"vignettes/Sampling_and_ML_estimation.Rmd:29"
"vignettes/Sampling_and_ML_estimation.Rmd" = 29,
"R/probdist-class.R" = c(25, 29, 38, 40, 43),
"R/prepEta.R" = 2
)
style_rules <- list(
T_and_F_symbol_linter(), assignment_linter(), brace_linter(),
commas_linter(), commented_code_linter(), todo_comment_linter(),
cyclocomp_linter(), equals_na_linter(),
equals_na_linter(),
function_left_parentheses_linter(), infix_spaces_linter(),
line_length_linter(), no_tab_linter(), absolute_path_linter(),
line_length_linter(), whitespace_linter(), absolute_path_linter(),
pipe_continuation_linter(),
semicolon_linter(), seq_linter(), single_quotes_linter(),
semicolon_linter(), seq_linter(), quotes_linter(),
spaces_inside_linter(), spaces_left_parentheses_linter(),
trailing_blank_lines_linter(), trailing_whitespace_linter(),
undesirable_function_linter(), undesirable_operator_linter(),
unneeded_concatenation_linter()
unnecessary_concatenation_linter()
)
lint_package(linters = style_rules, exclusions = excluded_files)
expect_lint_free(linters = style_rules, exclusions = excluded_files)
shell: Rscript {0}
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand Down
95 changes: 95 additions & 0 deletions .github/workflows/rhub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# R-hub's generic GitHub Actions workflow file. It's canonical location is at
# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml
# You can update this file to a newer version using the rhub2 package:
#
# rhub::rhub_setup()
#
# It is unlikely that you need to modify this file manually.

name: R-hub
run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}"

on:
workflow_dispatch:
inputs:
config:
description: 'A comma separated list of R-hub platforms to use.'
type: string
default: 'linux,windows,macos'
name:
description: 'Run name. You can leave this empty now.'
type: string
id:
description: 'Unique ID. You can leave this empty now.'
type: string

jobs:

setup:
runs-on: ubuntu-latest
outputs:
containers: ${{ steps.rhub-setup.outputs.containers }}
platforms: ${{ steps.rhub-setup.outputs.platforms }}

steps:
# NO NEED TO CHECKOUT HERE
- uses: r-hub/actions/setup@v1
with:
config: ${{ github.event.inputs.config }}
id: rhub-setup

linux-containers:
needs: setup
if: ${{ needs.setup.outputs.containers != '[]' }}
runs-on: ubuntu-latest
name: ${{ matrix.config.label }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.setup.outputs.containers) }}
container:
image: ${{ matrix.config.container }}

steps:
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/platform-info@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/setup-deps@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/run-check@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}

other-platforms:
needs: setup
if: ${{ needs.setup.outputs.platforms != '[]' }}
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.label }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.setup.outputs.platforms) }}

steps:
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/setup-r@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/actions/platform-info@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/setup-deps@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/actions/run-check@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
Expand Down
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 1.1.1
Date: 2024-02-26 15:11:55 UTC
SHA: d3942e5b524eb80d5cabfc6cdd5fecb48f5f3a50
Version: 1.2.0
Date: 2024-09-26 06:14:26 UTC
SHA: aac7a6b6cc93a891f567efa812c71ea719d34713
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: TruncExpFam
Title: Truncated Exponential Family
Version: 1.1.1
Date: 2024-02-26
Version: 1.2.0
Date: 2024-09-26
Authors@R:
c(
person(
Expand All @@ -27,7 +27,7 @@ Description: Handles truncated members from the exponential family of
License: GPL-3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Imports: methods, invgamma, rmutil
Suggests:
knitr,
Expand Down
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.

When we speak of free software, we are referring to freedom, not
When we speak of free software, we are refering to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
Expand Down Expand Up @@ -111,7 +111,7 @@ menu, a prominent item in the list meets this criterion.

1. Source Code.

The "source code" for a work means the preferred form of the work
The "source code" for a work means the prefered form of the work
for making modifications to it. "Object code" means any non-source
form of a work.

Expand Down
27 changes: 26 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,33 @@ export(mlEstimationTruncDist)
export(natural2parameters)
export(parameters2natural)
export(probdist)
export(ptrunc)
export(ptruncbeta)
export(ptruncbinom)
export(ptruncchisq)
export(ptrunccontbern)
export(ptruncexp)
export(ptruncgamma)
export(ptruncinvgamma)
export(ptruncinvgauss)
export(ptrunclnorm)
export(ptruncnbinom)
export(ptruncnorm)
export(ptruncpois)
export(qtrunc)
export(qtruncbeta)
export(qtruncbinom)
export(qtruncchisq)
export(qtrunccontbern)
export(qtruncexp)
export(qtruncgamma)
export(qtruncinvgamma)
export(qtruncinvgauss)
export(qtrunclnorm)
export(qtruncnbinom)
export(qtruncnorm)
export(qtruncpois)
export(rtrunc)
export(rtrunc.beta)
export(rtrunc_direct)
export(rtruncbeta)
export(rtruncbinom)
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# TruncExpFam 1.2.0

* Implemented `ptrunc()` and `qtrunc()` for all distributions (issue #54)
* Refactoring (issue #104, #112)
* 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)
* Added `faster` argument to `rtrunc()` aliases (issue #110)
* Improved calculation of cumulative densities (issue #113)

# TruncExpFam 1.1.1

* Fixed `UseMethod()` no longer forwarding local variables from the generic on R-devel (issue #103)
Expand Down
2 changes: 1 addition & 1 deletion R/TruncExpFam-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#' }
#' @note Found a bug? Want to suggest a feature? Contribute to the scientific
#' and open source communities by opening an issue on our home page.
#' Check the "BugReports" field on \code{packageDescription("TruncExpFam")} for
#' Check the "BugReports" field on `packageDescription("TruncExpFam")` for
#' the URL.
#' @importFrom methods new is
#' @importFrom stats dbinom dgamma dlnorm dnorm dpois pbinom pgamma plnorm pnorm
Expand Down
2 changes: 1 addition & 1 deletion R/attachDistroAttributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ attachDistroAttributes <- function(sample, family, parms) {
attr(sample, "truncation_limits") <- parms[c("a", "b")]
attr(sample, "continuous") <- family_attributes$cont
}
return(sample)
sample
}
1 change: 0 additions & 1 deletion R/averageT.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ averageT <- function(y) {
} else {
out <- colMeans(Ty)
}
return(out)
}
29 changes: 18 additions & 11 deletions R/beta.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
#' @param shape2 positive shape parameter beta
#' @rdname rtrunc
#' @export
rtrunc.beta <- function(n, shape1, shape2, a = 0, b = 1) {
rtruncbeta <- function(n, shape1, shape2, a = 0, b = 1, faster = FALSE) {
class(n) <- "trunc_beta"
sampleFromTruncated(mget(ls()))
if (faster) {
family <- gsub("trunc_", "", class(n))
parms <- mget(ls())[grep("^faster$|^n$|^family$", ls(), invert = TRUE)]
return(rtrunc_direct(n, family, parms, a, b))
} else {
parms <- mget(ls())[grep("^faster$", ls(), invert = TRUE)]
return(sampleFromTruncated(parms))
}
}

#' @rdname rtrunc
#' @export
rtruncbeta <- rtrunc.beta
rtrunc.beta <- rtruncbeta

#' @export
dtrunc.trunc_beta <- function(y, shape1, shape2, eta, a = 0, b = 1, ...) {
Expand All @@ -40,12 +45,13 @@ empiricalParameters.trunc_beta <- function(y, ...) {
beta <- alpha * (1 / amean - 1)
parms <- c(shape1 = alpha, shape2 = beta)
class(parms) <- "parms_beta"
return(parms)
parms
}

#' @method sufficientT trunc_beta
sufficientT.trunc_beta <- function(y) {
# Calculates the sufficient statistic T(y)
return(suff.T = cbind(log(y), log(1 - y)))
suff.T <- cbind(log(y), log(1 - y))
}

#' @export
Expand All @@ -55,17 +61,17 @@ natural2parameters.parms_beta <- function(eta, ...) {
if (length(eta) != 2) stop("Eta must be a vector of two elements")
parms <- c(shape1 = eta[[1]], shape2 = eta[[2]])
class(parms) <- class(eta)
return(parms)
parms
}

#' @export
parameters2natural.parms_beta <- function(parms, ...) {
# parms: The parameters shape and rate in a beta distribution
# returns the natural parameters
eta <- prepEta(c(parms[1], parms[2]), class(parms))
return(eta)
}

#' @method getYseq trunc_beta
getYseq.trunc_beta <- function(y, y.min = 0, y.max = 1, n = 100) {
# needs chekking
mean <- mean(y, na.rm = TRUE)
Expand All @@ -75,9 +81,10 @@ getYseq.trunc_beta <- function(y, y.min = 0, y.max = 1, n = 100) {
out <- seq(lo, hi, length = n)
out <- out[out > 0 & out < 1] # prevents NaN as sufficient statistics
class(out) <- class(y)
return(out)
out
}

#' @method getGradETinv parms_beta
getGradETinv.parms_beta <- function(eta, ...) {
# eta: Natural parameter
# return the inverse of E.T differentiated with respect to eta' : p x p matrix
Expand All @@ -90,5 +97,5 @@ getGradETinv.parms_beta <- function(eta, ...) {
term.12 <- -(1 + 2 * (x + y)) / (2 * (x + y) ^ 2)
term.2 <- (x * (x + 2 * x * y + 2 * y * (1 + y))) / (2 * y ^ 2 * (x + y) ^ 2)
A_inv <- matrix(c(term.1, term.12, term.12, term.2), ncol = 2)
return(A = solve(A_inv))
solve(A_inv)
}
Loading

0 comments on commit 9838bb2

Please sign in to comment.