Skip to content

Commit

Permalink
Merge branch 'release/1.2.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
demsarjure committed Mar 24, 2023
2 parents 1b6e7b2 + 971eacd commit 965cfb7
Show file tree
Hide file tree
Showing 34 changed files with 520 additions and 572 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ cran-comments.md
^doc$
^Meta$
^CRAN-RELEASE$
^\.github$
^CRAN-SUBMISSION$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
50 changes: 50 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master, develop]
pull_request:
branches: [main, master, develop]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3

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

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
error-on: '"error"'
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ vignettes/*.pdf
*.o
*.so
*.cc
*.hpp
doc
Meta
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 1.2.11
Date: 2023-03-22 19:58:11 UTC
SHA: ebd5258c187e9b08ce60238e50168d25c2b5e910
13 changes: 7 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: bayes4psy
Version: 1.2.10
Version: 1.2.11
Title: User Friendly Bayesian Data Analysis for Psychology
Description: Contains several Bayesian models for data analysis of psychological tests. A user friendly interface for these models should enable students and researchers to perform professional level Bayesian data analysis without advanced knowledge in programming and Bayesian statistics. This package is based on the Stan platform (Carpenter et el. 2017 <doi:10.18637/jss.v076.i01>).
Authors@R:
Expand Down Expand Up @@ -28,10 +28,9 @@ Imports:
rstan (>= 2.21.2),
rstantools (>= 2.1.1),
mcmcse (>= 1.4.1),
scales (>= 1.1.1),
stats (>= 4.0.0),
utils (>= 4.0.0)
Suggests:
RcppParallel
Suggests:
testthat (>= 3.0.0),
rmarkdown (>= 2.5.0),
knitr (>= 1.30.0)
Expand All @@ -40,10 +39,12 @@ LinkingTo:
rstan (>= 2.21.0),
BH (>= 1.72.0.3),
Rcpp (>= 1.0.5),
RcppEigen (>= 0.3.3.7.0)
RcppEigen (>= 0.3.3.7.0),
RcppParallel
SystemRequirements: GNU make
VignetteBuilder: knitr
NeedsCompilation: yes
RoxygenNote: 7.1.1
UseLTO: true
RoxygenNote: 7.2.3
URL: https://github.com/bstatcomp/bayes4psy
BugReports: https://github.com/bstatcomp/bayes4psy/issues
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import(dplyr)
import(ggplot2)
import(methods)
import(rstan)
import(rstantools)
importFrom(RcppParallel,RcppParallelLibs)
importFrom(rstan,sampling)
importFrom(rstantools,rstan_config)
useDynLib(bayes4psy, .registration = TRUE)
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# bayes4psy change log

## bayes4psy 1.2.11

Optimized building of RStan models.

## bayes4psy 1.2.10

Tidied up the README file.
Expand Down
20 changes: 10 additions & 10 deletions R/b_bootstrap.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @title b_bootstrap
#' @description Performs a Bayesian bootstrap and returns a sample of size n1 representing the posterior distribution of the statistic. Returns a vector if the statistic is one-dimensional (like for mean(...)) or a data.frame if the statistic is multi-dimensional (like for the coefficients of lm).
#' @author Rasmus Baath
#' @references \url{http://www.sumsar.net/blog/2015/07/easy-bayesian-bootstrap-in-r/}
#' @references \url{https://www.sumsar.net/blog/2015/07/easy-bayesian-bootstrap-in-r/}
#' @references Rubin, D. B. (1981). The Bayesian Bootstrap. The annals of statistics, 9(1), 130-134.
#' @export
#' @param data The data as either a vector, matrix or data.frame.
Expand All @@ -24,35 +24,35 @@
#' data <- adaptation_level_small
#'
#' # bootstrap
#' data_bootstrap <- b_bootstrap(data, lm_statistic, n1=1000, n2=1000)
#' data_bootstrap <- b_bootstrap(data, lm_statistic, n1 = 1000, n2 = 1000)
#'
b_bootstrap <- function(data, statistic, n1=1000, n2=1000, use_weights=FALSE, weight_arg=NULL, ...) {
b_bootstrap <- function(data, statistic, n1 = 1000, n2 = 1000, use_weights = FALSE, weight_arg = NULL, ...) {
# Draw from a uniform Dirichlet dist. with alpha set to rep(1, n_dim).
# Using the facts that you can transform gamma distributed draws into
# Dirichlet draws and that rgamma(n, 1) <=> rexp(n, 1)
dirichlet_weights <- matrix(stats::rexp(NROW(data) * n1, 1) , ncol=NROW(data), byrow=TRUE)
dirichlet_weights <- matrix(stats::rexp(NROW(data) * n1, 1), ncol = NROW(data), byrow = TRUE)
dirichlet_weights <- dirichlet_weights / rowSums(dirichlet_weights)

if(use_weights) {
if (use_weights) {
stat_call <- quote(statistic(data, w, ...))
names(stat_call)[3] <- weight_arg
boot_sample <- apply(dirichlet_weights, 1, function(w) {
eval(stat_call)
})
} else {
if(is.null(dim(data)) || length(dim(data)) < 2) { # data is a list type of object
if (is.null(dim(data)) || length(dim(data)) < 2) { # data is a list type of object
boot_sample <- apply(dirichlet_weights, 1, function(w) {
data_sample <- sample(data, size=n2, replace=TRUE, prob=w)
data_sample <- sample(data, size = n2, replace = TRUE, prob = w)
statistic(data_sample, ...)
})
} else { # data is a table type of object
boot_sample <- apply(dirichlet_weights, 1, function(w) {
index_sample <- sample(nrow(data), size=n2, replace=TRUE, prob=w)
statistic(data[index_sample, , drop=FALSE], ...)
index_sample <- sample(nrow(data), size = n2, replace = TRUE, prob = w)
statistic(data[index_sample, , drop = FALSE], ...)
})
}
}
if(is.null(dim(boot_sample)) || length(dim(boot_sample)) < 2) {
if (is.null(dim(boot_sample)) || length(dim(boot_sample)) < 2) {
# If the bootstrap sample is just a simple vector return it.
boot_sample
} else {
Expand Down
3 changes: 2 additions & 1 deletion R/bayes4psy-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#' @useDynLib bayes4psy, .registration = TRUE
#' @import methods
#' @import Rcpp
#' @import rstantools
#' @importFrom rstantools rstan_config
#' @importFrom RcppParallel RcppParallelLibs
#' @importFrom rstan sampling
#'
#' @references
Expand Down
12 changes: 6 additions & 6 deletions R/reaction_time_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ setMethod(f="compare_means", signature(object="reaction_time_class"), definition
# provided a list of fits
i <- 2
for (fit in arguments$fits) {
if (class(fit) != "reaction_time_class") {
if (!("reaction_time_class" %in% class(fit))) {
stop("One of the fits in the fits list is not a valid reaction_time_class object.")
}

Expand Down Expand Up @@ -608,7 +608,7 @@ setMethod(f="plot_means_difference", signature(object="reaction_time_class"), de
} else if (!is.null(arguments$fits)) {
i <- 2
for (fit in arguments$fits) {
if (class(fit) != "reaction_time_class") {
if (!("reaction_time_class" %in% class(fit))) {
stop("One of the fits in the fits list is not a valid reaction_time_class object.")
}

Expand Down Expand Up @@ -737,7 +737,7 @@ setMethod(f="plot_means", signature(object="reaction_time_class"), definition=fu
} else if (!is.null(arguments$fits)) {
i <- 2
for (fit in arguments$fits) {
if (class(fit) != "reaction_time_class") {
if (!("reaction_time_class" %in% class(fit))) {
stop("One of the fits in the fits list is not a valid reaction_time_class object.")
}

Expand Down Expand Up @@ -836,7 +836,7 @@ setMethod(f="compare_distributions", signature(object="reaction_time_class"), de
# provided a list of fits
i <- 2
for (fit in arguments$fits) {
if (class(fit) != "reaction_time_class") {
if (!("reaction_time_class" %in% class(fit))) {
stop("One of the fits in the fits list is not a valid reaction_time_class object.")
}

Expand Down Expand Up @@ -927,7 +927,7 @@ setMethod(f="plot_distributions", signature(object="reaction_time_class"), defin
} else if (!is.null(arguments$fits)) {
i <- 2
for (fit in arguments$fits) {
if (class(fit) != "reaction_time_class") {
if (!("reaction_time_class" %in% class(fit))) {
stop("One of the fits in the fits list is not a valid reaction_time_class object.")
}

Expand Down Expand Up @@ -1040,7 +1040,7 @@ setMethod(f="plot_distributions_difference", signature(object="reaction_time_cla
} else if (!is.null(arguments$fits)) {
i <- 2
for (fit in arguments$fits) {
if (class(fit) != "reaction_time_class") {
if (!("reaction_time_class" %in% class(fit))) {
stop("One of the fits in the fits list is not a valid reaction_time_class object.")
}

Expand Down
37 changes: 0 additions & 37 deletions R/stanmodels.R

This file was deleted.

Loading

0 comments on commit 965cfb7

Please sign in to comment.