├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── .gitignore ├── .travis.yml ├── CRAN-SUBMISSION ├── DESCRIPTION ├── NAMESPACE ├── NEWS.md ├── R ├── b_bootstrap.R ├── b_color.R ├── b_linear.R ├── b_prior.R ├── b_reaction_time.R ├── b_results.R ├── b_success_rate.R ├── b_ttest.R ├── bayes4psy-package.R ├── color_class.R ├── data.R ├── linear_class.R ├── reaction_time_class.R ├── shared_functions.R ├── shared_plots.R ├── success_rate_class.R └── ttest_class.R ├── README.md ├── bayes4psy.Rproj ├── configure ├── configure.win ├── cran-comments.md ├── data ├── adaptation_level.rda ├── adaptation_level_small.rda ├── after_images.rda ├── after_images_opponent_process.rda ├── after_images_stimuli.rda ├── after_images_trichromatic.rda ├── flanker.rda ├── stroop_extended.rda └── stroop_simple.rda ├── inst ├── include │ └── stan_meta_header.hpp └── stan │ ├── color.stan │ ├── include │ └── license.stan │ ├── linear.stan │ ├── reaction_time.stan │ ├── success_rate.stan │ └── ttest.stan ├── man ├── b_bootstrap.Rd ├── b_color.Rd ├── b_linear.Rd ├── b_prior-class.Rd ├── b_prior-get_prior_id.Rd ├── b_reaction_time.Rd ├── b_results-class.Rd ├── b_results-compare_distributions.Rd ├── b_results-compare_means.Rd ├── b_results-get_parameters.Rd ├── b_results-get_subject_parameters.Rd ├── b_results-plot_distributions.Rd ├── b_results-plot_distributions_difference.Rd ├── b_results-plot_fit.Rd ├── b_results-plot_means.Rd ├── b_results-plot_means_difference.Rd ├── b_results-plot_trace.Rd ├── b_success_rate.Rd ├── b_ttest.Rd ├── bayes4psy-datasets.Rd ├── bayes4psy-package.Rd ├── color_class-class.Rd ├── color_class-compare_distributions.Rd ├── color_class-compare_means.Rd ├── color_class-get_parameters.Rd ├── color_class-plot_distributions.Rd ├── color_class-plot_distributions_difference.Rd ├── color_class-plot_distributions_hsv.Rd ├── color_class-plot_fit.Rd ├── color_class-plot_fit_hsv.Rd ├── color_class-plot_hsv.Rd ├── color_class-plot_means.Rd ├── color_class-plot_means_difference.Rd ├── color_class-plot_means_hsv.Rd ├── color_class-plot_trace.Rd ├── linear_class-class.Rd ├── linear_class-compare_distributions.Rd ├── linear_class-compare_means.Rd ├── linear_class-get_parameters.Rd ├── linear_class-get_subject_parameters.Rd ├── linear_class-plot_distributions.Rd ├── linear_class-plot_distributions_difference.Rd ├── linear_class-plot_fit.Rd ├── linear_class-plot_means.Rd ├── linear_class-plot_means_difference.Rd ├── linear_class-plot_trace.Rd ├── mcmc_hdi.Rd ├── plot-color_class-missing-method.Rd ├── plot-linear_class-missing-method.Rd ├── plot-reaction_time_class-missing-method.Rd ├── plot-success_rate_class-missing-method.Rd ├── plot-ttest_class-missing-method.Rd ├── reaction_time_class-class.Rd ├── reaction_time_class-compare_distributions.Rd ├── reaction_time_class-compare_means.Rd ├── reaction_time_class-get_parameters.Rd ├── reaction_time_class-get_subject_parameters.Rd ├── reaction_time_class-plot_distributions.Rd ├── reaction_time_class-plot_distributions_difference.Rd ├── reaction_time_class-plot_fit.Rd ├── reaction_time_class-plot_means.Rd ├── reaction_time_class-plot_means_difference.Rd ├── reaction_time_class-plot_trace.Rd ├── show-color_class-method.Rd ├── show-linear_class-method.Rd ├── show-reaction_time_class-method.Rd ├── show-success_rate_class-method.Rd ├── show-ttest_class-method.Rd ├── success_rate_class-class.Rd ├── success_rate_class-compare_distributions.Rd ├── success_rate_class-compare_means.Rd ├── success_rate_class-get_parameters.Rd ├── success_rate_class-get_subject_parameters.Rd ├── success_rate_class-plot_distributions.Rd ├── success_rate_class-plot_distributions_difference.Rd ├── success_rate_class-plot_fit.Rd ├── success_rate_class-plot_means.Rd ├── success_rate_class-plot_means_difference.Rd ├── success_rate_class-plot_trace.Rd ├── summary-color_class-method.Rd ├── summary-linear_class-method.Rd ├── summary-reaction_time_class-method.Rd ├── summary-success_rate_class-method.Rd ├── summary-ttest_class-method.Rd ├── ttest_class-class.Rd ├── ttest_class-compare_distributions.Rd ├── ttest_class-compare_means.Rd ├── ttest_class-get_parameters.Rd ├── ttest_class-plot_distributions.Rd ├── ttest_class-plot_distributions_difference.Rd ├── ttest_class-plot_fit.Rd ├── ttest_class-plot_means.Rd ├── ttest_class-plot_means_difference.Rd └── ttest_class-plot_trace.Rd ├── tests ├── testthat.R └── testthat │ ├── test_bootstrap.R │ ├── test_color.R │ ├── test_linear.R │ ├── test_reaction_time.R │ ├── test_success_rate.R │ └── test_ttest.R └── vignettes ├── adaptation_level.Rmd ├── afterimages.Rmd ├── flanker.Rmd └── stroop.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^bayes4psy\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | .git 5 | cran-comments.md 6 | ^doc$ 7 | ^Meta$ 8 | ^CRAN-RELEASE$ 9 | ^\.github$ 10 | ^CRAN-SUBMISSION$ 11 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master, develop] 6 | pull_request: 7 | branches: [main, master, develop] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macos-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 24 | - {os: ubuntu-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'oldrel-1'} 26 | 27 | env: 28 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 29 | R_KEEP_PKG_SOURCE: yes 30 | 31 | steps: 32 | - uses: actions/checkout@v3 33 | 34 | - uses: r-lib/actions/setup-pandoc@v2 35 | 36 | - uses: r-lib/actions/setup-r@v2 37 | with: 38 | r-version: ${{ matrix.config.r }} 39 | http-user-agent: ${{ matrix.config.http-user-agent }} 40 | use-public-rspm: true 41 | 42 | - uses: r-lib/actions/setup-r-dependencies@v2 43 | with: 44 | extra-packages: any::rcmdcheck 45 | needs: check 46 | 47 | - uses: r-lib/actions/check-r-package@v2 48 | with: 49 | upload-snapshots: true 50 | error-on: '"error"' 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Session Data files 6 | .RData 7 | 8 | # Example code in package build process 9 | *-Ex.R 10 | 11 | # Output files from R CMD build 12 | /*.tar.gz 13 | 14 | # Output files from R CMD check 15 | /*.Rcheck/ 16 | 17 | # RStudio files 18 | .Rproj.user/ 19 | 20 | # produced vignettes 21 | vignettes/*.html 22 | vignettes/*.pdf 23 | 24 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 25 | .httr-oauth 26 | 27 | # knitr and R markdown default cache directories 28 | /*_cache/ 29 | /cache/ 30 | 31 | # Temporary files created by R markdown 32 | *.utf8.md 33 | *.knit.md 34 | .Rproj.user 35 | 36 | # mac files 37 | .DS_store 38 | 39 | # R package stuff 40 | *.dll 41 | *.o 42 | *.so 43 | *.cc 44 | doc 45 | Meta 46 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | sudo: false 3 | cache: packages 4 | 5 | latex: true 6 | 7 | matrix: 8 | include: 9 | - os: linux 10 | compiler: clang 11 | addons: 12 | apt: 13 | sources: 14 | - ubuntu-toolchain-r-test 15 | packages: 16 | - g++-7 17 | env: 18 | - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" 19 | 20 | before_install: 21 | - mkdir -p ~/.R/ 22 | - echo "CXX14 = g++-7 -fPIC -flto=2" >> ~/.R/Makevars 23 | - echo "CXX14FLAGS = -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-unused-local-typedefs -Wno-ignored-attributes -Wno-deprecated-declarations -Wno-attributes -O3" >> ~/.R/Makevars 24 | 25 | script: 26 | - | 27 | travis_wait 42 R CMD build . 28 | travis_wait 59 R CMD check bayes4psy*tar.gz 29 | 30 | after_script: 31 | - tar -ztvf bayes4psy_*.tar.gz 32 | - echo ${NOT_CRAN} 33 | 34 | after_success: 35 | - travis_wait 40 tar -C .. -xf $PKG_TARBALL 36 | 37 | after_failure: 38 | - cat bayes4psy.Rcheck/00* 39 | -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 1.2.12 2 | Date: 2023-09-29 12:32:54 UTC 3 | SHA: 3564186c5c9464a9107af82d962456848a8e9dd1 4 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: bayes4psy 2 | Version: 1.2.12 3 | Title: User Friendly Bayesian Data Analysis for Psychology 4 | 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 ). 5 | Authors@R: 6 | c(person("Jure", "Demšar", , "jure.demsar@fri.uni-lj.si", c("cre", "aut")), 7 | person("Grega", "Repovš", , "grega.repovs@psy.ff.uni-lj.si", "aut"), 8 | person("Erik", "Štrumbelj", , "erik.strumbelj@fri.uni-lj.si", "aut"), 9 | person("Trustees of", "Columbia University", role = "cph"), 10 | person("John", "Kruschke", role = "cph", comment = "R/shared_functions.R - mcmc_hdi, src/stan_files/ttest.stan"), 11 | person("Rasmus", "Baath", role = "cph", comment = "R/b_bootstrap.R")) 12 | License: GPL (>=3) 13 | Encoding: UTF-8 14 | LazyData: true 15 | ByteCompile: true 16 | Depends: 17 | methods (>= 4.0.0), 18 | R (>= 4.0.0), 19 | Rcpp (>= 1.0.5) 20 | Imports: 21 | circular (>= 0.4.93), 22 | cowplot (>= 1.1.0), 23 | dplyr (>= 1.0.2), 24 | emg (>= 1.0.9), 25 | ggplot2 (>= 3.3.2), 26 | metRology (>= 0.9.28.1), 27 | reshape (>= 0.8.8), 28 | rstan (>= 2.26.0), 29 | rstantools (>= 2.1.1), 30 | mcmcse (>= 1.4.1), 31 | stats (>= 4.0.0), 32 | RcppParallel 33 | Suggests: 34 | testthat (>= 3.0.0), 35 | rmarkdown (>= 2.5.0), 36 | knitr (>= 1.30.0) 37 | LinkingTo: 38 | StanHeaders (>= 2.26.0), 39 | rstan (>= 2.26.0), 40 | BH (>= 1.72.0.3), 41 | Rcpp (>= 1.0.5), 42 | RcppEigen (>= 0.3.3.7.0), 43 | RcppParallel 44 | SystemRequirements: GNU make 45 | VignetteBuilder: knitr 46 | NeedsCompilation: yes 47 | UseLTO: true 48 | RoxygenNote: 7.2.3 49 | URL: https://github.com/bstatcomp/bayes4psy 50 | BugReports: https://github.com/bstatcomp/bayes4psy/issues 51 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(b_bootstrap) 4 | export(b_color) 5 | export(b_linear) 6 | export(b_prior) 7 | export(b_reaction_time) 8 | export(b_success_rate) 9 | export(b_ttest) 10 | export(mcmc_hdi) 11 | exportClasses(b_prior) 12 | exportMethods(compare_distributions) 13 | exportMethods(compare_means) 14 | exportMethods(get_parameters) 15 | exportMethods(get_prior_id) 16 | exportMethods(get_subject_parameters) 17 | exportMethods(plot) 18 | exportMethods(plot_distributions) 19 | exportMethods(plot_distributions_difference) 20 | exportMethods(plot_distributions_hsv) 21 | exportMethods(plot_fit) 22 | exportMethods(plot_fit_hsv) 23 | exportMethods(plot_hsv) 24 | exportMethods(plot_means) 25 | exportMethods(plot_means_difference) 26 | exportMethods(plot_means_hsv) 27 | exportMethods(plot_trace) 28 | exportMethods(show) 29 | exportMethods(summary) 30 | import(Rcpp) 31 | import(dplyr) 32 | import(ggplot2) 33 | import(methods) 34 | import(rstan) 35 | importFrom(RcppParallel,RcppParallelLibs) 36 | importFrom(rstan,sampling) 37 | importFrom(rstantools,rstan_config) 38 | useDynLib(bayes4psy, .registration = TRUE) 39 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # bayes4psy change log 2 | 3 | ## bayes4psy 1.2.12 4 | 5 | RStan updates and optimizations. 6 | 7 | ## bayes4psy 1.2.11 8 | 9 | Optimized building of RStan models. 10 | 11 | ## bayes4psy 1.2.10 12 | 13 | Tidied up the README file. 14 | 15 | ## bayes4psy 1.2.9 16 | 17 | Added funding information. 18 | 19 | ## bayes4psy 1.2.8 20 | 21 | Additional fixes required for newer versions of RStan. 22 | 23 | ## bayes4psy 1.2.7 24 | 25 | Support for newer versions of RStan. 26 | 27 | ## bayes4psy 1.2.6 28 | 29 | Further optimization of vignettes, tests and examples. 30 | 31 | ## bayes4psy 1.2.5 32 | 33 | Optimized vignettes for faster compilation. 34 | 35 | ## bayes4psy 1.2.4 36 | 37 | More robust unit tests and vignettes for the purpose of CRAN checks. 38 | 39 | ## bayes4psy 1.2.3 40 | 41 | Additional unit tests for CRAN checks. 42 | 43 | ## bayes4psy 1.2.2 44 | 45 | Further vignettes and tests optimizations. 46 | Added references to the description. 47 | 48 | ## bayes4psy 1.2.1 49 | 50 | Vignettes optimizations. 51 | 52 | ## bayes4psy 1.2.0 53 | 54 | Added detailed examples of usage as vignettes. 55 | All models now create visualizations with the default R plot function. 56 | Several minor tweaks and improvements. 57 | 58 | ## bayes4psy 1.1.1 59 | 60 | Modified some examples due to CRAN revision. 61 | Beautified some outputs. 62 | T-test now supports comparison through the sigma parameter only. 63 | 64 | ## bayes4psy 1.1.0 65 | 66 | Examples for all models and fitting functions. 67 | Code tests for all core functions. 68 | Documentation amended in accordance with CRAN team comments. 69 | 70 | ## bayes4psy 1.0.2 71 | 72 | Compilation is now c++14 compliant. 73 | Minor update to one of color visualizations. 74 | 75 | ## bayes4psy 1.0.1 76 | 77 | Ran CRAN checks (spell check, ...) and fixed some minor issues according to feedback. 78 | 79 | ## bayes4psy 1.0.0 80 | 81 | Greatly expanded the readme file. 82 | Minor changes to a few documentation entries. 83 | CRAN publish preparations. 84 | 85 | ## bayes4psy 0.9.0 86 | 87 | Various quality of life improvements (nicer graphs and outputs). 88 | Package is not in its own repository so it can be installed from GitHub via devtools. 89 | Upgraded all examples and tests. 90 | Examples and tests are now in a separate repository. 91 | 92 | ## bayes4psy 0.8.0 93 | 94 | Renamed package from EasyBayes to bayes4psy. 95 | Parameters are no longer permuted when extracted from a Stan fit. 96 | 97 | ## bayes4psy 0.7.0 98 | 99 | Functions for comparing multiple fits at the same time. 100 | Revised prior system so it is now more user friendly. 101 | Implementation of Bayesian t-test. 102 | 103 | ## bayes4psy 0.6.0 104 | 105 | Flexible setting of priors on all of the model's parameters. 106 | The plot_fit function for hierarchical models now allows visual inspection of a fit on top and bottom levels. 107 | Added functions for easy extraction of parameter values. 108 | 109 | ## bayes4psy 0.5.0 110 | 111 | Color model implementation. 112 | Specific visualizations for colors. 113 | Success rate hierarchical model rework. 114 | Extended documentation. 115 | Multiple chains support. 116 | 117 | ## bayes4psy 0.4.0 118 | 119 | Large update to documentation, which is now CRAN compliant. 120 | Added an additional, more detailed diagnostic print of fit. 121 | Updates to various visualizations. 122 | Bayesian bootstrap implementation. 123 | Tidyverse style code. 124 | 125 | ## bayes4psy 0.3.0 126 | 127 | Removed all warnings. 128 | CRAN ready! 129 | 130 | ## bayes4psy 0.2.0 131 | 132 | Cross platform compilation. 133 | Package now passes CRAN checks (with a lot of warnings and notes). 134 | Added documentation. 135 | 136 | ## bayes4psy 0.1.4 137 | 138 | Integrated linear model into the package. 139 | Changed version numbering. 140 | Using HDI instead of CI now. 141 | 142 | ## bayes4psy 0.1.3 143 | 144 | Expanded documentation of functions and classes. Consolidate functions and parameter passing between all models. 145 | 146 | ## bayes4psy 0.1.2 147 | 148 | Implementation of the success rate model. 149 | 150 | ## bayes4psy 0.1.1 151 | 152 | Implementation of ttest model. 153 | Implementation of reaction times model. 154 | -------------------------------------------------------------------------------- /R/b_bootstrap.R: -------------------------------------------------------------------------------- 1 | #' @title b_bootstrap 2 | #' @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). 3 | #' @author Rasmus Baath 4 | #' @references \url{https://www.sumsar.net/blog/2015/07/easy-bayesian-bootstrap-in-r/} 5 | #' @references Rubin, D. B. (1981). The Bayesian Bootstrap. The annals of statistics, 9(1), 130-134. 6 | #' @export 7 | #' @param data The data as either a vector, matrix or data.frame. 8 | #' @param statistic A function that accepts data as its first argument and if use_weights is TRUE the weights as its second argument. Function should return a numeric vector. 9 | #' @param n1 The size of the bootstrap sample (default = 1000). 10 | #' @param n2 The sample size used to calculate the statistic each bootstrap draw (default = 1000). 11 | #' @param use_weights Whether the statistic function accepts a weight argument or should be calculated using resampled data (default = FALSE). 12 | #' @param weight_arg If the statistic function includes a named argument for the weights this could be specified here (default = NULL). 13 | #' @param ... Further arguments passed on to the statistic function. 14 | #' @return A data frame containing bootstrap samples. 15 | #' 16 | #' @examples 17 | #' 18 | #' # linear function of seqence vs. response 19 | #' lm_statistic <- function(data) { 20 | #' lm(sequence ~ response, data)$coef 21 | #' } 22 | #' 23 | #' # load data 24 | #' data <- adaptation_level_small 25 | #' 26 | #' # bootstrap 27 | #' data_bootstrap <- b_bootstrap(data, lm_statistic, n1 = 1000, n2 = 1000) 28 | #' 29 | b_bootstrap <- function(data, statistic, n1 = 1000, n2 = 1000, use_weights = FALSE, weight_arg = NULL, ...) { 30 | # Draw from a uniform Dirichlet dist. with alpha set to rep(1, n_dim). 31 | # Using the facts that you can transform gamma distributed draws into 32 | # Dirichlet draws and that rgamma(n, 1) <=> rexp(n, 1) 33 | dirichlet_weights <- matrix(stats::rexp(NROW(data) * n1, 1), ncol = NROW(data), byrow = TRUE) 34 | dirichlet_weights <- dirichlet_weights / rowSums(dirichlet_weights) 35 | 36 | if (use_weights) { 37 | stat_call <- quote(statistic(data, w, ...)) 38 | names(stat_call)[3] <- weight_arg 39 | boot_sample <- apply(dirichlet_weights, 1, function(w) { 40 | eval(stat_call) 41 | }) 42 | } else { 43 | if (is.null(dim(data)) || length(dim(data)) < 2) { # data is a list type of object 44 | boot_sample <- apply(dirichlet_weights, 1, function(w) { 45 | data_sample <- sample(data, size = n2, replace = TRUE, prob = w) 46 | statistic(data_sample, ...) 47 | }) 48 | } else { # data is a table type of object 49 | boot_sample <- apply(dirichlet_weights, 1, function(w) { 50 | index_sample <- sample(nrow(data), size = n2, replace = TRUE, prob = w) 51 | statistic(data[index_sample, , drop = FALSE], ...) 52 | }) 53 | } 54 | } 55 | if (is.null(dim(boot_sample)) || length(dim(boot_sample)) < 2) { 56 | # If the bootstrap sample is just a simple vector return it. 57 | boot_sample 58 | } else { 59 | # Otherwise it is a matrix. Since apply returns one row per statistic 60 | # let's transpose it and return it as a data frame. 61 | as.data.frame(t(boot_sample)) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /R/b_linear.R: -------------------------------------------------------------------------------- 1 | #' @title b_linear 2 | #' @description Bayesian model for fitting a linear normal model to data. 3 | #' @import rstan 4 | #' @export 5 | #' @param x a vector containing sequence indexes (time). 6 | #' @param y a vector containing responses of subjects. 7 | #' @param s a vector containing subject indexes. Starting index should be 1 and the largest subject index should equal the number of subjects. 8 | #' @param priors List of parameters and their priors - b_prior objects. You can put a prior on the mu_a (mean intercept), sigma_a (variance of mu_a), mu_b (mean slope), sigma_s (variance of mu_b), mu_s (variance) and sigma_s (variance of mu_s) parameters (default = NULL). 9 | #' @param warmup Integer specifying the number of warmup iterations per chain (default = 1000). 10 | #' @param iter Integer specifying the number of iterations (including warmup, default = 2000). 11 | #' @param chains Integer specifying the number of parallel chains (default = 4). 12 | #' @param seed Random number generator seed (default = NULL). 13 | #' @param refresh Frequency of output (default = NULL). 14 | #' @param control A named list of parameters to control the sampler's behavior (default = NULL). 15 | #' @param suppress_warnings Suppress warnings returned by Stan (default = TRUE). 16 | #' @return An object of class `linear_class`. 17 | #' 18 | #' @examples 19 | #' \donttest{ 20 | #' # priors 21 | #' mu_prior <- b_prior(family="normal", pars=c(0, 100)) 22 | #' sigma_prior <- b_prior(family="uniform", pars=c(0, 500)) 23 | #' 24 | #' # attach priors to relevant parameters 25 | #' priors <- list(c("mu_a", mu_prior), 26 | #' c("sigma_a", sigma_prior), 27 | #' c("mu_b", mu_prior), 28 | #' c("sigma_b", sigma_prior), 29 | #' c("mu_s", sigma_prior), 30 | #' c("sigma_s", sigma_prior)) 31 | #' 32 | #' # generate data 33 | #' x <- vector() 34 | #' y <- vector() 35 | #' s <- vector() 36 | #' for (i in 1:5) { 37 | #' x <- c(x, rep(1:10, 2)) 38 | #' y <- c(y, rnorm(20, mean=1:10, sd=2)) 39 | #' s <- c(s, rep(i, 20)) 40 | #' } 41 | #' 42 | # fit 43 | #' fit <- b_linear(x=x, y=y, s=s, priors=priors, chains=1) 44 | #' } 45 | #' 46 | b_linear <- function(x, 47 | y, 48 | s, 49 | priors=NULL, 50 | warmup=1000, 51 | iter=2000, 52 | chains=4, 53 | seed=NULL, 54 | refresh=NULL, 55 | control=NULL, 56 | suppress_warnings=TRUE) { 57 | 58 | # multi core 59 | if (chains > 1) { 60 | options(mc.cores = parallel::detectCores()) 61 | } 62 | 63 | # prepare data 64 | n <- length(y) 65 | m <- length(unique(s)) 66 | 67 | # prior ids and values 68 | p_ids <- rep(0, 6) 69 | p_values <- rep(0, 12) 70 | 71 | # parameter mapping 72 | df_pars <- data.frame(par=c("mu_a", "sigma_a", "mu_b", "sigma_b", "mu_s", "sigma_s"), index=seq(1, 6)) 73 | 74 | # priors 75 | if (!is.null(priors)) { 76 | for (p in priors) { 77 | par <- p[[1]] 78 | prior <- p[[2]] 79 | 80 | # get parameter index 81 | id <- 0 82 | par_id <- df_pars[df_pars$par==par,] 83 | if (nrow(par_id) > 0) { 84 | id <- par_id$index 85 | } else { 86 | wrong_prior <- "Provided an unknown parameter for prior, use \"mu_m\", \"sigma_m\", \"mu_s\", \"sigma_s\", \"mu_l\" or \"sigma_l\"." 87 | warning(wrong_prior) 88 | return() 89 | } 90 | # set prior family id 91 | p_ids[id] <- get_prior_id(prior) 92 | if (p_ids[id] == 0) { 93 | wrong_prior <- "Provided an unknown prior family, use \"uniform\", \"normal\", \"gamma\" or \"beta\"." 94 | warning(wrong_prior) 95 | return() 96 | } 97 | 98 | # set parameter values 99 | if (length(prior@pars) != 2) { 100 | wrong_pars <- "Incorrect prior parameters, provide a vector of 2 numerical values." 101 | warning(wrong_pars) 102 | return() 103 | } 104 | p_values[2*id-1] <- prior@pars[1] 105 | p_values[2*id] <- prior@pars[2] 106 | } 107 | } 108 | 109 | # put data together 110 | stan_data <- list(n=n, 111 | m=m, 112 | x=x, 113 | y=y, 114 | s=s, 115 | p_ids = p_ids, 116 | p_values = p_values) 117 | 118 | # set seed 119 | if (is.null(seed)) { 120 | seed <- sample.int(.Machine$integer.max, 1) 121 | } 122 | 123 | # set output frequency 124 | if (is.null(refresh)) { 125 | refresh <- max(iter/10, 1) 126 | } 127 | 128 | # fit 129 | if (suppress_warnings) { 130 | fit <- suppressWarnings(sampling(stanmodels$linear, 131 | data=stan_data, 132 | iter=iter, 133 | warmup=warmup, 134 | chains=chains, 135 | seed=seed, 136 | refresh=refresh, 137 | control=control)) 138 | } else { 139 | fit <- sampling(stanmodels$linear, 140 | data=stan_data, 141 | iter=iter, 142 | warmup=warmup, 143 | chains=chains, 144 | seed=seed, 145 | refresh=refresh, 146 | control=control) 147 | } 148 | 149 | # extract and parse into list 150 | extract_raw <- extract(fit, permuted=FALSE) 151 | 152 | # alpha 153 | i <- 1 154 | j <- m 155 | alpha <- extract_raw[, 1, i:j] 156 | 157 | # beta 158 | i <- i + m 159 | j <- i + m - 1 160 | beta <- extract_raw[, 1, i:j] 161 | 162 | # sigma 163 | i <- i + m 164 | j <- i + m - 1 165 | sigma <- extract_raw[, 1, i:j] 166 | 167 | # mu_a 168 | i <- i + m 169 | mu_a <- extract_raw[, 1, i] 170 | 171 | # mu_b 172 | i <- i + 1 173 | mu_b <- extract_raw[, 1, i] 174 | 175 | # mu_s 176 | i <- i + 1 177 | mu_s <- extract_raw[, 1, i] 178 | 179 | # sigma_a 180 | i <- i + 1 181 | sigma_a <- extract_raw[, 1, i] 182 | 183 | # sigma_b 184 | i <- i + 1 185 | sigma_b <- extract_raw[, 1, i] 186 | 187 | # sigma_s 188 | i <- i + 1 189 | sigma_s <- extract_raw[, 1, i] 190 | 191 | # lp__ 192 | i <- i + 1 193 | lp__ <- extract_raw[, 1, i] 194 | 195 | extract <- list(alpha=alpha, 196 | beta=beta, 197 | sigma=sigma, 198 | mu_a=mu_a, 199 | mu_b=mu_b, 200 | mu_s=mu_s, 201 | sigma_a=sigma_a, 202 | sigma_b=sigma_b, 203 | sigma_s=sigma_s, 204 | lp__=lp__) 205 | 206 | # create output class 207 | out <- linear_class(extract=extract, data=stan_data, fit=fit) 208 | 209 | # return 210 | return(out) 211 | } 212 | -------------------------------------------------------------------------------- /R/b_prior.R: -------------------------------------------------------------------------------- 1 | #' @title b_prior 2 | #' @description An S4 class for defining priors for Bayesian models. 3 | #' @slot family Prior family - \"uniform\", \"normal\", \"gamma\" or \"beta\". 4 | #' @slot pars Parameters of the prior - a vector of two numerical values. 5 | #' @export b_prior 6 | #' @exportClass b_prior 7 | b_prior <- setClass( 8 | "b_prior", 9 | slots = c( 10 | family = "character", 11 | pars = "vector" 12 | ) 13 | ) 14 | 15 | #' @rdname b_prior-get_prior_id 16 | #' @exportMethod get_prior_id 17 | setGeneric(name="get_prior_id", function(object) standardGeneric("get_prior_id")) 18 | 19 | #' @title get_prior_id 20 | #' @description \code{get_prior_id} returns an integer id of prior's family (1 = uniform, 2 = normal, 3 = gamma, 4 = beta). 21 | #' @param object b_prior object. 22 | #' @rdname b_prior-get_prior_id 23 | #' @aliases get_prior_id_b_prior 24 | setMethod(f="get_prior_id", signature(object="b_prior"), definition=function(object) { 25 | if (object@family == "uniform") { 26 | return(1) 27 | } else if (object@family == "normal") { 28 | return(2) 29 | } else if (object@family == "gamma") { 30 | return(3) 31 | } else if (object@family == "beta") { 32 | return(4) 33 | } 34 | return(0) 35 | }) 36 | -------------------------------------------------------------------------------- /R/b_reaction_time.R: -------------------------------------------------------------------------------- 1 | #' @title b_reaction_time 2 | #' @description Bayesian model for comparing reaction times. 3 | #' @import rstan 4 | #' @export 5 | #' @param t a vector containing reaction times for each measurement. 6 | #' @param s a vector containing subject indexes. Starting index should be 1 and the largest subject index should equal the number of subjects. 7 | #' @param priors List of parameters and their priors - b_prior objects. You can put a prior on the mu_m (mean), sigma_m (variance of mu_m), mu_s (variance), sigma_s (variance of mu_s), mu_l (mean of the exponent factor) and sigma_l (variance of mu_l) parameters (default = NULL). 8 | #' @param warmup Integer specifying the number of warmup iterations per chain (default = 1000). 9 | #' @param iter Integer specifying the number of iterations (including warmup, default = 2000). 10 | #' @param chains Integer specifying the number of parallel chains (default = 4). 11 | #' @param seed Random number generator seed (default = NULL). 12 | #' @param refresh Frequency of output (default = NULL). 13 | #' @param control A named list of parameters to control the sampler's behavior (default = NULL). 14 | #' @param suppress_warnings Suppress warnings returned by Stan (default = TRUE). 15 | #' @return An object of class `reaction_time_class` 16 | #' 17 | #' @examples 18 | #' \donttest{ 19 | #' # priors 20 | #' mu_prior <- b_prior(family="normal", pars=c(0, 100)) 21 | #' sigma_prior <- b_prior(family="uniform", pars=c(0, 500)) 22 | #' lambda_prior <- b_prior(family="uniform", pars=c(0.05, 5)) 23 | #' 24 | #' # attach priors to relevant parameters 25 | #' priors <- list(c("mu_m", mu_prior), 26 | #' c("sigma_m", sigma_prior), 27 | #' c("mu_s", sigma_prior), 28 | #' c("sigma_s", sigma_prior), 29 | #' c("mu_l", lambda_prior), 30 | #' c("sigma_l", sigma_prior)) 31 | #' 32 | #' # generate data 33 | #' s <- rep(1:5, 20) 34 | #' rt <- emg::remg(100, mu=10, sigma=1, lambda=0.4) 35 | #' 36 | #' # fit 37 | #' fit <- b_reaction_time(t=rt, s=s, priors=priors, chains=1) 38 | #' } 39 | #' 40 | b_reaction_time <- function(t, 41 | s, 42 | priors=NULL, 43 | warmup=1000, 44 | iter=2000, 45 | chains=4, 46 | seed=NULL, 47 | refresh=NULL, 48 | control=NULL, 49 | suppress_warnings=TRUE) { 50 | 51 | # multi core 52 | if (chains > 1) { 53 | options(mc.cores = parallel::detectCores()) 54 | } 55 | 56 | # prepare data 57 | n <- length(t) 58 | m <- length(unique(s)) 59 | 60 | # prior ids and values 61 | p_ids <- rep(0, 6) 62 | p_values <- rep(0, 12) 63 | 64 | # parameter mapping 65 | df_pars <- data.frame(par=c("mu_m", "sigma_m", "mu_s", "sigma_s", "mu_l", "sigma_l"), index=seq(1, 6)) 66 | 67 | # priors 68 | if (!is.null(priors)) { 69 | for (p in priors) { 70 | par <- p[[1]] 71 | prior <- p[[2]] 72 | 73 | # get parameter index 74 | id <- 0 75 | par_id <- df_pars[df_pars$par==par,] 76 | if (nrow(par_id) > 0) { 77 | id <- par_id$index 78 | } else { 79 | wrong_prior <- "Provided an unknown parameter for prior, use \"mu_m\", \"sigma_m\", \"mu_s\", \"sigma_s\", \"mu_l\" or \"sigma_l\"." 80 | warning(wrong_prior) 81 | return() 82 | } 83 | # set prior family id 84 | p_ids[id] <- get_prior_id(prior) 85 | if (p_ids[id] == 0) { 86 | wrong_prior <- "Provided an unknown prior family, use \"uniform\", \"normal\", \"gamma\" or \"beta\"." 87 | warning(wrong_prior) 88 | return() 89 | } 90 | 91 | # set parameter values 92 | if (length(prior@pars) != 2) { 93 | wrong_pars <- "Incorrect prior parameters, provide a vector of 2 numerical values." 94 | warning(wrong_pars) 95 | return() 96 | } 97 | p_values[2*id-1] <- prior@pars[1] 98 | p_values[2*id] <- prior@pars[2] 99 | } 100 | } 101 | 102 | # put data together 103 | stan_data <- list(n=n, 104 | m=m, 105 | t=t, 106 | s=s, 107 | p_ids = p_ids, 108 | p_values = p_values) 109 | 110 | # set seed 111 | if (is.null(seed)) { 112 | seed <- sample.int(.Machine$integer.max, 1) 113 | } 114 | 115 | # set output frequency 116 | if (is.null(refresh)) { 117 | refresh <- max(iter/10, 1) 118 | } 119 | 120 | # fit 121 | if (suppress_warnings) { 122 | fit <- suppressWarnings(sampling(stanmodels$reaction_time, 123 | data=stan_data, 124 | iter=iter, 125 | warmup=warmup, 126 | chains=chains, 127 | seed=seed, 128 | refresh=refresh, 129 | control=control)) 130 | } else { 131 | fit <- sampling(stanmodels$reaction_time, 132 | data=stan_data, 133 | iter=iter, 134 | warmup=warmup, 135 | chains=chains, 136 | seed=seed, 137 | refresh=refresh, 138 | control=control) 139 | } 140 | 141 | # extract and parse into list 142 | extract_raw <- extract(fit, permuted=FALSE) 143 | 144 | # mu 145 | i <- 1 146 | j <- m 147 | mu <- extract_raw[, 1, i:j] 148 | 149 | # sigma 150 | i <- i + m 151 | j <- i + m - 1 152 | sigma <- extract_raw[, 1, i:j] 153 | 154 | # lambda 155 | i <- i + m 156 | j <- i + m - 1 157 | lambda <- extract_raw[, 1, i:j] 158 | 159 | # mu_m 160 | i <- i + m 161 | mu_m <- extract_raw[, 1, i] 162 | 163 | # mu_l 164 | i <- i + 1 165 | mu_l <- extract_raw[, 1, i] 166 | 167 | # mu_s 168 | i <- i + 1 169 | mu_s <- extract_raw[, 1, i] 170 | 171 | # sigma_m 172 | i <- i + 1 173 | sigma_m <- extract_raw[, 1, i] 174 | 175 | # sigma_l 176 | i <- i + 1 177 | sigma_l <- extract_raw[, 1, i] 178 | 179 | # sigma_s 180 | i <- i + 1 181 | sigma_s <- extract_raw[, 1, i] 182 | 183 | # rt 184 | i <- i + 1 185 | rt <- extract_raw[, 1, i] 186 | 187 | # rt_subjects 188 | i <- i + 1 189 | j <- i + m - 1 190 | rt_subjects <- extract_raw[, 1, i:j] 191 | 192 | # lp__ 193 | i <- i + m 194 | lp__ <- extract_raw[, 1, i] 195 | 196 | extract <- list(mu=mu, 197 | sigma=sigma, 198 | lambda=lambda, 199 | mu_m=mu_m, 200 | mu_l=mu_l, 201 | mu_s=mu_s, 202 | sigma_m=sigma_m, 203 | sigma_l=sigma_l, 204 | sigma_s=sigma_s, 205 | rt=rt, 206 | rt_subjects=rt_subjects, 207 | lp__=lp__) 208 | 209 | # create output class 210 | out <- reaction_time_class(extract=extract, data=stan_data, fit=fit) 211 | 212 | # return 213 | return(out) 214 | } 215 | -------------------------------------------------------------------------------- /R/b_results.R: -------------------------------------------------------------------------------- 1 | #' @title b_results 2 | #' @description Parent S4 class for declaring shared function generics. 3 | setClass("b_results") 4 | 5 | 6 | #' @title get_parameters 7 | #' @description \code{get_parameters} returns a dataframe with values of fitted parameters. 8 | #' @param object S4 class object from bayes4psy library. 9 | #' @rdname b_results-get_parameters 10 | #' @exportMethod get_parameters 11 | setGeneric(name="get_parameters", function(object) standardGeneric("get_parameters")) 12 | 13 | 14 | #' @title get_subject_parameters 15 | #' @description \code{get_subject_parameters} returns a dataframe with values of fitted parameters for each subject in the hierarchical model. 16 | #' @param object S4 class object from bayes4psy library. 17 | #' @rdname b_results-get_subject_parameters 18 | #' @exportMethod get_subject_parameters 19 | setGeneric(name="get_subject_parameters", function(object) standardGeneric("get_subject_parameters")) 20 | 21 | 22 | #' @title compare_means 23 | #' @description \code{compare_means} prints difference between means of two or multiple fits. 24 | #' @param object S4 class object from bayes4psy library. 25 | #' @param ... see documentation for specific class for the description of available parameters, e.g. ?compare_means_ttest or ?compare_means_linear. 26 | #' @rdname b_results-compare_means 27 | #' @exportMethod compare_means 28 | setGeneric(name="compare_means", function(object, ...) standardGeneric("compare_means")) 29 | 30 | 31 | #' @title plot_means_difference 32 | #' @description \code{plot_means_difference} plots difference between means of two or multiple fits. 33 | #' @param object S4 class object from bayes4psy library. 34 | #' @param ... see documentation for specific class for the description of available parameters, e.g. ?plot_means_difference_ttest or ?plot_means_difference_linear. 35 | #' @rdname b_results-plot_means_difference 36 | #' @exportMethod plot_means_difference 37 | setGeneric(name="plot_means_difference", function(object, ...) standardGeneric("plot_means_difference")) 38 | 39 | 40 | #' @title plot_means 41 | #' @description \code{plot_means} plots means for one or multiple fits. 42 | #' @param object S4 class object from bayes4psy library. 43 | #' @param ... see documentation for specific class for the description of available parameters, e.g. ?plot_means_ttest or ?plot_means_linear. 44 | #' @rdname b_results-plot_means 45 | #' @exportMethod plot_means 46 | setGeneric(name="plot_means", function(object, ...) standardGeneric("plot_means")) 47 | 48 | 49 | #' @title compare_distributions 50 | #' @description \code{compare_distributions} draws samples from distribution of the first fit and compares them against samples drawn from the distribution of the second fit, or against samples from multiple fits. 51 | #' @param object S4 class object from bayes4psy library. 52 | #' @param ... see documentation for specific class for the description of available parameters, e.g. ?compare_distributions_ttest or ?compare_distributions_linear. 53 | #' @rdname b_results-compare_distributions 54 | #' @exportMethod compare_distributions 55 | setGeneric(name="compare_distributions", function(object, ...) standardGeneric("compare_distributions")) 56 | 57 | 58 | #' @title plot_distributions 59 | #' @description \code{plot_distributions} visualizes fitted distributions. 60 | #' @param object S4 class object from bayes4psy library. 61 | #' @param ... see documentation for specific class for the description of available parameters, e.g. ?plot_distributions_ttest or ?plot_distributions_linear. 62 | #' @rdname b_results-plot_distributions 63 | #' @exportMethod plot_distributions 64 | setGeneric(name="plot_distributions", function(object, ...) standardGeneric("plot_distributions")) 65 | 66 | 67 | #' @title plot_distributions_difference 68 | #' @description \code{plot_distributions_difference} a visualization of the difference between the distributions of two or more fits. 69 | #' @param object S4 class object from bayes4psy library. 70 | #' @param ... see documentation for specific class for the description of available parameters, e.g. ?plot_distributions_difference_ttest or ?plot_distributions_difference_linear. 71 | #' @rdname b_results-plot_distributions_difference 72 | #' @exportMethod plot_distributions_difference 73 | setGeneric(name="plot_distributions_difference", function(object, ...) standardGeneric("plot_distributions_difference")) 74 | 75 | 76 | #' @title plot_fit 77 | #' @description \code{plot_fit} plots fitted model against the data. Use this function to explore the quality of your fit. 78 | #' @param object S4 class object from bayes4psy library. 79 | #' @param ... see documentation for specific class for the description of available parameters, e.g. ?plot_fit_colors or ?plot_fit_linear. 80 | #' @rdname b_results-plot_fit 81 | #' @exportMethod plot_fit 82 | setGeneric(name="plot_fit", function(object, ...) standardGeneric("plot_fit")) 83 | 84 | 85 | #' @title plot_trace 86 | #' @description \code{plot_trace} traceplot for main fitted model parameters. 87 | #' @param object S4 class object from bayes4psy library. 88 | #' @rdname b_results-plot_trace 89 | #' @exportMethod plot_trace 90 | setGeneric(name="plot_trace", function(object) standardGeneric("plot_trace")) 91 | -------------------------------------------------------------------------------- /R/b_success_rate.R: -------------------------------------------------------------------------------- 1 | #' @title b_success_rate 2 | #' @description Bayesian model for comparing test success rate. 3 | #' @import rstan 4 | #' @export 5 | #' @param r a vector containing test results (0 - test was not solved successfully, 1 - test was solved successfully). 6 | #' @param s a vector containing subject indexes. Starting index should be 1 and the largest subject index should equal the number of subjects. 7 | #' @param priors List of parameters and their priors - b_prior objects. You can put a prior on the p (mean probability of success) and tau (variance) parameters (default = NULL). 8 | #' @param warmup Integer specifying the number of warmup iterations per chain (default = 1000). 9 | #' @param iter Integer specifying the number of iterations (including warmup, default = 2000). 10 | #' @param chains Integer specifying the number of parallel chains (default = 4). 11 | #' @param seed Random number generator seed (default = NULL). 12 | #' @param refresh Frequency of output (default = NULL). 13 | #' @param control A named list of parameters to control the sampler's behavior (default = NULL). 14 | #' @param suppress_warnings Suppress warnings returned by Stan (default = TRUE). 15 | #' @return An object of class `success_rate_class`. 16 | #' 17 | #' @examples 18 | #' \donttest{ 19 | #' # priors 20 | #' p_prior <- b_prior(family="beta", pars=c(1, 1)) 21 | #' tau_prior <- b_prior(family="uniform", pars=c(0, 500)) 22 | #' 23 | #' # attach priors to relevant parameters 24 | #' priors <- list(c("p", p_prior), 25 | #' c("tau", tau_prior)) 26 | #' 27 | #' # generate data 28 | #' s <- rep(1:5, 20) 29 | #' data <- rbinom(100, size=1, prob=0.6) 30 | #' 31 | #' # fit 32 | #' fit <- b_success_rate(r=data, s=s, priors=priors, chains=1) 33 | #' } 34 | #' 35 | b_success_rate <- function(r, 36 | s, 37 | priors=NULL, 38 | warmup=1000, 39 | iter=2000, 40 | chains=4, 41 | seed=NULL, 42 | refresh=NULL, 43 | control=NULL, 44 | suppress_warnings=TRUE) { 45 | 46 | # multi core 47 | if (chains > 1) { 48 | options(mc.cores = parallel::detectCores()) 49 | } 50 | 51 | # prepare data 52 | n <- length(r) 53 | m <- length(unique(s)) 54 | 55 | # prior ids and values 56 | p_ids <- rep(0, 2) 57 | p_values <- rep(0, 4) 58 | 59 | # parameter mapping 60 | df_pars <- data.frame(par=c("p", "tau"), index=c(1, 2)) 61 | 62 | # priors 63 | if (!is.null(priors)) { 64 | for (p in priors) { 65 | par <- p[[1]] 66 | prior <- p[[2]] 67 | 68 | # get parameter index 69 | id <- 0 70 | par_id <- df_pars[df_pars$par==par,] 71 | if (nrow(par_id) > 0) { 72 | id <- par_id$index 73 | } else { 74 | wrong_prior <- "Provided an unknown parameter for prior, use \"p\" or \"tau\"." 75 | warning(wrong_prior) 76 | return() 77 | } 78 | # set prior family id 79 | p_ids[id] <- get_prior_id(prior) 80 | if (p_ids[id] == 0) { 81 | wrong_prior <- "Provided an unknown prior family, use \"uniform\", \"normal\", \"gamma\" or \"beta\"." 82 | warning(wrong_prior) 83 | return() 84 | } 85 | 86 | # set parameter values 87 | if (length(prior@pars) != 2) { 88 | wrong_pars <- "Incorrect prior parameters, provide a vector of 2 numerical values." 89 | warning(wrong_pars) 90 | return() 91 | } 92 | p_values[2*id-1] <- prior@pars[1] 93 | p_values[2*id] <- prior@pars[2] 94 | } 95 | } 96 | 97 | # put data together 98 | stan_data <- list(n=n, 99 | m=m, 100 | r=r, 101 | s=s, 102 | p_ids = p_ids, 103 | p_values = p_values) 104 | 105 | # set seed 106 | if (is.null(seed)) { 107 | seed <- sample.int(.Machine$integer.max, 1) 108 | } 109 | 110 | # set output frequency 111 | if (is.null(refresh)) { 112 | refresh <- max(iter/10, 1) 113 | } 114 | 115 | # fit 116 | if (suppress_warnings) { 117 | fit <- suppressWarnings(sampling(stanmodels$success_rate, 118 | data=stan_data, 119 | iter=iter, 120 | warmup=warmup, 121 | chains=chains, 122 | seed=seed, 123 | refresh=refresh, 124 | control=control)) 125 | } else { 126 | fit <- sampling(stanmodels$success_rate, 127 | data=stan_data, 128 | iter=iter, 129 | warmup=warmup, 130 | chains=chains, 131 | seed=seed, 132 | refresh=refresh, 133 | control=control) 134 | } 135 | 136 | # extract and parse into list 137 | extract_raw <- extract(fit, permuted=FALSE) 138 | 139 | # p0 140 | i <- 1 141 | p0 <- extract_raw[, 1, i] 142 | 143 | # tau 144 | i <- i + 1 145 | tau <- extract_raw[, 1, i] 146 | 147 | # p 148 | i <- i + 1 149 | j <- i + m - 1 150 | p <- extract_raw[, 1, i:j] 151 | 152 | # lp__ 153 | i <- i + m 154 | lp__ <- extract_raw[, 1, i] 155 | 156 | extract <- list(p0=p0, 157 | tau=tau, 158 | p=p, 159 | lp__=lp__) 160 | 161 | # create output class 162 | out <- success_rate_class(extract=extract, data=stan_data, fit=fit) 163 | 164 | # return 165 | return(out) 166 | } 167 | -------------------------------------------------------------------------------- /R/b_ttest.R: -------------------------------------------------------------------------------- 1 | #' @title b_ttest 2 | #' @description Bayesian t-test. 3 | #' @import rstan 4 | #' @export 5 | #' @param data Numeric vector of values on which the fit will be based. 6 | #' @param priors List of parameters and their priors - b_prior objects. You can put a prior on the mu (mean) and sigma (variance) parameters (default = NULL). 7 | #' @param warmup Integer specifying the number of warmup iterations per chain (default = 1000). 8 | #' @param iter Integer specifying the number of iterations (including warmup, default = 2000). 9 | #' @param chains Integer specifying the number of parallel chains (default = 4). 10 | #' @param seed Random number generator seed (default = NULL). 11 | #' @param refresh Frequency of output (default = NULL). 12 | #' @param control A named list of parameters to control the sampler's behavior (default = NULL). 13 | #' @param suppress_warnings Suppress warnings returned by Stan (default = TRUE). 14 | #' @return An object of class `ttest_class`. 15 | #' 16 | #' @examples 17 | #' \donttest{ 18 | #' # priors 19 | #' mu_prior <- b_prior(family="normal", pars=c(0, 1000)) 20 | #' sigma_prior <- b_prior(family="uniform", pars=c(0, 500)) 21 | #' nu_prior <- b_prior(family="normal", pars=c(2000, 1000)) 22 | #' 23 | #' # attach priors to relevant parameters 24 | #' priors <- list(c("mu", mu_prior), 25 | #' c("sigma", sigma_prior), 26 | #' c("nu", nu_prior)) 27 | #' 28 | #' # generate some data 29 | #' data <- rnorm(20, mean=150, sd=20) 30 | #' 31 | #' # fit 32 | #' fit <- b_ttest(data=data, priors=priors, chains=1) 33 | #' } 34 | #' 35 | b_ttest <- function(data, 36 | priors=NULL, 37 | warmup=1000, 38 | iter=2000, 39 | chains=4, 40 | seed=NULL, 41 | refresh=NULL, 42 | control=NULL, 43 | suppress_warnings=TRUE) { 44 | 45 | # multi core 46 | if (chains > 1) { 47 | options(mc.cores = parallel::detectCores()) 48 | } 49 | 50 | # prepare data 51 | n <- length(data) 52 | 53 | # prior ids and values 54 | p_ids <- rep(0, 3) 55 | p_values <- rep(0, 6) 56 | 57 | # parameter mapping 58 | df_pars <- data.frame(par=c("mu", "sigma", "nu"), index=c(1, 2, 3)) 59 | 60 | # priors 61 | if (!is.null(priors)) { 62 | for (p in priors) { 63 | par <- p[[1]] 64 | prior <- p[[2]] 65 | 66 | # get parameter index 67 | id <- 0 68 | par_id <- df_pars[df_pars$par==par,] 69 | if (nrow(par_id) > 0) { 70 | id <- par_id$index 71 | } else { 72 | wrong_prior <- "Provided an unknown parameter for prior, use \"nu\", \"mu\" or \"sigma\"." 73 | warning(wrong_prior) 74 | return() 75 | } 76 | # set prior family id 77 | p_ids[id] <- get_prior_id(prior) 78 | if (p_ids[id] == 0) { 79 | wrong_prior <- "Provided an unknown prior family, use \"uniform\", \"normal\", \"gamma\" or \"beta\"." 80 | warning(wrong_prior) 81 | return() 82 | } 83 | 84 | # set parameter values 85 | if (length(prior@pars) != 2) { 86 | wrong_pars <- "Incorrect prior parameters, provide a vector of 2 numerical values." 87 | warning(wrong_pars) 88 | return() 89 | } 90 | p_values[2*id-1] <- prior@pars[1] 91 | p_values[2*id] <- prior@pars[2] 92 | } 93 | } 94 | 95 | # put data together 96 | stan_data <- list(n = n, 97 | y = data, 98 | p_ids = p_ids, 99 | p_values = p_values) 100 | 101 | # set seed 102 | if (is.null(seed)) { 103 | seed <- sample.int(.Machine$integer.max, 1) 104 | } 105 | 106 | # set output frequency 107 | if (is.null(refresh)) { 108 | refresh <- max(iter/10, 1) 109 | } 110 | 111 | # fit 112 | if (suppress_warnings) { 113 | fit <- suppressWarnings(sampling(stanmodels$ttest, 114 | data=stan_data, 115 | warmup=warmup, 116 | iter=iter, 117 | chains=chains, 118 | seed=seed, 119 | refresh=refresh, 120 | control=control)) 121 | } else { 122 | fit <- sampling(stanmodels$ttest, 123 | data=stan_data, 124 | warmup=warmup, 125 | iter=iter, 126 | chains=chains, 127 | seed=seed, 128 | refresh=refresh, 129 | control=control) 130 | } 131 | 132 | # extract and parse into a list 133 | extract_raw <- extract(fit, permuted=FALSE) 134 | extract <- NULL 135 | samples <- iter - warmup 136 | for (i in 1:samples) { 137 | extract <- rbind(extract, extract_raw[i, 1,]) 138 | } 139 | extract <- as.list(data.frame(extract)) 140 | 141 | # create output class 142 | out <- ttest_class(extract=extract, fit=fit, data=data) 143 | 144 | # return 145 | return(out) 146 | } 147 | -------------------------------------------------------------------------------- /R/bayes4psy-package.R: -------------------------------------------------------------------------------- 1 | #' The 'bayes4psy' package. 2 | #' 3 | #' @description A user-friendly implementation of Bayesian statistical methods commonly used in social sciences. All used models are pre-compiled, meaning that users only need to call appropriate functions using their data. 4 | #' 5 | #' @docType package 6 | #' @name bayes4psy-package 7 | #' @aliases bayes4psy 8 | #' @useDynLib bayes4psy, .registration = TRUE 9 | #' @import methods 10 | #' @import Rcpp 11 | #' @importFrom rstantools rstan_config 12 | #' @importFrom RcppParallel RcppParallelLibs 13 | #' @importFrom rstan sampling 14 | #' 15 | #' @references 16 | #' Stan Development Team (NA) - the Stan framework and RStan interface. 17 | #' John Kruschke - mcmc_hdi function 18 | #' Rasmus Bååth - Easy Bayesian Bootstrap in R 19 | NULL 20 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' Datasets for bayes4psy examples 2 | #' Example datasets for use in \pkg{rstanarm} examples and vignettes. 3 | #' The datasets were extracted from the internal MBLab \url{http://www.mblab.si} repository. 4 | #' MBLab is a research lab at the Faculty of Arts, Department of Psychology, University of Ljubljana, Slovenia. 5 | #' 6 | #' @name bayes4psy-datasets 7 | #' @aliases adaptation_level_small adaptation_level after_images_opponent_process after_images_stimuli after_images_trichromatic after_images flanker stroop_extended stroop_simple 8 | #' 9 | #' @format 10 | #' \describe{ 11 | #' \item{\code{adaptation_level_small}}{ 12 | #' Small dataset on subjects picking up weights and determining their weights from 1..10. 13 | #' 14 | #' Source: Internal MBLab repository. 15 | #' 16 | #' 50 obs. of 3 variables 17 | #' \itemize{ 18 | #' \item \code{sequence} sequence index. 19 | #' \item \code{weight} actual weight of the object. 20 | #' \item \code{response} subject's estimation of weight. 21 | #' } 22 | #' } 23 | #' \item{\code{adaptation_level}}{ 24 | #' Data on subjects picking up weights and determining their weights from 1..10. 25 | #' 26 | #' Source: Internal MBLab repository. 27 | #' 28 | #' 2900 obs. of 6 variables 29 | #' \itemize{ 30 | #' \item \code{subject} subject index. 31 | #' \item \code{group} group index. 32 | #' \item \code{part} first or second part of the experiment. 33 | #' \item \code{sequence} sequence index. 34 | #' \item \code{weight} actual weight of the object. 35 | #' \item \code{response} subject's estimation of weight. 36 | #' } 37 | #' } 38 | #' #' \item{\code{after_images_opponent_process}}{ 39 | #' Colors predicted by the opponent process theory. 40 | #' 41 | #' Source: Internal MBLab repository. 42 | #' 43 | #' 6 obs. of 7 variables 44 | #' \itemize{ 45 | #' \item \code{stimuli} name of the color stimuli. 46 | #' \item \code{r} value of the R component in the RGB model. 47 | #' \item \code{g} value of the G component in the RGB model. 48 | #' \item \code{b} value of the B component in the RGB model. 49 | #' \item \code{h} value of the H component in the HSV model. 50 | #' \item \code{s} value of the S component in the HSV model. 51 | #' \item \code{v} value of the V component in the HSV model. 52 | #' } 53 | #' } 54 | #' #' \item{\code{after_images_opponent_stimuli}}{ 55 | #' Stimuli used in the after images experiment. 56 | #' 57 | #' Source: Internal MBLab repository. 58 | #' 59 | #' 6 obs. of 7 variables 60 | #' \itemize{ 61 | #' \item \code{r_s} value of the R component in the RGB model. 62 | #' \item \code{g_s} value of the G component in the RGB model. 63 | #' \item \code{b_s} value of the B component in the RGB model. 64 | #' \item \code{stimuli} name of the color stimuli. 65 | #' \item \code{h_s} value of the H component in the HSV model. 66 | #' \item \code{s_s} value of the S component in the HSV model. 67 | #' \item \code{v_s} value of the V component in the HSV model. 68 | #' } 69 | #' } 70 | #' #' \item{\code{after_images_trichromatic}}{ 71 | #' Colors predicted by the trichromatic theory. 72 | #' 73 | #' Source: Internal MBLab repository. 74 | #' 75 | #' 6 obs. of 7 variables 76 | #' \itemize{ 77 | #' \item \code{stimuli} name of the color stimuli. 78 | #' \item \code{r} value of the R component in the RGB model. 79 | #' \item \code{g} value of the G component in the RGB model. 80 | #' \item \code{b} value of the B component in the RGB model. 81 | #' \item \code{h} value of the H component in the HSV model. 82 | #' \item \code{s} value of the S component in the HSV model. 83 | #' \item \code{v} value of the V component in the HSV model. 84 | #' } 85 | #' } 86 | #' #' \item{\code{after_images}}{ 87 | #' Data gathered by the after images experiment. 88 | #' 89 | #' Source: Internal MBLab repository. 90 | #' 91 | #' 1311 obs. of 12 variables 92 | #' \itemize{ 93 | #' \item \code{subject} subject index. 94 | #' \item \code{rt} reaction time. 95 | #' \item \code{r} value of the R component in the RGB model of subject's response. 96 | #' \item \code{g} value of the G component in the RGB model of subject's response. 97 | #' \item \code{b} value of the B component in the RGB model of subject's response. 98 | #' \item \code{stimuli} name of the color stimuli. 99 | #' \item \code{r_s} value of the R component in the RGB model of the shown stimulus 100 | #' \item \code{g_s} value of the G component in the RGB model of the shown stimulus 101 | #' \item \code{b_s} value of the B component in the RGB model of the shown stimulus 102 | #' \item \code{h_s} value of the H component in the HSV model of the shown stimulus 103 | #' \item \code{s_s} value of the S component in the HSV model of the shown stimulus 104 | #' \item \code{v_s} value of the V component in the HSV model of the shown stimulus 105 | #' } 106 | #' } 107 | #' #' \item{\code{flanker}}{ 108 | #' Data gathered by the flanker experiment. 109 | #' 110 | #' Source: Internal MBLab repository. 111 | #' 112 | #' 8256 obs. of 5 variables 113 | #' \itemize{ 114 | #' \item \code{subject} subject index. 115 | #' \item \code{group} group index. 116 | #' \item \code{congruencty} type of stimulus. 117 | #' \item \code{result} was subject's reponse correct or wrong? 118 | #' \item \code{rt} reaction time. 119 | #' } 120 | #' } 121 | #' #' \item{\code{stroop_extended}}{ 122 | #' All the data gathered by the Stroop experiment. 123 | #' 124 | #' Source: Internal MBLab repository. 125 | #' 126 | #' 41068 obs. of 5 variables 127 | #' \itemize{ 128 | #' \item \code{subject} subject ID. 129 | #' \item \code{cond} type of condition. 130 | #' \item \code{rt} reaction time. 131 | #' \item \code{acc} was subject's reponse correct or wrong? 132 | #' \item \code{age} age of subject. 133 | #' } 134 | #' } 135 | #' #' \item{\code{stroop_simple}}{ 136 | #' All the data gathered by the Stroop experiment. 137 | #' 138 | #' Source: Internal MBLab repository. 139 | #' 140 | #' 61 obs. of 5 variables 141 | #' \itemize{ 142 | #' \item \code{subject} subject ID. 143 | #' \item \code{reading_neutral} average response time for reading neutral stimuli. 144 | #' \item \code{naming_neutral} average response time for naming neutral stimuli. 145 | #' \item \code{reading_incongruent} average response time for reading incongruent stimuli. 146 | #' \item \code{naming_incongruent} average response time for naming incongruent stimuli. 147 | #' } 148 | #' } 149 | #' } 150 | #' 151 | #' @examples 152 | #' 153 | #' # Example of Bayesian bootstraping on 'adaptation_level_small' dataset 154 | #' # linear function of seqence vs. response 155 | #' lm_statistic <- function(data) { 156 | #' lm(sequence ~ response, data)$coef 157 | #' } 158 | #' 159 | #' # load data 160 | #' data <- adaptation_level_small 161 | #' 162 | #' # bootstrap 163 | #' data_bootstrap <- b_bootstrap(data, lm_statistic, n1=1000, n2=1000) 164 | #' 165 | NULL 166 | -------------------------------------------------------------------------------- /R/shared_plots.R: -------------------------------------------------------------------------------- 1 | #' @import ggplot2 2 | 3 | # function for visalizsing the difference between two datasets 4 | plot_difference <- function(y1, y2, rope=NULL, bins=30, circular=FALSE, nrow=1, max_diff=NULL) { 5 | # init local varibales for CRAN check 6 | value <- NULL 7 | 8 | # difference 9 | y_diff <- y1 - y2 10 | 11 | # if circular cast differences to a -pi..pi, 0..2pi or -2pi..0 interval 12 | if (circular) { 13 | y_diff <- preprocess_circular(y_diff) 14 | y_diff <- as.numeric(y_diff) 15 | } 16 | 17 | # max diff 18 | if (!is.null(max_diff)) { 19 | y_diff[y_diff > max_diff] <- max_diff 20 | y_diff[y_diff < -max_diff] <- -max_diff 21 | } 22 | 23 | # get 95% HDI 24 | hdi <- mcmc_hdi(y_diff) 25 | 26 | # mean difference 27 | mean_diff <- mean(y_diff) 28 | 29 | # get x range 30 | x_min <- min(y_diff) 31 | x_max <- max(y_diff) 32 | 33 | diff <- x_max - x_min 34 | 35 | x_min <- x_min - 0.1*diff 36 | x_max <- x_max + 0.1*diff 37 | 38 | if (!is.null(rope)) { 39 | x_min <- min(x_min, rope[1]) 40 | x_max <- max(x_max, rope[2]) 41 | } 42 | 43 | # create df 44 | df_diff <- data.frame(value=y_diff) 45 | 46 | # basic histogram chart 47 | graph <- ggplot() + 48 | geom_histogram(data=df_diff, aes(x=value), fill="#3182bd", alpha=0.4, bins=bins, na.rm=T) + 49 | xlim(x_min, x_max) 50 | 51 | # add mean 52 | y_max <- max(ggplot_build(graph)$data[[1]]$count) 53 | 54 | # if mean is near min or max hjust inward 55 | hjust_range <- (x_max - x_min) * 0.1 56 | hjust = "center" 57 | if (mean_diff < (x_min + hjust_range) || mean_diff > (x_max - hjust_range)) { 58 | hjust = "inward" 59 | } 60 | 61 | graph <- graph + 62 | geom_segment(aes(x=mean_diff, xend=mean_diff, y=0, yend=y_max * 1.05), size=1.5, color="#3182bd", na.rm=T) + 63 | geom_text(aes(label=sprintf("%.2f", mean_diff), x=mean_diff, y=y_max * (1.05 + (nrow * 0.05))), size=4, hjust=hjust) 64 | 65 | # add HDI 66 | graph <- graph + 67 | geom_segment(aes(x=hdi[1], xend=hdi[2], y=y_max * 0.01 * nrow, yend=y_max * 0.01 * nrow), size=2.5, color="black", na.rm=T) 68 | 69 | hjust = "center" 70 | if (hdi[1] < (x_min + hjust_range)) { 71 | hjust = "inward" 72 | } 73 | 74 | graph <- graph + 75 | geom_text(aes(label=sprintf("%.2f", hdi[1]), x=hdi[1], y=y_max * (0.05 * nrow)), size=3.5, hjust=hjust) 76 | 77 | if (hdi[2] > (x_max - hjust_range)) { 78 | hjust = "inward" 79 | } 80 | 81 | graph <- graph + 82 | geom_text(aes(label=sprintf("%.2f", hdi[2]), x=hdi[2], y=y_max * (0.05 * nrow)), size=3.5, hjust=hjust) 83 | 84 | # add ROPE interval? 85 | if (!is.null(rope)) { 86 | graph <- graph + 87 | geom_segment(aes(x=rope[1], xend=rope[2], y=-(y_max * 0.01 * nrow), yend=-(y_max * 0.01 * nrow)), size=2.5, color="grey50", na.rm=T) 88 | } 89 | 90 | # style and labels 91 | graph <- graph + 92 | xlab("difference") 93 | 94 | return(graph) 95 | } 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bayes4psy—User Friendly Bayesian Data Analysis for Psychology 2 | 3 | 4 | [![R-CMD-check](https://github.com/bstatcomp/bayes4psy/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/bstatcomp/bayes4psy/actions/workflows/R-CMD-check.yaml) 5 | [![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/bayes4psy?color=blue)](https://CRAN.R-project.org/package=bayes4psy)[![Downloads](http://cranlogs.r-pkg.org/badges/bayes4psy?color=blue)](https://CRAN.R-project.org/package=bayes4psy) 6 | 7 | 8 | ## Authors 9 | 10 | Jure Demšar, Grega Repovš and Erik Štrumbelj 11 | 12 | * Faculty of Computer and Information Science, University of Ljubljana 13 | * MBLab, Department of Psychology, Faculty of Arts, University of Ljubljana 14 | 15 | ## The package 16 | 17 | This is an R package intended for Bayesian statistical analysis in the field of psychology. Psychology is one of the fields where [the replication crisis](https://en.wikipedia.org/wiki/Replication_crisis) is the most prominent. Scientist believe that one of the main reason for this might be non-transparent and inappropriate use of frequentist statistics. We believe that using fully transparent Bayesian methods provided in this package could greatly alleviate the replication crisis in psychology. 18 | 19 | We also prepared several examples where we used the **bayes4psy** package to perform Bayesian data analysis for scientific publications on actual data gathered by psychological tests. These examples can be found on our [GitHub repository](https://github.com/bstatcomp/bayes4psy_tools). This repository also includes short test scenarios (these scenarios execute all developed functionalities on dummy data) intended for debugging the package. 20 | 21 | This readme document provides only a brief overview of the package, a detailed description of all implemented functions is provided in package's help pages. 22 | 23 | ## Models 24 | 25 | Bayesian models in the **bayes4psy** package are written with the [Stan](https://mc-stan.org) language. Stan functions required for working with these models are accessed via the **RStan** package. There are currently five models in the package: 26 | 27 | * a Bayesian t-test (Bayesian alternative to the classic t-test, see John Kruschke -- Doing Bayesian Data Analysis: A Tutorial with R, JAGS, and Stan), 28 | * a reaction time model (a hierarchical exponentially modified Gaussian model), 29 | * a success rate model (a hierarchical Bernoulli-Beta model), 30 | * a linear model (a hierarchical linear regression), 31 | * a color model (normal/Von Mises model). 32 | 33 | ## Model fitting 34 | 35 | The fitted model objects returned by the **bayes4psy** package are called _b\_results_ objects. These objects contain three components, _extract_ contains values of fitted parameters, _fit_ is the original _stanfit_ object and _data_ is the input data used for fitting. To fit a model to the data one has to first prepare the input data and then call an appropriate fitting function: 36 | 37 | * b_ttest (the Bayesian t-test), 38 | * b_reaction_time (the reaction time model), 39 | * b_success_rate (the success rate model, 40 | * b_linear (the linear model), 41 | * b_color (the color model). 42 | 43 | If no priors are provided as parameters for fitting functions, then flat (improper) priors are put on all parameters. See provided examples and tests to see how one can specify their own priors. 44 | 45 | ## Analyzing fits 46 | 47 | To enable users without extensive programming knowledge to perform professional level Bayesian data analysis we developed a number of custom methods. Below is a short description of functions common to all models, for descriptions of functions specific to certain models consult the package's help pages. 48 | 49 | * __`summary`__ prints a summary of the fit. 50 | * __`print`__, __`show`__ prints a more detailed summary of the fit (same as RStan's _print_ function). 51 | * __`plot_fit`__ visualize the quality of the fitted model against the input data. 52 | * __`plot_trace`__ construct a trace plot for relevant parameters of the fitted model. 53 | * __`get_parameters`__ extracts the parameters of the fitted model. 54 | * __`get_subject_parameters`__ get parameters for each subject (useful only for hierarchical models). 55 | * __`plot_means`__ visualize means for a single or multiple fitted models. 56 | * __`compare_means`__ compare means between two or more fitted models. 57 | * __`plot_means_difference`__ visualize the difference of means between two or more fitted models. 58 | * __`plot_distributions`__ visualize distributions underlying fitted models, can be used to visualize one or more fitted models. 59 | * __`compare_distributions`__ draw and compare samples from distributions underlying fitted models, can be used to compare two or more fitted models. 60 | * __`plot_distributions_difference`__ visualize the difference in distributions underlying fitted models, can be used to compare two or more fitted models. 61 | 62 | ## Resources 63 | 64 | * [bayes4psy_tools](https://github.com/bstatcomp/bayes4psy_tools) repository with real life examples that use the package to perform scientific paper grade Bayesian data analysis. 65 | * [Open an issue](https://github.com/bstatcomp/bayes4psy/issues) GitHub issues for bug reports, feature requests. 66 | * [Stan](https://mc-stan.org/) the Stan homepage. 67 | 68 | ## Development Version 69 | 70 | You can install the development version from GitHub. To do so you first have to install the **RStan** package and C++ toolchain ([instructions](https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started)). Once **RStan** and the toolchain are installed, you can install **bayes4psy** by using the **devtools** package in R: 71 | 72 | ```r 73 | if (!require(devtools)) { 74 | install.packages("devtools") 75 | library(devtools) 76 | } 77 | install_github("bstatcomp/bayes4psy") 78 | ``` 79 | 80 | ## Funding 81 | 82 | The research behind this software was partially funded by the Slovenian Research Agency (ARRS) through grants L1-7542 (Advancement of computationally intensive methods for efficient modern general-purpose statistical analysis and inference), P3-0338 (Physiological mechanisms of neurological disorders and diseases), J3-9264 (Decomposing cognition: working memory mechanism and representations), P5-0410 (Digitalization as driving force for sustainability of individuals, organizations, and society), and P5-0110 (Psychological and neuroscientific aspects of cognition). 83 | -------------------------------------------------------------------------------- /bayes4psy.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageCheckArgs: --no-multiarch 22 | PackageRoxygenize: rd,collate,namespace,vignette 23 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | # Generated by rstantools. Do not edit by hand. 2 | 3 | #! /bin/sh 4 | "${R_HOME}/bin/Rscript" -e "rstantools::rstan_config()" 5 | -------------------------------------------------------------------------------- /configure.win: -------------------------------------------------------------------------------- 1 | # Generated by rstantools. Do not edit by hand. 2 | 3 | #! /bin/sh 4 | "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "rstantools::rstan_config()" 5 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | # Revisions 2 | 3 | ## CRAN submission 26. 9. 2023 4 | 5 | RStan optimizations and updates. 6 | 7 | ## CRAN submission 16. 3. 2023 8 | 9 | Optimized building of RStan models. 10 | 11 | ## CRAN submission 27. 9. 2021 12 | 13 | Additional fixes required for newer versions of the RStan package. 14 | 15 | ## CRAN submission 10. 9. 2021 16 | 17 | Support for newer versions of the RStan package. 18 | 19 | ## CRAN submission 14. 4. 2021 20 | 21 | Further vignettes optimization. The package now uses a stable rstan version. 22 | 23 | ## CRAN submission 7. 12. 2020 24 | 25 | Vignettes are now optimized to enable faster package compilation. 26 | 27 | ## CRAN submission 20. 11. 2020 28 | 29 | Revised tests to avoid stability issues on Solaris. 30 | 31 | ## CRAN submission 19. 2. 2020 32 | 33 | Reran all unit tests manually and corrected all checks. 34 | 35 | ## CRAN submission 17. 2. 2020 36 | 37 | Fixxed errors denoted in the check results report. 38 | 39 | ## CRAN submission 23. 12. 2019 40 | 41 | Everything was OK. 42 | 43 | ## CRAN submission 19. 6. 2019 44 | 45 | 1. CRAN: Omit the redundant part "An R Package for" in your title. Please do not start your Description with "This package", package name or similar. 46 | Response: Done. 47 | 48 | 2. CRAN: Please add small executable examples in your Rd-files. 49 | Response: Added function level examples to exported model fitting functions (b_bootstrap, b_color, b_linear, b_reaction_time, b_success_rate and b_ttest). Added class level examples to classes that represent fitted models (color_class, linear_class, reacion_time_class, success_rate_class, ttest_class), adding to particular functions here does not make sense because these functions cannot be used in a vacuum. 50 | 51 | 3. CRAN: We are missing some authors and copyright holder in the authors list: author Rasmus Baath, author John Kruschke, Trustees of Columbia University. 52 | Response: Authors mentioned above are now added into the Authors@R field. 53 | 54 | ## Test environments 55 | 56 | * local OS X Mojave 10.14.5, R 3.5.4 57 | * local Windows 10, R 3.5.4 58 | * win-builder (R-devel) 59 | * Ubuntu Linux 16.04 LTS (rhub) 60 | * Fedora Linux, R-devel (rhub) 61 | 62 | ## R CMD check results 63 | 64 | There were no ERRORs or WARNINGs. 65 | 66 | There were 2 NOTES: 67 | 68 | * checking installed package size ... NOTE 69 | installed size is 6.1Mb 70 | sub-directories of 1Mb or more: 71 | libs 5.2Mb 72 | 73 | * hecking for GNU extensions in Makefiles ... NOTE 74 | GNU make is a SystemRequirements. 75 | 76 | ## Downstream dependencies 77 | 78 | There are currently no downstream dependencies for this package. 79 | -------------------------------------------------------------------------------- /data/adaptation_level.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bstatcomp/bayes4psy/483cf701cfd3a3a8385c3a79d33bbe81a3269ef2/data/adaptation_level.rda -------------------------------------------------------------------------------- /data/adaptation_level_small.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bstatcomp/bayes4psy/483cf701cfd3a3a8385c3a79d33bbe81a3269ef2/data/adaptation_level_small.rda -------------------------------------------------------------------------------- /data/after_images.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bstatcomp/bayes4psy/483cf701cfd3a3a8385c3a79d33bbe81a3269ef2/data/after_images.rda -------------------------------------------------------------------------------- /data/after_images_opponent_process.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bstatcomp/bayes4psy/483cf701cfd3a3a8385c3a79d33bbe81a3269ef2/data/after_images_opponent_process.rda -------------------------------------------------------------------------------- /data/after_images_stimuli.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bstatcomp/bayes4psy/483cf701cfd3a3a8385c3a79d33bbe81a3269ef2/data/after_images_stimuli.rda -------------------------------------------------------------------------------- /data/after_images_trichromatic.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bstatcomp/bayes4psy/483cf701cfd3a3a8385c3a79d33bbe81a3269ef2/data/after_images_trichromatic.rda -------------------------------------------------------------------------------- /data/flanker.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bstatcomp/bayes4psy/483cf701cfd3a3a8385c3a79d33bbe81a3269ef2/data/flanker.rda -------------------------------------------------------------------------------- /data/stroop_extended.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bstatcomp/bayes4psy/483cf701cfd3a3a8385c3a79d33bbe81a3269ef2/data/stroop_extended.rda -------------------------------------------------------------------------------- /data/stroop_simple.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bstatcomp/bayes4psy/483cf701cfd3a3a8385c3a79d33bbe81a3269ef2/data/stroop_simple.rda -------------------------------------------------------------------------------- /inst/include/stan_meta_header.hpp: -------------------------------------------------------------------------------- 1 | // Insert all #include statements here 2 | -------------------------------------------------------------------------------- /inst/stan/color.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int n; // number of data entries 3 | // rgb 4 | vector[n] r; 5 | vector[n] g; 6 | vector[n] b; 7 | // hsv 8 | vector[n] h; 9 | vector[n] s; 10 | vector[n] v; 11 | 12 | // priors 13 | array[12] int p_ids; 14 | vector[24] p_values; 15 | } 16 | 17 | parameters { 18 | // rgb 19 | real mu_r; 20 | real sigma_r; 21 | real mu_g; 22 | real sigma_g; 23 | real mu_b; 24 | real sigma_b; 25 | 26 | // hsv 27 | real mu_h; 28 | real kappa_h; 29 | real mu_s; 30 | real sigma_s; 31 | real mu_v; 32 | real sigma_v; 33 | } 34 | 35 | model { 36 | // priors 37 | // mu_r 38 | int id = 1; 39 | if (p_ids[id] == 1) { 40 | mu_r ~ uniform(p_values[id*2-1], p_values[id*2]); 41 | } else if (p_ids[id] == 2) { 42 | mu_r ~ normal(p_values[id*2-1], p_values[id*2]); 43 | } else if (p_ids[id] == 3) { 44 | mu_r ~ gamma(p_values[id*2-1], p_values[id*2]); 45 | } else if (p_ids[id] == 4) { 46 | mu_r ~ beta(p_values[id*2-1], p_values[id*2]); 47 | } 48 | // sigma_r 49 | id = 2; 50 | if (p_ids[id] == 1) { 51 | sigma_r ~ uniform(p_values[id*2-1], p_values[id*2]); 52 | } else if (p_ids[id] == 2) { 53 | sigma_r ~ normal(p_values[id*2-1], p_values[id*2]); 54 | } else if (p_ids[id] == 3) { 55 | sigma_r ~ gamma(p_values[id*2-1], p_values[id*2]); 56 | } else if (p_ids[id] == 4) { 57 | sigma_r ~ beta(p_values[id*2-1], p_values[id*2]); 58 | } 59 | 60 | // mu_g 61 | id = 3; 62 | if (p_ids[id] == 1) { 63 | mu_g ~ uniform(p_values[id*2-1], p_values[id*2]); 64 | } else if (p_ids[id] == 2) { 65 | mu_g ~ normal(p_values[id*2-1], p_values[id*2]); 66 | } else if (p_ids[id] == 3) { 67 | mu_g ~ gamma(p_values[id*2-1], p_values[id*2]); 68 | } else if (p_ids[id] == 4) { 69 | mu_g ~ beta(p_values[id*2-1], p_values[id*2]); 70 | } 71 | // sigma_g 72 | id = 4; 73 | if (p_ids[id] == 1) { 74 | sigma_g ~ uniform(p_values[id*2-1], p_values[id*2]); 75 | } else if (p_ids[id] == 2) { 76 | sigma_g ~ normal(p_values[id*2-1], p_values[id*2]); 77 | } else if (p_ids[id] == 3) { 78 | sigma_g ~ gamma(p_values[id*2-1], p_values[id*2]); 79 | } else if (p_ids[id] == 4) { 80 | sigma_g ~ beta(p_values[id*2-1], p_values[id*2]); 81 | } 82 | 83 | // mu_b 84 | id = 5; 85 | if (p_ids[id] == 1) { 86 | mu_b ~ uniform(p_values[id*2-1], p_values[id*2]); 87 | } else if (p_ids[id] == 2) { 88 | mu_b ~ normal(p_values[id*2-1], p_values[id*2]); 89 | } else if (p_ids[id] == 3) { 90 | mu_b ~ gamma(p_values[id*2-1], p_values[id*2]); 91 | } else if (p_ids[id] == 4) { 92 | mu_b ~ beta(p_values[id*2-1], p_values[id*2]); 93 | } 94 | // sigma_b 95 | id = 6; 96 | if (p_ids[id] == 1) { 97 | sigma_b ~ uniform(p_values[id*2-1], p_values[id*2]); 98 | } else if (p_ids[id] == 2) { 99 | sigma_b ~ normal(p_values[id*2-1], p_values[id*2]); 100 | } else if (p_ids[id] == 3) { 101 | sigma_b ~ gamma(p_values[id*2-1], p_values[id*2]); 102 | } else if (p_ids[id] == 4) { 103 | sigma_b ~ beta(p_values[id*2-1], p_values[id*2]); 104 | } 105 | 106 | // mu_h 107 | id = 7; 108 | if (p_ids[id] == 1) { 109 | mu_h ~ uniform(p_values[id*2-1], p_values[id*2]); 110 | } else if (p_ids[id] == 2) { 111 | mu_h ~ normal(p_values[id*2-1], p_values[id*2]); 112 | } else if (p_ids[id] == 3) { 113 | mu_h ~ gamma(p_values[id*2-1], p_values[id*2]); 114 | } else if (p_ids[id] == 4) { 115 | mu_h ~ beta(p_values[id*2-1], p_values[id*2]); 116 | } 117 | // kappa_h 118 | id = 8; 119 | if (p_ids[id] == 1) { 120 | kappa_h ~ uniform(p_values[id*2-1], p_values[id*2]); 121 | } else if (p_ids[id] == 2) { 122 | kappa_h ~ normal(p_values[id*2-1], p_values[id*2]); 123 | } else if (p_ids[id] == 3) { 124 | kappa_h ~ gamma(p_values[id*2-1], p_values[id*2]); 125 | } else if (p_ids[id] == 4) { 126 | kappa_h ~ beta(p_values[id*2-1], p_values[id*2]); 127 | } 128 | 129 | // mu_s 130 | id = 9; 131 | if (p_ids[id] == 1) { 132 | mu_s ~ uniform(p_values[id*2-1], p_values[id*2]); 133 | } else if (p_ids[id] == 2) { 134 | mu_s ~ normal(p_values[id*2-1], p_values[id*2]); 135 | } else if (p_ids[id] == 3) { 136 | mu_s ~ gamma(p_values[id*2-1], p_values[id*2]); 137 | } else if (p_ids[id] == 4) { 138 | mu_s ~ beta(p_values[id*2-1], p_values[id*2]); 139 | } 140 | // sigma_s 141 | id = 10; 142 | if (p_ids[id] == 1) { 143 | sigma_s ~ uniform(p_values[id*2-1], p_values[id*2]); 144 | } else if (p_ids[id] == 2) { 145 | sigma_s ~ normal(p_values[id*2-1], p_values[id*2]); 146 | } else if (p_ids[id] == 3) { 147 | sigma_s ~ gamma(p_values[id*2-1], p_values[id*2]); 148 | } else if (p_ids[id] == 4) { 149 | sigma_s ~ beta(p_values[id*2-1], p_values[id*2]); 150 | } 151 | 152 | // mu_v 153 | id = 11; 154 | if (p_ids[id] == 1) { 155 | mu_v ~ uniform(p_values[id*2-1], p_values[id*2]); 156 | } else if (p_ids[id] == 2) { 157 | mu_v ~ normal(p_values[id*2-1], p_values[id*2]); 158 | } else if (p_ids[id] == 3) { 159 | mu_v ~ gamma(p_values[id*2-1], p_values[id*2]); 160 | } else if (p_ids[id] == 4) { 161 | mu_v ~ beta(p_values[id*2-1], p_values[id*2]); 162 | } 163 | // sigma_v 164 | id = 12; 165 | if (p_ids[id] == 1) { 166 | sigma_v ~ uniform(p_values[id*2-1], p_values[id*2]); 167 | } else if (p_ids[id] == 2) { 168 | sigma_v ~ normal(p_values[id*2-1], p_values[id*2]); 169 | } else if (p_ids[id] == 3) { 170 | sigma_v ~ gamma(p_values[id*2-1], p_values[id*2]); 171 | } else if (p_ids[id] == 4) { 172 | sigma_v ~ beta(p_values[id*2-1], p_values[id*2]); 173 | } 174 | 175 | // posteriors 176 | // rgb 177 | r ~ normal(mu_r, sigma_r); 178 | g ~ normal(mu_g, sigma_g); 179 | b ~ normal(mu_b, sigma_b); 180 | // hsv 181 | h ~ von_mises(mu_h, kappa_h); 182 | s ~ normal(mu_s, sigma_s); 183 | v ~ normal(mu_v, sigma_v); 184 | } 185 | -------------------------------------------------------------------------------- /inst/stan/include/license.stan: -------------------------------------------------------------------------------- 1 | /* 2 | bayes4psy is free software: you can redistribute it and/or modify 3 | it under the terms of the GNU General Public License as published by 4 | the Free Software Foundation, either version 3 of the License, or 5 | (at your option) any later version. 6 | 7 | bayes4psy is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with bayes4psy. If not, see . 14 | */ 15 | -------------------------------------------------------------------------------- /inst/stan/linear.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int n; // total number of measurements 3 | int m; // number of subjects 4 | vector[n] x; // sequence/time 5 | vector[n] y; // response 6 | array[n] int s; // subject ids 7 | 8 | // priors 9 | array[6] int p_ids; 10 | vector[12] p_values; 11 | } 12 | 13 | parameters { 14 | // per subject parameters 15 | vector[m] alpha; 16 | vector[m] beta; 17 | vector[m] sigma; 18 | 19 | // global parameters 20 | real mu_a; 21 | real mu_b; 22 | real mu_s; 23 | real sigma_a; 24 | real sigma_b; 25 | real sigma_s; 26 | } 27 | 28 | model { 29 | // priors 30 | // mu_a 31 | int id = 1; 32 | if (p_ids[id] == 1) { 33 | mu_a ~ uniform(p_values[id*2-1], p_values[id*2]); 34 | } else if (p_ids[id] == 2) { 35 | mu_a ~ normal(p_values[id*2-1], p_values[id*2]); 36 | } else if (p_ids[id] == 3) { 37 | mu_a ~ gamma(p_values[id*2-1], p_values[id*2]); 38 | } else if (p_ids[id] == 4) { 39 | mu_a ~ beta(p_values[id*2-1], p_values[id*2]); 40 | } 41 | // sigma_a 42 | id = 2; 43 | if (p_ids[id] == 1) { 44 | sigma_a ~ uniform(p_values[id*2-1], p_values[id*2]); 45 | } else if (p_ids[id] == 2) { 46 | sigma_a ~ normal(p_values[id*2-1], p_values[id*2]); 47 | } else if (p_ids[id] == 3) { 48 | sigma_a ~ gamma(p_values[id*2-1], p_values[id*2]); 49 | } else if (p_ids[id] == 4) { 50 | sigma_a ~ beta(p_values[id*2-1], p_values[id*2]); 51 | } 52 | 53 | // mu_b 54 | id = 3; 55 | if (p_ids[id] == 1) { 56 | mu_b ~ uniform(p_values[id*2-1], p_values[id*2]); 57 | } else if (p_ids[id] == 2) { 58 | mu_b ~ normal(p_values[id*2-1], p_values[id*2]); 59 | } else if (p_ids[id] == 3) { 60 | mu_b ~ gamma(p_values[id*2-1], p_values[id*2]); 61 | } else if (p_ids[id] == 4) { 62 | mu_b ~ beta(p_values[id*2-1], p_values[id*2]); 63 | } 64 | // sigma_b 65 | id = 4; 66 | if (p_ids[id] == 1) { 67 | sigma_b ~ uniform(p_values[id*2-1], p_values[id*2]); 68 | } else if (p_ids[id] == 2) { 69 | sigma_b ~ normal(p_values[id*2-1], p_values[id*2]); 70 | } else if (p_ids[id] == 3) { 71 | sigma_b ~ gamma(p_values[id*2-1], p_values[id*2]); 72 | } else if (p_ids[id] == 4) { 73 | sigma_b ~ beta(p_values[id*2-1], p_values[id*2]); 74 | } 75 | 76 | // mu_s 77 | id = 5; 78 | if (p_ids[id] == 1) { 79 | mu_s ~ uniform(p_values[id*2-1], p_values[id*2]); 80 | } else if (p_ids[id] == 2) { 81 | mu_s ~ normal(p_values[id*2-1], p_values[id*2]); 82 | } else if (p_ids[id] == 3) { 83 | mu_s ~ gamma(p_values[id*2-1], p_values[id*2]); 84 | } else if (p_ids[id] == 4) { 85 | mu_s ~ beta(p_values[id*2-1], p_values[id*2]); 86 | } 87 | // sigma_s 88 | id = 6; 89 | if (p_ids[id] == 1) { 90 | sigma_s ~ uniform(p_values[id*2-1], p_values[id*2]); 91 | } else if (p_ids[id] == 2) { 92 | sigma_s ~ normal(p_values[id*2-1], p_values[id*2]); 93 | } else if (p_ids[id] == 3) { 94 | sigma_s ~ gamma(p_values[id*2-1], p_values[id*2]); 95 | } else if (p_ids[id] == 4) { 96 | sigma_s ~ beta(p_values[id*2-1], p_values[id*2]); 97 | } 98 | 99 | alpha ~ normal(mu_a, sigma_a); 100 | beta ~ normal(mu_b, sigma_b); 101 | sigma ~ normal(mu_s, sigma_s); 102 | 103 | for (i in 1:n) 104 | y[i] ~ normal(alpha[s[i]] + beta[s[i]] * x[i], sigma[s[i]]); 105 | } 106 | -------------------------------------------------------------------------------- /inst/stan/reaction_time.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int n; // total number of measurements 3 | int m; // number of subjects 4 | vector[n] t; // reaction times 5 | array[n] int s; // subject ids 6 | 7 | // priors 8 | array[6] int p_ids; 9 | vector[12] p_values; 10 | } 11 | 12 | parameters { 13 | // per subject parameters 14 | vector[m] mu; 15 | vector[m] sigma; 16 | vector[m] lambda; 17 | 18 | // global parameters 19 | real mu_m; 20 | real mu_l; 21 | real mu_s; 22 | real sigma_m; 23 | real sigma_l; 24 | real sigma_s; 25 | } 26 | 27 | model { 28 | // priors 29 | // mu_m 30 | int id = 1; 31 | if (p_ids[id] == 1) { 32 | mu_m ~ uniform(p_values[id*2-1], p_values[id*2]); 33 | } else if (p_ids[id] == 2) { 34 | mu_m ~ normal(p_values[id*2-1], p_values[id*2]); 35 | } else if (p_ids[id] == 3) { 36 | mu_m ~ gamma(p_values[id*2-1], p_values[id*2]); 37 | } else if (p_ids[id] == 4) { 38 | mu_m ~ beta(p_values[id*2-1], p_values[id*2]); 39 | } 40 | // sigma_m 41 | id = 2; 42 | if (p_ids[id] == 1) { 43 | sigma_m ~ uniform(p_values[id*2-1], p_values[id*2]); 44 | } else if (p_ids[id] == 2) { 45 | sigma_m ~ normal(p_values[id*2-1], p_values[id*2]); 46 | } else if (p_ids[id] == 3) { 47 | sigma_m ~ gamma(p_values[id*2-1], p_values[id*2]); 48 | } else if (p_ids[id] == 4) { 49 | sigma_m ~ beta(p_values[id*2-1], p_values[id*2]); 50 | } 51 | 52 | // mu_s 53 | id = 3; 54 | if (p_ids[id] == 1) { 55 | mu_s ~ uniform(p_values[id*2-1], p_values[id*2]); 56 | } else if (p_ids[id] == 2) { 57 | mu_s ~ normal(p_values[id*2-1], p_values[id*2]); 58 | } else if (p_ids[id] == 3) { 59 | mu_s ~ gamma(p_values[id*2-1], p_values[id*2]); 60 | } else if (p_ids[id] == 4) { 61 | mu_s ~ beta(p_values[id*2-1], p_values[id*2]); 62 | } 63 | // sigma_s 64 | id = 4; 65 | if (p_ids[id] == 1) { 66 | sigma_s ~ uniform(p_values[id*2-1], p_values[id*2]); 67 | } else if (p_ids[id] == 2) { 68 | sigma_s ~ normal(p_values[id*2-1], p_values[id*2]); 69 | } else if (p_ids[id] == 3) { 70 | sigma_s ~ gamma(p_values[id*2-1], p_values[id*2]); 71 | } else if (p_ids[id] == 4) { 72 | sigma_s ~ beta(p_values[id*2-1], p_values[id*2]); 73 | } 74 | 75 | // mu_l 76 | id = 5; 77 | if (p_ids[id] == 1) { 78 | mu_l ~ uniform(p_values[id*2-1], p_values[id*2]); 79 | } else if (p_ids[id] == 2) { 80 | mu_l ~ normal(p_values[id*2-1], p_values[id*2]); 81 | } else if (p_ids[id] == 3) { 82 | mu_l ~ gamma(p_values[id*2-1], p_values[id*2]); 83 | } else if (p_ids[id] == 4) { 84 | mu_l ~ beta(p_values[id*2-1], p_values[id*2]); 85 | } 86 | // sigma_l 87 | id = 6; 88 | if (p_ids[id] == 1) { 89 | sigma_l ~ uniform(p_values[id*2-1], p_values[id*2]); 90 | } else if (p_ids[id] == 2) { 91 | sigma_l ~ normal(p_values[id*2-1], p_values[id*2]); 92 | } else if (p_ids[id] == 3) { 93 | sigma_l ~ gamma(p_values[id*2-1], p_values[id*2]); 94 | } else if (p_ids[id] == 4) { 95 | sigma_l ~ beta(p_values[id*2-1], p_values[id*2]); 96 | } 97 | 98 | mu ~ normal(mu_m, sigma_m); 99 | sigma ~ normal(mu_s, sigma_s); 100 | lambda ~ normal(mu_l, sigma_l); 101 | 102 | // iterate over all measurements 103 | for (i in 1:n) { 104 | t[i] ~ exp_mod_normal(mu[s[i]], sigma[s[i]], lambda[s[i]]); 105 | } 106 | } 107 | 108 | generated quantities { 109 | real rt; 110 | vector[m] rt_subjects; 111 | 112 | rt = mu_m + 1/mu_l; 113 | for (i in 1:m) { 114 | rt_subjects[i] = mu[i] + 1/lambda[i]; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /inst/stan/success_rate.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int n; // total number of measurements 3 | int m; // number of subjects 4 | array[n] int r; // results - success or fail 5 | array[n] int s; // subject ids 6 | 7 | // priors 8 | array[2] int p_ids; 9 | array[4] real p_values; 10 | } 11 | 12 | parameters { 13 | // global parameters 14 | real p0; 15 | real tau; 16 | 17 | // success per subject 18 | vector[m] p; 19 | } 20 | 21 | model { 22 | // priors 23 | // p0 24 | int id = 1; 25 | if (p_ids[id] == 1) { 26 | p0 ~ uniform(p_values[id*2-1], p_values[id*2]); 27 | } else if (p_ids[id] == 2) { 28 | p0 ~ normal(p_values[id*2-1], p_values[id*2]); 29 | } else if (p_ids[id] == 3) { 30 | p0 ~ gamma(p_values[id*2-1], p_values[id*2]); 31 | } else if (p_ids[id] == 4) { 32 | p0 ~ beta(p_values[id*2-1], p_values[id*2]); 33 | } 34 | 35 | // tau 36 | id = 2; 37 | if (p_ids[id] == 1) { 38 | tau ~ uniform(p_values[id*2-1], p_values[id*2]); 39 | } else if (p_ids[id] == 2) { 40 | tau ~ normal(p_values[id*2-1], p_values[id*2]); 41 | } else if (p_ids[id] == 3) { 42 | tau ~ gamma(p_values[id*2-1], p_values[id*2]); 43 | } else if (p_ids[id] == 4) { 44 | tau ~ beta(p_values[id*2-1], p_values[id*2]); 45 | } 46 | 47 | // percentage 48 | p ~ beta(p0*tau, (1 - p0)*tau); 49 | 50 | // iterate over all measurements 51 | for (i in 1:n) { 52 | r[i] ~ bernoulli(p[s[i]]); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /inst/stan/ttest.stan: -------------------------------------------------------------------------------- 1 | data { 2 | int n; // number of samples 3 | vector[n] y; 4 | 5 | // priors 6 | array[3] int p_ids; 7 | vector[6] p_values; 8 | } 9 | 10 | parameters { 11 | real mu; 12 | real sigma; 13 | real nu; 14 | } 15 | 16 | model { 17 | // priors 18 | // mu 19 | int id = 1; 20 | if (p_ids[id] == 1) { 21 | mu ~ uniform(p_values[id*2-1], p_values[id*2]); 22 | } else if (p_ids[id] == 2) { 23 | mu ~ normal(p_values[id*2-1], p_values[id*2]); 24 | } else if (p_ids[id] == 3) { 25 | mu ~ gamma(p_values[id*2-1], p_values[id*2]); 26 | } else if (p_ids[id] == 4) { 27 | mu ~ beta(p_values[id*2-1], p_values[id*2]); 28 | } 29 | 30 | // sigma 31 | id = 2; 32 | if (p_ids[id] == 1) { 33 | sigma ~ uniform(p_values[id*2-1], p_values[id*2]); 34 | } else if (p_ids[id] == 2) { 35 | sigma ~ normal(p_values[id*2-1], p_values[id*2]); 36 | } else if (p_ids[id] == 3) { 37 | sigma ~ gamma(p_values[id*2-1], p_values[id*2]); 38 | } else if (p_ids[id] == 4) { 39 | sigma ~ beta(p_values[id*2-1], p_values[id*2]); 40 | } 41 | 42 | // nu 43 | id = 3; 44 | if (p_ids[id] == 1) { 45 | nu ~ uniform(p_values[id*2-1], p_values[id*2]); 46 | } else if (p_ids[id] == 2) { 47 | nu ~ normal(p_values[id*2-1], p_values[id*2]); 48 | } else if (p_ids[id] == 3) { 49 | nu ~ gamma(p_values[id*2-1], p_values[id*2]); 50 | } else if (p_ids[id] == 4) { 51 | nu ~ beta(p_values[id*2-1], p_values[id*2]); 52 | } else { 53 | nu ~ exponential(1.0/29.0); 54 | } 55 | 56 | y ~ student_t(nu, mu, sigma); 57 | } 58 | -------------------------------------------------------------------------------- /man/b_bootstrap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_bootstrap.R 3 | \name{b_bootstrap} 4 | \alias{b_bootstrap} 5 | \title{b_bootstrap} 6 | \usage{ 7 | b_bootstrap( 8 | data, 9 | statistic, 10 | n1 = 1000, 11 | n2 = 1000, 12 | use_weights = FALSE, 13 | weight_arg = NULL, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{data}{The data as either a vector, matrix or data.frame.} 19 | 20 | \item{statistic}{A function that accepts data as its first argument and if use_weights is TRUE the weights as its second argument. Function should return a numeric vector.} 21 | 22 | \item{n1}{The size of the bootstrap sample (default = 1000).} 23 | 24 | \item{n2}{The sample size used to calculate the statistic each bootstrap draw (default = 1000).} 25 | 26 | \item{use_weights}{Whether the statistic function accepts a weight argument or should be calculated using resampled data (default = FALSE).} 27 | 28 | \item{weight_arg}{If the statistic function includes a named argument for the weights this could be specified here (default = NULL).} 29 | 30 | \item{...}{Further arguments passed on to the statistic function.} 31 | } 32 | \value{ 33 | A data frame containing bootstrap samples. 34 | } 35 | \description{ 36 | 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). 37 | } 38 | \examples{ 39 | 40 | # linear function of seqence vs. response 41 | lm_statistic <- function(data) { 42 | lm(sequence ~ response, data)$coef 43 | } 44 | 45 | # load data 46 | data <- adaptation_level_small 47 | 48 | # bootstrap 49 | data_bootstrap <- b_bootstrap(data, lm_statistic, n1 = 1000, n2 = 1000) 50 | 51 | } 52 | \references{ 53 | \url{https://www.sumsar.net/blog/2015/07/easy-bayesian-bootstrap-in-r/} 54 | 55 | Rubin, D. B. (1981). The Bayesian Bootstrap. The annals of statistics, 9(1), 130-134. 56 | } 57 | \author{ 58 | Rasmus Baath 59 | } 60 | -------------------------------------------------------------------------------- /man/b_color.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_color.R 3 | \name{b_color} 4 | \alias{b_color} 5 | \title{b_color} 6 | \usage{ 7 | b_color( 8 | colors, 9 | priors = NULL, 10 | hsv = FALSE, 11 | warmup = 1000, 12 | iter = 2000, 13 | chains = 4, 14 | seed = NULL, 15 | refresh = NULL, 16 | control = NULL, 17 | suppress_warnings = TRUE 18 | ) 19 | } 20 | \arguments{ 21 | \item{colors}{a data frame of colors either in RGB or HSV format. The first column should be the R (or H) component, the second column should be the G (or S) component and the third column should be the B (or V) component.} 22 | 23 | \item{priors}{List of parameters and their priors - b_prior objects. You can put a prior on the mu_r (mean r component), sigma_r (variance of mu_r), mu_g (mean g component), sigma_g (variance of mu_g), mu_b (mean b component), sigma_b (variance of mu_b), mu_h (mean h component), kappa_h (variance of mu_h), mu_s (mean s component), sigma_s (variance of mu_s), mu_v (mean v component) and sigma_v (variance of mu_v) parameters (default = NULL).} 24 | 25 | \item{hsv}{set to TRUE if colors are provided in HSV format (default = FALSE).} 26 | 27 | \item{warmup}{Integer specifying the number of warmup iterations per chain (default = 1000).} 28 | 29 | \item{iter}{Integer specifying the number of iterations (including warmup, default = 2000).} 30 | 31 | \item{chains}{Integer specifying the number of parallel chains (default = 4).} 32 | 33 | \item{seed}{Random number generator seed (default = NULL).} 34 | 35 | \item{refresh}{Frequency of output (default = NULL).} 36 | 37 | \item{control}{A named list of parameters to control the sampler's behavior (default = NULL).} 38 | 39 | \item{suppress_warnings}{Suppress warnings returned by Stan (default = TRUE).} 40 | } 41 | \value{ 42 | An object of class `color_class` 43 | } 44 | \description{ 45 | Bayesian model for comparing colors. 46 | } 47 | \examples{ 48 | \donttest{ 49 | # priors for rgb 50 | mu_prior <- b_prior(family="uniform", pars=c(0, 255)) 51 | sigma_prior <- b_prior(family="uniform", pars=c(0, 100)) 52 | 53 | # attach priors to relevant parameters 54 | priors_rgb <- list(c("mu_r", mu_prior), 55 | c("sigma_r", sigma_prior), 56 | c("mu_g", mu_prior), 57 | c("sigma_g", sigma_prior), 58 | c("mu_b", mu_prior), 59 | c("sigma_b", sigma_prior)) 60 | 61 | 62 | # generate data (rgb) 63 | r <- as.integer(rnorm(100, mean=250, sd=20)) 64 | r[r > 255] <- 255 65 | r[r < 0] <- 0 66 | 67 | g <- as.integer(rnorm(100, mean=20, sd=20)) 68 | g[g > 255] <- 255 69 | g[g < 0] <- 0 70 | 71 | b <- as.integer(rnorm(100, mean=40, sd=20)) 72 | b[b > 255] <- 255 73 | b[b < 0] <- 0 74 | 75 | colors_rgb <- data.frame(r=r, g=g, b=b) 76 | 77 | # fit 78 | fit_rgb <- b_color(colors=colors_rgb, priors=priors_rgb, chains=1) 79 | 80 | 81 | # priors for hsv 82 | h_prior <- b_prior(family="uniform", pars=c(0, 2*pi)) 83 | sv_prior <- b_prior(family="uniform", pars=c(0, 1)) 84 | kappa_prior <- b_prior(family="uniform", pars=c(0, 500)) 85 | sigma_prior <- b_prior(family="uniform", pars=c(0, 1)) 86 | 87 | # attach priors to relevant parameters 88 | priors_hsv <- list(c("mu_h", h_prior), 89 | c("kappa_h", kappa_prior), 90 | c("mu_s", sv_prior), 91 | c("sigma_s", sigma_prior), 92 | c("mu_v", sv_prior), 93 | c("sigma_v", sigma_prior)) 94 | 95 | # generate data (hsv) 96 | h <- rnorm(100, mean=2*pi/3, sd=0.5) 97 | h[h > 2*pi] <- 2*pi 98 | h[h < 0] <- 0 99 | 100 | s <- rnorm(100, mean=0.9, sd=0.2) 101 | s[s > 1] <- 1 102 | s[s < 0] <- 0 103 | 104 | v <- rnorm(100, mean=0.9, sd=0.2) 105 | v[v > 1] <- 1 106 | v[v < 0] <- 0 107 | 108 | colors_hsv <- data.frame(h=h, s=s, v=v) 109 | 110 | # fit 111 | fit_hsv <- b_color(colors=colors_hsv, hsv=TRUE, priors=priors_hsv, chains=1) 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /man/b_linear.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_linear.R 3 | \name{b_linear} 4 | \alias{b_linear} 5 | \title{b_linear} 6 | \usage{ 7 | b_linear( 8 | x, 9 | y, 10 | s, 11 | priors = NULL, 12 | warmup = 1000, 13 | iter = 2000, 14 | chains = 4, 15 | seed = NULL, 16 | refresh = NULL, 17 | control = NULL, 18 | suppress_warnings = TRUE 19 | ) 20 | } 21 | \arguments{ 22 | \item{x}{a vector containing sequence indexes (time).} 23 | 24 | \item{y}{a vector containing responses of subjects.} 25 | 26 | \item{s}{a vector containing subject indexes. Starting index should be 1 and the largest subject index should equal the number of subjects.} 27 | 28 | \item{priors}{List of parameters and their priors - b_prior objects. You can put a prior on the mu_a (mean intercept), sigma_a (variance of mu_a), mu_b (mean slope), sigma_s (variance of mu_b), mu_s (variance) and sigma_s (variance of mu_s) parameters (default = NULL).} 29 | 30 | \item{warmup}{Integer specifying the number of warmup iterations per chain (default = 1000).} 31 | 32 | \item{iter}{Integer specifying the number of iterations (including warmup, default = 2000).} 33 | 34 | \item{chains}{Integer specifying the number of parallel chains (default = 4).} 35 | 36 | \item{seed}{Random number generator seed (default = NULL).} 37 | 38 | \item{refresh}{Frequency of output (default = NULL).} 39 | 40 | \item{control}{A named list of parameters to control the sampler's behavior (default = NULL).} 41 | 42 | \item{suppress_warnings}{Suppress warnings returned by Stan (default = TRUE).} 43 | } 44 | \value{ 45 | An object of class `linear_class`. 46 | } 47 | \description{ 48 | Bayesian model for fitting a linear normal model to data. 49 | } 50 | \examples{ 51 | \donttest{ 52 | # priors 53 | mu_prior <- b_prior(family="normal", pars=c(0, 100)) 54 | sigma_prior <- b_prior(family="uniform", pars=c(0, 500)) 55 | 56 | # attach priors to relevant parameters 57 | priors <- list(c("mu_a", mu_prior), 58 | c("sigma_a", sigma_prior), 59 | c("mu_b", mu_prior), 60 | c("sigma_b", sigma_prior), 61 | c("mu_s", sigma_prior), 62 | c("sigma_s", sigma_prior)) 63 | 64 | # generate data 65 | x <- vector() 66 | y <- vector() 67 | s <- vector() 68 | for (i in 1:5) { 69 | x <- c(x, rep(1:10, 2)) 70 | y <- c(y, rnorm(20, mean=1:10, sd=2)) 71 | s <- c(s, rep(i, 20)) 72 | } 73 | 74 | fit <- b_linear(x=x, y=y, s=s, priors=priors, chains=1) 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /man/b_prior-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_prior.R 3 | \docType{class} 4 | \name{b_prior-class} 5 | \alias{b_prior-class} 6 | \alias{b_prior} 7 | \title{b_prior} 8 | \description{ 9 | An S4 class for defining priors for Bayesian models. 10 | } 11 | \section{Slots}{ 12 | 13 | \describe{ 14 | \item{\code{family}}{Prior family - \"uniform\", \"normal\", \"gamma\" or \"beta\".} 15 | 16 | \item{\code{pars}}{Parameters of the prior - a vector of two numerical values.} 17 | }} 18 | 19 | -------------------------------------------------------------------------------- /man/b_prior-get_prior_id.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_prior.R 3 | \name{get_prior_id} 4 | \alias{get_prior_id} 5 | \alias{get_prior_id,b_prior-method} 6 | \alias{get_prior_id_b_prior} 7 | \title{get_prior_id} 8 | \usage{ 9 | get_prior_id(object) 10 | 11 | \S4method{get_prior_id}{b_prior}(object) 12 | } 13 | \arguments{ 14 | \item{object}{b_prior object.} 15 | } 16 | \description{ 17 | \code{get_prior_id} returns an integer id of prior's family (1 = uniform, 2 = normal, 3 = gamma, 4 = beta). 18 | } 19 | -------------------------------------------------------------------------------- /man/b_reaction_time.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_reaction_time.R 3 | \name{b_reaction_time} 4 | \alias{b_reaction_time} 5 | \title{b_reaction_time} 6 | \usage{ 7 | b_reaction_time( 8 | t, 9 | s, 10 | priors = NULL, 11 | warmup = 1000, 12 | iter = 2000, 13 | chains = 4, 14 | seed = NULL, 15 | refresh = NULL, 16 | control = NULL, 17 | suppress_warnings = TRUE 18 | ) 19 | } 20 | \arguments{ 21 | \item{t}{a vector containing reaction times for each measurement.} 22 | 23 | \item{s}{a vector containing subject indexes. Starting index should be 1 and the largest subject index should equal the number of subjects.} 24 | 25 | \item{priors}{List of parameters and their priors - b_prior objects. You can put a prior on the mu_m (mean), sigma_m (variance of mu_m), mu_s (variance), sigma_s (variance of mu_s), mu_l (mean of the exponent factor) and sigma_l (variance of mu_l) parameters (default = NULL).} 26 | 27 | \item{warmup}{Integer specifying the number of warmup iterations per chain (default = 1000).} 28 | 29 | \item{iter}{Integer specifying the number of iterations (including warmup, default = 2000).} 30 | 31 | \item{chains}{Integer specifying the number of parallel chains (default = 4).} 32 | 33 | \item{seed}{Random number generator seed (default = NULL).} 34 | 35 | \item{refresh}{Frequency of output (default = NULL).} 36 | 37 | \item{control}{A named list of parameters to control the sampler's behavior (default = NULL).} 38 | 39 | \item{suppress_warnings}{Suppress warnings returned by Stan (default = TRUE).} 40 | } 41 | \value{ 42 | An object of class `reaction_time_class` 43 | } 44 | \description{ 45 | Bayesian model for comparing reaction times. 46 | } 47 | \examples{ 48 | \donttest{ 49 | # priors 50 | mu_prior <- b_prior(family="normal", pars=c(0, 100)) 51 | sigma_prior <- b_prior(family="uniform", pars=c(0, 500)) 52 | lambda_prior <- b_prior(family="uniform", pars=c(0.05, 5)) 53 | 54 | # attach priors to relevant parameters 55 | priors <- list(c("mu_m", mu_prior), 56 | c("sigma_m", sigma_prior), 57 | c("mu_s", sigma_prior), 58 | c("sigma_s", sigma_prior), 59 | c("mu_l", lambda_prior), 60 | c("sigma_l", sigma_prior)) 61 | 62 | # generate data 63 | s <- rep(1:5, 20) 64 | rt <- emg::remg(100, mu=10, sigma=1, lambda=0.4) 65 | 66 | # fit 67 | fit <- b_reaction_time(t=rt, s=s, priors=priors, chains=1) 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /man/b_results-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_results.R 3 | \docType{class} 4 | \name{b_results-class} 5 | \alias{b_results-class} 6 | \title{b_results} 7 | \description{ 8 | Parent S4 class for declaring shared function generics. 9 | } 10 | -------------------------------------------------------------------------------- /man/b_results-compare_distributions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_results.R 3 | \name{compare_distributions} 4 | \alias{compare_distributions} 5 | \title{compare_distributions} 6 | \usage{ 7 | compare_distributions(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{S4 class object from bayes4psy library.} 11 | 12 | \item{...}{see documentation for specific class for the description of available parameters, e.g. ?compare_distributions_ttest or ?compare_distributions_linear.} 13 | } 14 | \description{ 15 | \code{compare_distributions} draws samples from distribution of the first fit and compares them against samples drawn from the distribution of the second fit, or against samples from multiple fits. 16 | } 17 | -------------------------------------------------------------------------------- /man/b_results-compare_means.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_results.R 3 | \name{compare_means} 4 | \alias{compare_means} 5 | \title{compare_means} 6 | \usage{ 7 | compare_means(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{S4 class object from bayes4psy library.} 11 | 12 | \item{...}{see documentation for specific class for the description of available parameters, e.g. ?compare_means_ttest or ?compare_means_linear.} 13 | } 14 | \description{ 15 | \code{compare_means} prints difference between means of two or multiple fits. 16 | } 17 | -------------------------------------------------------------------------------- /man/b_results-get_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_results.R 3 | \name{get_parameters} 4 | \alias{get_parameters} 5 | \title{get_parameters} 6 | \usage{ 7 | get_parameters(object) 8 | } 9 | \arguments{ 10 | \item{object}{S4 class object from bayes4psy library.} 11 | } 12 | \description{ 13 | \code{get_parameters} returns a dataframe with values of fitted parameters. 14 | } 15 | -------------------------------------------------------------------------------- /man/b_results-get_subject_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_results.R 3 | \name{get_subject_parameters} 4 | \alias{get_subject_parameters} 5 | \title{get_subject_parameters} 6 | \usage{ 7 | get_subject_parameters(object) 8 | } 9 | \arguments{ 10 | \item{object}{S4 class object from bayes4psy library.} 11 | } 12 | \description{ 13 | \code{get_subject_parameters} returns a dataframe with values of fitted parameters for each subject in the hierarchical model. 14 | } 15 | -------------------------------------------------------------------------------- /man/b_results-plot_distributions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_results.R 3 | \name{plot_distributions} 4 | \alias{plot_distributions} 5 | \title{plot_distributions} 6 | \usage{ 7 | plot_distributions(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{S4 class object from bayes4psy library.} 11 | 12 | \item{...}{see documentation for specific class for the description of available parameters, e.g. ?plot_distributions_ttest or ?plot_distributions_linear.} 13 | } 14 | \description{ 15 | \code{plot_distributions} visualizes fitted distributions. 16 | } 17 | -------------------------------------------------------------------------------- /man/b_results-plot_distributions_difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_results.R 3 | \name{plot_distributions_difference} 4 | \alias{plot_distributions_difference} 5 | \title{plot_distributions_difference} 6 | \usage{ 7 | plot_distributions_difference(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{S4 class object from bayes4psy library.} 11 | 12 | \item{...}{see documentation for specific class for the description of available parameters, e.g. ?plot_distributions_difference_ttest or ?plot_distributions_difference_linear.} 13 | } 14 | \description{ 15 | \code{plot_distributions_difference} a visualization of the difference between the distributions of two or more fits. 16 | } 17 | -------------------------------------------------------------------------------- /man/b_results-plot_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_results.R 3 | \name{plot_fit} 4 | \alias{plot_fit} 5 | \title{plot_fit} 6 | \usage{ 7 | plot_fit(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{S4 class object from bayes4psy library.} 11 | 12 | \item{...}{see documentation for specific class for the description of available parameters, e.g. ?plot_fit_colors or ?plot_fit_linear.} 13 | } 14 | \description{ 15 | \code{plot_fit} plots fitted model against the data. Use this function to explore the quality of your fit. 16 | } 17 | -------------------------------------------------------------------------------- /man/b_results-plot_means.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_results.R 3 | \name{plot_means} 4 | \alias{plot_means} 5 | \title{plot_means} 6 | \usage{ 7 | plot_means(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{S4 class object from bayes4psy library.} 11 | 12 | \item{...}{see documentation for specific class for the description of available parameters, e.g. ?plot_means_ttest or ?plot_means_linear.} 13 | } 14 | \description{ 15 | \code{plot_means} plots means for one or multiple fits. 16 | } 17 | -------------------------------------------------------------------------------- /man/b_results-plot_means_difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_results.R 3 | \name{plot_means_difference} 4 | \alias{plot_means_difference} 5 | \title{plot_means_difference} 6 | \usage{ 7 | plot_means_difference(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{S4 class object from bayes4psy library.} 11 | 12 | \item{...}{see documentation for specific class for the description of available parameters, e.g. ?plot_means_difference_ttest or ?plot_means_difference_linear.} 13 | } 14 | \description{ 15 | \code{plot_means_difference} plots difference between means of two or multiple fits. 16 | } 17 | -------------------------------------------------------------------------------- /man/b_results-plot_trace.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_results.R 3 | \name{plot_trace} 4 | \alias{plot_trace} 5 | \title{plot_trace} 6 | \usage{ 7 | plot_trace(object) 8 | } 9 | \arguments{ 10 | \item{object}{S4 class object from bayes4psy library.} 11 | } 12 | \description{ 13 | \code{plot_trace} traceplot for main fitted model parameters. 14 | } 15 | -------------------------------------------------------------------------------- /man/b_success_rate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_success_rate.R 3 | \name{b_success_rate} 4 | \alias{b_success_rate} 5 | \title{b_success_rate} 6 | \usage{ 7 | b_success_rate( 8 | r, 9 | s, 10 | priors = NULL, 11 | warmup = 1000, 12 | iter = 2000, 13 | chains = 4, 14 | seed = NULL, 15 | refresh = NULL, 16 | control = NULL, 17 | suppress_warnings = TRUE 18 | ) 19 | } 20 | \arguments{ 21 | \item{r}{a vector containing test results (0 - test was not solved successfully, 1 - test was solved successfully).} 22 | 23 | \item{s}{a vector containing subject indexes. Starting index should be 1 and the largest subject index should equal the number of subjects.} 24 | 25 | \item{priors}{List of parameters and their priors - b_prior objects. You can put a prior on the p (mean probability of success) and tau (variance) parameters (default = NULL).} 26 | 27 | \item{warmup}{Integer specifying the number of warmup iterations per chain (default = 1000).} 28 | 29 | \item{iter}{Integer specifying the number of iterations (including warmup, default = 2000).} 30 | 31 | \item{chains}{Integer specifying the number of parallel chains (default = 4).} 32 | 33 | \item{seed}{Random number generator seed (default = NULL).} 34 | 35 | \item{refresh}{Frequency of output (default = NULL).} 36 | 37 | \item{control}{A named list of parameters to control the sampler's behavior (default = NULL).} 38 | 39 | \item{suppress_warnings}{Suppress warnings returned by Stan (default = TRUE).} 40 | } 41 | \value{ 42 | An object of class `success_rate_class`. 43 | } 44 | \description{ 45 | Bayesian model for comparing test success rate. 46 | } 47 | \examples{ 48 | \donttest{ 49 | # priors 50 | p_prior <- b_prior(family="beta", pars=c(1, 1)) 51 | tau_prior <- b_prior(family="uniform", pars=c(0, 500)) 52 | 53 | # attach priors to relevant parameters 54 | priors <- list(c("p", p_prior), 55 | c("tau", tau_prior)) 56 | 57 | # generate data 58 | s <- rep(1:5, 20) 59 | data <- rbinom(100, size=1, prob=0.6) 60 | 61 | # fit 62 | fit <- b_success_rate(r=data, s=s, priors=priors, chains=1) 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /man/b_ttest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/b_ttest.R 3 | \name{b_ttest} 4 | \alias{b_ttest} 5 | \title{b_ttest} 6 | \usage{ 7 | b_ttest( 8 | data, 9 | priors = NULL, 10 | warmup = 1000, 11 | iter = 2000, 12 | chains = 4, 13 | seed = NULL, 14 | refresh = NULL, 15 | control = NULL, 16 | suppress_warnings = TRUE 17 | ) 18 | } 19 | \arguments{ 20 | \item{data}{Numeric vector of values on which the fit will be based.} 21 | 22 | \item{priors}{List of parameters and their priors - b_prior objects. You can put a prior on the mu (mean) and sigma (variance) parameters (default = NULL).} 23 | 24 | \item{warmup}{Integer specifying the number of warmup iterations per chain (default = 1000).} 25 | 26 | \item{iter}{Integer specifying the number of iterations (including warmup, default = 2000).} 27 | 28 | \item{chains}{Integer specifying the number of parallel chains (default = 4).} 29 | 30 | \item{seed}{Random number generator seed (default = NULL).} 31 | 32 | \item{refresh}{Frequency of output (default = NULL).} 33 | 34 | \item{control}{A named list of parameters to control the sampler's behavior (default = NULL).} 35 | 36 | \item{suppress_warnings}{Suppress warnings returned by Stan (default = TRUE).} 37 | } 38 | \value{ 39 | An object of class `ttest_class`. 40 | } 41 | \description{ 42 | Bayesian t-test. 43 | } 44 | \examples{ 45 | \donttest{ 46 | # priors 47 | mu_prior <- b_prior(family="normal", pars=c(0, 1000)) 48 | sigma_prior <- b_prior(family="uniform", pars=c(0, 500)) 49 | nu_prior <- b_prior(family="normal", pars=c(2000, 1000)) 50 | 51 | # attach priors to relevant parameters 52 | priors <- list(c("mu", mu_prior), 53 | c("sigma", sigma_prior), 54 | c("nu", nu_prior)) 55 | 56 | # generate some data 57 | data <- rnorm(20, mean=150, sd=20) 58 | 59 | # fit 60 | fit <- b_ttest(data=data, priors=priors, chains=1) 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /man/bayes4psy-datasets.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \name{bayes4psy-datasets} 4 | \alias{bayes4psy-datasets} 5 | \alias{adaptation_level_small} 6 | \alias{adaptation_level} 7 | \alias{after_images_opponent_process} 8 | \alias{after_images_stimuli} 9 | \alias{after_images_trichromatic} 10 | \alias{after_images} 11 | \alias{flanker} 12 | \alias{stroop_extended} 13 | \alias{stroop_simple} 14 | \title{Datasets for bayes4psy examples 15 | Example datasets for use in \pkg{rstanarm} examples and vignettes. 16 | The datasets were extracted from the internal MBLab \url{http://www.mblab.si} repository. 17 | MBLab is a research lab at the Faculty of Arts, Department of Psychology, University of Ljubljana, Slovenia.} 18 | \format{ 19 | \describe{ 20 | \item{\code{adaptation_level_small}}{ 21 | Small dataset on subjects picking up weights and determining their weights from 1..10. 22 | 23 | Source: Internal MBLab repository. 24 | 25 | 50 obs. of 3 variables 26 | \itemize{ 27 | \item \code{sequence} sequence index. 28 | \item \code{weight} actual weight of the object. 29 | \item \code{response} subject's estimation of weight. 30 | } 31 | } 32 | \item{\code{adaptation_level}}{ 33 | Data on subjects picking up weights and determining their weights from 1..10. 34 | 35 | Source: Internal MBLab repository. 36 | 37 | 2900 obs. of 6 variables 38 | \itemize{ 39 | \item \code{subject} subject index. 40 | \item \code{group} group index. 41 | \item \code{part} first or second part of the experiment. 42 | \item \code{sequence} sequence index. 43 | \item \code{weight} actual weight of the object. 44 | \item \code{response} subject's estimation of weight. 45 | } 46 | } 47 | #' \item{\code{after_images_opponent_process}}{ 48 | Colors predicted by the opponent process theory. 49 | 50 | Source: Internal MBLab repository. 51 | 52 | 6 obs. of 7 variables 53 | \itemize{ 54 | \item \code{stimuli} name of the color stimuli. 55 | \item \code{r} value of the R component in the RGB model. 56 | \item \code{g} value of the G component in the RGB model. 57 | \item \code{b} value of the B component in the RGB model. 58 | \item \code{h} value of the H component in the HSV model. 59 | \item \code{s} value of the S component in the HSV model. 60 | \item \code{v} value of the V component in the HSV model. 61 | } 62 | } 63 | #' \item{\code{after_images_opponent_stimuli}}{ 64 | Stimuli used in the after images experiment. 65 | 66 | Source: Internal MBLab repository. 67 | 68 | 6 obs. of 7 variables 69 | \itemize{ 70 | \item \code{r_s} value of the R component in the RGB model. 71 | \item \code{g_s} value of the G component in the RGB model. 72 | \item \code{b_s} value of the B component in the RGB model. 73 | \item \code{stimuli} name of the color stimuli. 74 | \item \code{h_s} value of the H component in the HSV model. 75 | \item \code{s_s} value of the S component in the HSV model. 76 | \item \code{v_s} value of the V component in the HSV model. 77 | } 78 | } 79 | #' \item{\code{after_images_trichromatic}}{ 80 | Colors predicted by the trichromatic theory. 81 | 82 | Source: Internal MBLab repository. 83 | 84 | 6 obs. of 7 variables 85 | \itemize{ 86 | \item \code{stimuli} name of the color stimuli. 87 | \item \code{r} value of the R component in the RGB model. 88 | \item \code{g} value of the G component in the RGB model. 89 | \item \code{b} value of the B component in the RGB model. 90 | \item \code{h} value of the H component in the HSV model. 91 | \item \code{s} value of the S component in the HSV model. 92 | \item \code{v} value of the V component in the HSV model. 93 | } 94 | } 95 | #' \item{\code{after_images}}{ 96 | Data gathered by the after images experiment. 97 | 98 | Source: Internal MBLab repository. 99 | 100 | 1311 obs. of 12 variables 101 | \itemize{ 102 | \item \code{subject} subject index. 103 | \item \code{rt} reaction time. 104 | \item \code{r} value of the R component in the RGB model of subject's response. 105 | \item \code{g} value of the G component in the RGB model of subject's response. 106 | \item \code{b} value of the B component in the RGB model of subject's response. 107 | \item \code{stimuli} name of the color stimuli. 108 | \item \code{r_s} value of the R component in the RGB model of the shown stimulus 109 | \item \code{g_s} value of the G component in the RGB model of the shown stimulus 110 | \item \code{b_s} value of the B component in the RGB model of the shown stimulus 111 | \item \code{h_s} value of the H component in the HSV model of the shown stimulus 112 | \item \code{s_s} value of the S component in the HSV model of the shown stimulus 113 | \item \code{v_s} value of the V component in the HSV model of the shown stimulus 114 | } 115 | } 116 | #' \item{\code{flanker}}{ 117 | Data gathered by the flanker experiment. 118 | 119 | Source: Internal MBLab repository. 120 | 121 | 8256 obs. of 5 variables 122 | \itemize{ 123 | \item \code{subject} subject index. 124 | \item \code{group} group index. 125 | \item \code{congruencty} type of stimulus. 126 | \item \code{result} was subject's reponse correct or wrong? 127 | \item \code{rt} reaction time. 128 | } 129 | } 130 | #' \item{\code{stroop_extended}}{ 131 | All the data gathered by the Stroop experiment. 132 | 133 | Source: Internal MBLab repository. 134 | 135 | 41068 obs. of 5 variables 136 | \itemize{ 137 | \item \code{subject} subject ID. 138 | \item \code{cond} type of condition. 139 | \item \code{rt} reaction time. 140 | \item \code{acc} was subject's reponse correct or wrong? 141 | \item \code{age} age of subject. 142 | } 143 | } 144 | #' \item{\code{stroop_simple}}{ 145 | All the data gathered by the Stroop experiment. 146 | 147 | Source: Internal MBLab repository. 148 | 149 | 61 obs. of 5 variables 150 | \itemize{ 151 | \item \code{subject} subject ID. 152 | \item \code{reading_neutral} average response time for reading neutral stimuli. 153 | \item \code{naming_neutral} average response time for naming neutral stimuli. 154 | \item \code{reading_incongruent} average response time for reading incongruent stimuli. 155 | \item \code{naming_incongruent} average response time for naming incongruent stimuli. 156 | } 157 | } 158 | } 159 | } 160 | \description{ 161 | Datasets for bayes4psy examples 162 | Example datasets for use in \pkg{rstanarm} examples and vignettes. 163 | The datasets were extracted from the internal MBLab \url{http://www.mblab.si} repository. 164 | MBLab is a research lab at the Faculty of Arts, Department of Psychology, University of Ljubljana, Slovenia. 165 | } 166 | \examples{ 167 | 168 | # Example of Bayesian bootstraping on 'adaptation_level_small' dataset 169 | # linear function of seqence vs. response 170 | lm_statistic <- function(data) { 171 | lm(sequence ~ response, data)$coef 172 | } 173 | 174 | # load data 175 | data <- adaptation_level_small 176 | 177 | # bootstrap 178 | data_bootstrap <- b_bootstrap(data, lm_statistic, n1=1000, n2=1000) 179 | 180 | } 181 | -------------------------------------------------------------------------------- /man/bayes4psy-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bayes4psy-package.R 3 | \docType{package} 4 | \name{bayes4psy-package} 5 | \alias{bayes4psy-package} 6 | \alias{bayes4psy} 7 | \title{The 'bayes4psy' package.} 8 | \description{ 9 | A user-friendly implementation of Bayesian statistical methods commonly used in social sciences. All used models are pre-compiled, meaning that users only need to call appropriate functions using their data. 10 | } 11 | \references{ 12 | Stan Development Team (NA) - the Stan framework and RStan interface. 13 | John Kruschke - mcmc_hdi function 14 | Rasmus Bååth - Easy Bayesian Bootstrap in R 15 | } 16 | -------------------------------------------------------------------------------- /man/color_class-compare_distributions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{compare_distributions,color_class-method} 4 | \alias{compare_distributions,color_class-method} 5 | \alias{compare_distributions_color} 6 | \title{compare_distributions} 7 | \usage{ 8 | \S4method{compare_distributions}{color_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{color_class object.} 12 | 13 | \item{...}{fit2 - a second color_class object, rgb - color defined through rgb, hsv - color defined through rgb, rope - region of practical equivalence, pars - components of comparison, a subset of (r, g, b, h, s, v).} 14 | } 15 | \value{ 16 | Comparison results or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{compare_distributions} draws samples from distribution of the first group and compares them against samples drawn from the distribution of the second group or against a color defined with rgb or hsv components. You can also provide the rope parameter or execute the comparison only through chosen color components (r, g, b, h, s, v). 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?color_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/color_class-compare_means.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{compare_means,color_class-method} 4 | \alias{compare_means,color_class-method} 5 | \alias{compare_means_color} 6 | \title{compare_means} 7 | \usage{ 8 | \S4method{compare_means}{color_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{color_class object.} 12 | 13 | \item{...}{fit2 - a second color_class object, rgb - color defined through rgb, hsv - color defined through rgb, rope - region of practical equivalence, pars - components of comparison, a subset of (r, g, b, h, s, v).} 14 | } 15 | \value{ 16 | Comparison results or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{compare_means} prints difference in colors between two fits or a fit and a color. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?color_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/color_class-get_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{get_parameters,color_class-method} 4 | \alias{get_parameters,color_class-method} 5 | \alias{get_parameters_color_class} 6 | \title{get_parameters} 7 | \usage{ 8 | \S4method{get_parameters}{color_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{color_class object.} 12 | } 13 | \value{ 14 | A data frame with parameter values. 15 | } 16 | \description{ 17 | \code{get_parameters} returns a dataframe with values of fitted parameters. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?color_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/color_class-plot_distributions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{plot_distributions,color_class-method} 4 | \alias{plot_distributions,color_class-method} 5 | \alias{plot_distributions_color} 6 | \title{plot_distributions} 7 | \usage{ 8 | \S4method{plot_distributions}{color_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{color_class object.} 12 | 13 | \item{...}{fit2 - a second color_class object, rgb - color defined through rgb, hsv - color defined through rgb, pars - components of comparison, a subset of (r, g, b, h, s, v).} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_distributions} a visualization of the fitted distributions or constant colors. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?color_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/color_class-plot_distributions_difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{plot_distributions_difference,color_class-method} 4 | \alias{plot_distributions_difference,color_class-method} 5 | \alias{plot_distributions_difference_color} 6 | \title{plot_distributions_difference} 7 | \usage{ 8 | \S4method{plot_distributions_difference}{color_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{color_class object.} 12 | 13 | \item{...}{fit2 - a second color_class object, rgb - color defined through rgb, hsv - color defined through rgb, rope - region of practical equivalence, bins - number of bins in the histogram, pars - components of comparison, a subset of (r, g, b, h, s, v).} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_distributions_difference} a visualization of the difference between the distribution of the first group and the second group. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?color_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/color_class-plot_distributions_hsv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{plot_distributions_hsv} 4 | \alias{plot_distributions_hsv} 5 | \alias{plot_distributions_hsv,color_class-method} 6 | \alias{plot_distributions_hsv_color} 7 | \title{plot_distributions_hsv} 8 | \usage{ 9 | plot_distributions_hsv(object, ...) 10 | 11 | \S4method{plot_distributions_hsv}{color_class}(object, ...) 12 | } 13 | \arguments{ 14 | \item{object}{color_class object.} 15 | 16 | \item{...}{fit2 - a second color_class object, points - points to plot defined through rgb or hsv, lines - lines to plot defined through rgb or hsv, hsv - are points and lines defined in hsv format (default = FALSE).} 17 | } 18 | \value{ 19 | A ggplot visualization. 20 | } 21 | \description{ 22 | \code{plot_distributions_hsv} a visualization of distributions of one or two fits thorough a circular visualization of hsv color components. You can also compare fit means with colors defined through rgb or hsv components (as points or as lines on the visualization). 23 | } 24 | \examples{ 25 | # to use the function you first have to prepare the data and fit the model 26 | # see class documentation for an example of the whole process 27 | # along with an example of how to use this function 28 | ?color_class 29 | 30 | } 31 | -------------------------------------------------------------------------------- /man/color_class-plot_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{plot_fit,color_class-method} 4 | \alias{plot_fit,color_class-method} 5 | \alias{plot_fit_color} 6 | \title{plot_fit} 7 | \usage{ 8 | \S4method{plot_fit}{color_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{color_class object.} 12 | 13 | \item{...}{pars - components of comparison, a subset of (r, g, b, h, s, v).} 14 | } 15 | \value{ 16 | A ggplot visualization. 17 | } 18 | \description{ 19 | \code{plot_fit} plots fitted model against the data. Use this function to explore the quality of your fit. You can compare fit with underlying data only through chosen color components (r, g, b, h, s, v). 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?color_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/color_class-plot_fit_hsv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{plot_fit_hsv} 4 | \alias{plot_fit_hsv} 5 | \alias{plot_fit_hsv,color_class-method} 6 | \alias{plot_fit_hsv_color} 7 | \title{plot_fit_hsv} 8 | \usage{ 9 | plot_fit_hsv(object) 10 | 11 | \S4method{plot_fit_hsv}{color_class}(object) 12 | } 13 | \arguments{ 14 | \item{object}{color_class object.} 15 | } 16 | \value{ 17 | A ggplot visualization. 18 | } 19 | \description{ 20 | \code{plot_fit_hsv} plots fitted model against the data. Use this function to explore the quality of your fit thorough a circular visualization of hsv color components. 21 | } 22 | \examples{ 23 | # to use the function you first have to prepare the data and fit the model 24 | # see class documentation for an example of the whole process 25 | # along with an example of how to use this function 26 | ?color_class 27 | 28 | } 29 | -------------------------------------------------------------------------------- /man/color_class-plot_hsv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{plot_hsv} 4 | \alias{plot_hsv} 5 | \alias{plot_hsv,color_class-method} 6 | \alias{plot_hsv_color} 7 | \title{plot_hsv} 8 | \usage{ 9 | plot_hsv(object) 10 | 11 | \S4method{plot_hsv}{color_class}(object) 12 | } 13 | \arguments{ 14 | \item{object}{color_class object.} 15 | } 16 | \value{ 17 | A ggplot visualization. 18 | } 19 | \description{ 20 | \code{plot_hsv} plots fitted model against the data. Use this function to explore the quality of your fit thorough a circular visualization of hsv color components. 21 | } 22 | \examples{ 23 | # to use the function you first have to prepare the data and fit the model 24 | # see class documentation for an example of the whole process 25 | # along with an example of how to use this function 26 | ?color_class 27 | 28 | } 29 | -------------------------------------------------------------------------------- /man/color_class-plot_means.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{plot_means,color_class-method} 4 | \alias{plot_means,color_class-method} 5 | \alias{plot_means_color} 6 | \title{plot_means} 7 | \usage{ 8 | \S4method{plot_means}{color_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{color_class object.} 12 | 13 | \item{...}{fit2 - a second color_class object, rgb - color defined through rgb, hsv - color defined through rgb, pars - components of comparison, a subset of (r, g, b, h, s, v).} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_means} plots density of means, the first and the second group means or a constant values in case second group is defined as rgb or hsv color. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?color_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/color_class-plot_means_difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{plot_means_difference,color_class-method} 4 | \alias{plot_means_difference,color_class-method} 5 | \alias{plot_means_difference_color} 6 | \title{plot_means_difference} 7 | \usage{ 8 | \S4method{plot_means_difference}{color_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{color_class object.} 12 | 13 | \item{...}{fit2 - a second color_class object, rgb - color defined through rgb, hsv - color defined through rgb, rope - region of practical equivalence, bins - number of bins in the histogram, pars - components of comparison, a subset of (r, g, b, h, s, v).} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_means_difference} a visualization of the difference between two fits 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?color_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/color_class-plot_means_hsv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{plot_means_hsv} 4 | \alias{plot_means_hsv} 5 | \alias{plot_means_hsv,color_class-method} 6 | \alias{plot_means_hsv_color} 7 | \title{plot_means_hsv} 8 | \usage{ 9 | plot_means_hsv(object, ...) 10 | 11 | \S4method{plot_means_hsv}{color_class}(object, ...) 12 | } 13 | \arguments{ 14 | \item{object}{color_class object.} 15 | 16 | \item{...}{fit2 - a second color_class object, points - points to plot defined through rgb or hsv, lines - lines to plot defined through rgb or hsv, hsv - are points and lines defined in hsv format (default = FALSE).} 17 | } 18 | \value{ 19 | A ggplot visualization. 20 | } 21 | \description{ 22 | \code{plot_means_hsv} a visualization of the difference between means of two fits through a circular visualization of hsv color components. You can also compare fit means with colors defined through rgb or hsv components (as points or as lines on the visualization). 23 | } 24 | \examples{ 25 | # to use the function you first have to prepare the data and fit the model 26 | # see class documentation for an example of the whole process 27 | # along with an example of how to use this function 28 | ?color_class 29 | 30 | } 31 | -------------------------------------------------------------------------------- /man/color_class-plot_trace.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{plot_trace,color_class-method} 4 | \alias{plot_trace,color_class-method} 5 | \alias{plot_trace_color} 6 | \title{plot_trace} 7 | \usage{ 8 | \S4method{plot_trace}{color_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{color_class object.} 12 | } 13 | \value{ 14 | A ggplot visualization. 15 | } 16 | \description{ 17 | \code{plot_trace} traceplot for main fitted model parameters. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?color_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/linear_class-class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \docType{class} 4 | \name{linear_class-class} 5 | \alias{linear_class-class} 6 | \alias{linear_class} 7 | \title{linear_class} 8 | \description{ 9 | An S4 class for storing results of normal linear model. 10 | 11 | \strong{Functions} 12 | 13 | summary(`linear_class`): prints a summary of the fit. 14 | 15 | print(`linear_class`): prints a more detailed summary of the fit 16 | 17 | show(`linear_class`): prints a more detailed summary of the fit. 18 | 19 | plot(`linear_class`): plots fitted model against the data. Use this function to explore the quality of your fit. Fit will be plotted on the subject level. 20 | 21 | plot(`linear_class`, subjects='boolean'): plots fitted model against the data. Use this function to explore the quality of your fit. You can plot on the subject level (subjects=TRUE) or on the subjects level (subjects=FALSE). 22 | 23 | plot_fit(`linear_class`): plots fitted model against the data. Use this function to explore the quality of your fit. Fit will be plotted on the subject level. 24 | 25 | plot_fit(`linear_class`, subjects='boolean'): plots fitted model against the data. Use this function to explore the quality of your fit. You can plot on the subject level (subjects=TRUE) or on the subjects level (subjects=FALSE). 26 | 27 | plot_trace(`linear_class`): traceplot for main fitted model parameters. 28 | 29 | get_parameters(`linear_class`): returns a dataframe with values of fitted parameters. 30 | 31 | get_subject_parameters(`linear_class`): returns a dataframe with values of fitted parameters for each subject in the hierarchical model. 32 | 33 | compare_means(`linear_class`, fit2=`linear_class`): prints difference in slope and intercept between two groups. You can also provide the rope parameter. 34 | 35 | plot_means_difference(`linear_class`, fit2=`linear_class`): a visualization of the difference between two groups. You can plot only slope or intercept by using the par parameter. You can also provide the rope and bins (number of bins in the histogram) parameters. 36 | 37 | plot_means(`linear_class`): plots density of means. You can plot only slope or intercept by using the par parameter. 38 | 39 | plot_means(`linear_class`, fit2=`linear_class`): plots density for the first and the second group means. You can plot only slope or intercept by using the par parameter. 40 | 41 | compare_distributions(`linear_class`, fit2=`linear_class`): draws samples from distribution of the first group and compares them against samples drawn from the distribution of the second group. 42 | 43 | plot_distributions(`linear_class`): a visualization of the fitted distribution. 44 | 45 | plot_distributions(`linear_class`, fit2=`linear_class`): a visualization of two fitted distribution. 46 | 47 | plot_distributions_difference(`linear_class`, fit2=`linear_class`): a visualization of the difference between the distribution of the first group and the second group. You can plot only slope or intercept by using the par parameter. You can also provide the rope and bins (number of bins in the histogram) parameters. 48 | } 49 | \section{Slots}{ 50 | 51 | \describe{ 52 | \item{\code{extract}}{Extract from Stan fit.} 53 | 54 | \item{\code{fit}}{Stan fit.} 55 | 56 | \item{\code{data}}{Raw data for the tested group.} 57 | }} 58 | 59 | \examples{ 60 | \donttest{ 61 | # priors 62 | mu_prior <- b_prior(family="normal", pars=c(0, 100)) 63 | sigma_prior <- b_prior(family="uniform", pars=c(0, 500)) 64 | 65 | # attach priors to relevant parameters 66 | priors <- list(c("mu_a", mu_prior), 67 | c("sigma_a", sigma_prior), 68 | c("mu_b", mu_prior), 69 | c("sigma_b", sigma_prior), 70 | c("mu_s", sigma_prior), 71 | c("sigma_s", sigma_prior)) 72 | 73 | 74 | # generate data and fit 75 | x <- vector() 76 | y <- vector() 77 | s <- vector() 78 | for (i in 1:5) { 79 | x <- c(x, rep(1:10, 2)) 80 | y <- c(y, rnorm(20, mean=1:10, sd=2)) 81 | s <- c(s, rep(i, 20)) 82 | } 83 | 84 | fit1 <- b_linear(x=x, y=y, s=s, priors=priors, chains=1) 85 | 86 | fit2 <- b_linear(x=x, y=-2*y, s=s, priors=priors, chains=1) 87 | 88 | # a short summary of fitted parameters 89 | summary(fit1) 90 | 91 | # a more detailed summary of fitted parameters 92 | print(fit1) 93 | show(fit1) 94 | 95 | # plot the fitted distribution against the data 96 | plot(fit1) 97 | plot_fit(fit1) 98 | 99 | # plot the fitted distribution against the data, 100 | # plot on the top (group) level 101 | plot(fit1, subjects=FALSE) 102 | plot_fit(fit1, subjects=FALSE) 103 | 104 | # traceplot of the fitted parameters 105 | plot_trace(fit1) 106 | # extract parameter values from the fit 107 | parameters <- get_parameters(fit1) 108 | 109 | # extract parameter values on the bottom (subject) level from the fit 110 | subject_parameters <- get_subject_parameters(fit1) 111 | 112 | # compare means between two fits 113 | compare_means(fit1, fit2=fit2) 114 | 115 | # compare means between two fits, use a rope interval for intercept and slope 116 | compare_means(fit1, fit2=fit2, rope_intercept=0.5, rope_slope=0.2) 117 | 118 | # visualize difference in means between two fits 119 | plot_means_difference(fit1, fit2=fit2) 120 | 121 | # visualize difference in means between two fits, 122 | # use a rope interval for intercept and slope, 123 | # set the number of bins in the histogram 124 | plot_means_difference(fit1, fit2=fit2, rope_intercept=0.5, rope_slope=0.2, bins=20) 125 | 126 | # visualize difference in means between two fits, compare only slope 127 | plot_means_difference(fit1, fit2=fit2, par="slope") 128 | 129 | # visualize means of a single fit 130 | plot_means(fit1) 131 | 132 | # visualize means of two fits 133 | plot_means(fit1, fit2=fit2) 134 | 135 | # visualize means of two fits, plot slope only 136 | plot_means(fit1, fit2=fit2, par="slope") 137 | 138 | # draw samples from distributions underlying two fits and compare them, 139 | # use a rope interval for intercept and slope 140 | compare_distributions(fit1, fit2=fit2, rope_intercept=0.5, rope_slope=0.2) 141 | 142 | # visualize the distribution underlying a fit 143 | plot_distributions(fit1) 144 | 145 | # visualize distributions underlying two fits 146 | plot_distributions(fit1, fit2=fit2) 147 | 148 | # visualize distributions underlying two fits, plot slope only 149 | plot_distributions(fit1, fit2=fit2, par="slope") 150 | 151 | # visualize difference between distributions underlying two fits 152 | plot_distributions_difference(fit1, fit2=fit2) 153 | 154 | # visualize difference between distributions underlying two fits, 155 | # use a rope interval for intercept and slope, 156 | # set the number of bins in the histogram 157 | plot_distributions_difference(fit1, fit2=fit2, rope_intercept=0.5, rope_slope=0.2, bins=20) 158 | 159 | # visualize difference between distributions underlying two fits, plot slope only 160 | plot_distributions_difference(fit1, fit2=fit2, par="slope") 161 | } 162 | 163 | } 164 | -------------------------------------------------------------------------------- /man/linear_class-compare_distributions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{compare_distributions,linear_class-method} 4 | \alias{compare_distributions,linear_class-method} 5 | \alias{compare_distributions_linear} 6 | \title{compare_distributions} 7 | \usage{ 8 | \S4method{compare_distributions}{linear_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{linear_class object.} 12 | 13 | \item{...}{fit2 - a second linear_class object, rope_intercept and rope_slope - regions of practical equivalence.} 14 | } 15 | \value{ 16 | Comparison results or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{compare_distributions} draws samples from distribution of the first group and compares them against samples drawn from the distribution of the second group. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?linear_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/linear_class-compare_means.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{compare_means,linear_class-method} 4 | \alias{compare_means,linear_class-method} 5 | \alias{compare_meanslinear} 6 | \title{compare_means} 7 | \usage{ 8 | \S4method{compare_means}{linear_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{linear_class object.} 12 | 13 | \item{...}{fit2 - a second linear_class object, rope_intercept and rope_slope - regions of practical equivalence.} 14 | } 15 | \value{ 16 | Comparison results or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{compare_means} prints difference in intercept and slope between two groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?linear_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/linear_class-get_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{get_parameters,linear_class-method} 4 | \alias{get_parameters,linear_class-method} 5 | \alias{get_parameters_linear_class} 6 | \title{get_parameters} 7 | \usage{ 8 | \S4method{get_parameters}{linear_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{linear_class object.} 12 | } 13 | \value{ 14 | A data frame with parameter values. 15 | } 16 | \description{ 17 | \code{get_parameters} returns a dataframe with values of fitted parameters. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?linear_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/linear_class-get_subject_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{get_subject_parameters,linear_class-method} 4 | \alias{get_subject_parameters,linear_class-method} 5 | \alias{get_subject_parameters_linear_class} 6 | \title{get_subject_parameters} 7 | \usage{ 8 | \S4method{get_subject_parameters}{linear_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{linear_class object.} 12 | } 13 | \value{ 14 | A data frame with parameter values. 15 | } 16 | \description{ 17 | \code{get_subject_parameters} returns a dataframe with values of fitted parameters for each subject in the hierarchical model. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?linear_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/linear_class-plot_distributions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{plot_distributions,linear_class-method} 4 | \alias{plot_distributions,linear_class-method} 5 | \alias{plot_distributions_linear} 6 | \title{plot_distributions} 7 | \usage{ 8 | \S4method{plot_distributions}{linear_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{linear_class object.} 12 | 13 | \item{...}{fit2 - a second linear_class object.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_distributions} a visualization of the fitted distribution, for one or two fits. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?linear_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/linear_class-plot_distributions_difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{plot_distributions_difference,linear_class-method} 4 | \alias{plot_distributions_difference,linear_class-method} 5 | \alias{plot_distributions_difference_linear} 6 | \title{plot_distributions_difference} 7 | \usage{ 8 | \S4method{plot_distributions_difference}{linear_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{linear_class object.} 12 | 13 | \item{...}{fit2 - a second linear_class object, par - specific parameter of comparison (slope or intercept), rope_intercept and rope_slope - regions of practical equivalence, bins - number of bins in the histogram.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_distributions_difference} visualizes the difference between two groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?linear_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/linear_class-plot_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{plot_fit,linear_class-method} 4 | \alias{plot_fit,linear_class-method} 5 | \alias{plot_fit_linear} 6 | \title{plot_fit} 7 | \usage{ 8 | \S4method{plot_fit}{linear_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{linear_class object.} 12 | 13 | \item{...}{subjects - plot fits on a subject level (default = TRUE).} 14 | } 15 | \value{ 16 | A ggplot visualization. 17 | } 18 | \description{ 19 | \code{plot_fit} plots fitted model against the data. Use this function to explore the quality of your fit. You can plot on the subject level (subjects=TRUE) or on the group level (subjects=FALSE). 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?linear_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/linear_class-plot_means.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{plot_means,linear_class-method} 4 | \alias{plot_means,linear_class-method} 5 | \alias{plot_means_linear} 6 | \title{plot_means} 7 | \usage{ 8 | \S4method{plot_means}{linear_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{linear_class object.} 12 | 13 | \item{...}{fit2 - a second linear_class object, par - plot a specific parameter (slope or intercept).} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_means} plots means or the first and the second group means. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?linear_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/linear_class-plot_means_difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{plot_means_difference,linear_class-method} 4 | \alias{plot_means_difference,linear_class-method} 5 | \alias{plot_means_difference_linear} 6 | \title{plot_means_difference} 7 | \usage{ 8 | \S4method{plot_means_difference}{linear_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{linear_class object.} 12 | 13 | \item{...}{fit2 - a second linear_class object, par - specific parameter of comparison (slope or intercept), rope_intercept and rope_slope - regions of practical equivalence, bins - number of bins in the histogram.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_means_difference} plots difference between two groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?linear_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/linear_class-plot_trace.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{plot_trace,linear_class-method} 4 | \alias{plot_trace,linear_class-method} 5 | \alias{plot_trace_linear} 6 | \title{plot_trace} 7 | \usage{ 8 | \S4method{plot_trace}{linear_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{linear_class object.} 12 | } 13 | \value{ 14 | A ggplot visualization. 15 | } 16 | \description{ 17 | \code{plot_trace} traceplot for main fitted model parameters. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?linear_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/mcmc_hdi.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shared_functions.R 3 | \name{mcmc_hdi} 4 | \alias{mcmc_hdi} 5 | \title{mcmc_hdi} 6 | \usage{ 7 | mcmc_hdi(samples, cred_mass = 0.95) 8 | } 9 | \arguments{ 10 | \item{samples}{vector of values.} 11 | 12 | \item{cred_mass}{credibility mass that the interval should include (default = 0.95).} 13 | } 14 | \value{ 15 | Boundaries of the HDI. 16 | } 17 | \description{ 18 | A function for calculating the HDI (highest density interval) of a vector of values. 19 | } 20 | \author{ 21 | John Kruschke 22 | } 23 | -------------------------------------------------------------------------------- /man/plot-color_class-missing-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{plot,color_class,missing-method} 4 | \alias{plot,color_class,missing-method} 5 | \title{plot} 6 | \usage{ 7 | \S4method{plot}{color_class,missing}(x, y, ...) 8 | } 9 | \arguments{ 10 | \item{x}{color_class object.} 11 | 12 | \item{y}{empty dummy variable, ignore this.} 13 | 14 | \item{...}{pars - components of comparison, a subset of (r, g, b, h, s, v).} 15 | } 16 | \description{ 17 | \code{plot} plots fitted model against the data. Use this function to explore the quality of your fit. You can compare fit with underlying data only through chosen color components (r, g, b, h, s, v). 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?color_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/plot-linear_class-missing-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{plot,linear_class,missing-method} 4 | \alias{plot,linear_class,missing-method} 5 | \title{plot} 6 | \usage{ 7 | \S4method{plot}{linear_class,missing}(x, y, ...) 8 | } 9 | \arguments{ 10 | \item{x}{linear_class object.} 11 | 12 | \item{y}{empty dummy variable, ignore this.} 13 | 14 | \item{...}{subjects - plot fits on a subject level (default = TRUE).} 15 | } 16 | \description{ 17 | \code{plot} plots fitted model against the data. Use this function to explore the quality of your fit. You can plot on the subject level (subjects=TRUE) or on the group level (subjects=FALSE). 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?linear_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/plot-reaction_time_class-missing-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{plot,reaction_time_class,missing-method} 4 | \alias{plot,reaction_time_class,missing-method} 5 | \title{plot} 6 | \usage{ 7 | \S4method{plot}{reaction_time_class,missing}(x, y, ...) 8 | } 9 | \arguments{ 10 | \item{x}{reaction_time_class object.} 11 | 12 | \item{y}{empty dummy variable, ignore this.} 13 | 14 | \item{...}{subjects - plot fits on a subject level (default = TRUE).} 15 | } 16 | \description{ 17 | \code{plot} plots fitted model against the data. Use this function to explore the quality of your fit. You can plot on the subjects level (subjects=TRUE) or on the group level (subjects=FALSE). 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?reaction_time_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/plot-success_rate_class-missing-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{plot,success_rate_class,missing-method} 4 | \alias{plot,success_rate_class,missing-method} 5 | \title{plot} 6 | \usage{ 7 | \S4method{plot}{success_rate_class,missing}(x, y, ...) 8 | } 9 | \arguments{ 10 | \item{x}{success_rate_class object.} 11 | 12 | \item{y}{empty dummy variable, ignore this.} 13 | 14 | \item{...}{subjects - plot fits on a subject level (default = TRUE).} 15 | } 16 | \description{ 17 | \code{plot} plots fitted model against the data. Use this function to explore the quality of your fit. You can plot on the subjects level (subjects=TRUE) or on the group level (subjects=FALSE). 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?success_rate_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/plot-ttest_class-missing-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ttest_class.R 3 | \name{plot,ttest_class,missing-method} 4 | \alias{plot,ttest_class,missing-method} 5 | \title{plot} 6 | \usage{ 7 | \S4method{plot}{ttest_class,missing}(x) 8 | } 9 | \arguments{ 10 | \item{x}{ttest_class object.} 11 | } 12 | \description{ 13 | \code{plot} plots fitted model against the data. Use this function to explore the quality of your fit. 14 | } 15 | \examples{ 16 | # to use the function you first have to prepare the data and fit the model 17 | # see class documentation for an example of the whole process 18 | # along with an example of how to use this function 19 | ?ttest_class 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/reaction_time_class-compare_distributions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{compare_distributions,reaction_time_class-method} 4 | \alias{compare_distributions,reaction_time_class-method} 5 | \alias{compare_distributions_reaction_time} 6 | \title{compare_distributions} 7 | \usage{ 8 | \S4method{compare_distributions}{reaction_time_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{reaction_time_class object.} 12 | 13 | \item{...}{fit2 - a second reaction_time_class object, fits - a list of reaction_time_class objects, rope - region of practical equivalence.} 14 | } 15 | \value{ 16 | Comparison results or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{compare_distributions} draws samples from distribution of the first group and compares them against samples drawn from the distribution of the second group or from samples drawn from distributions of multiple groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?reaction_time_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/reaction_time_class-compare_means.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{compare_means,reaction_time_class-method} 4 | \alias{compare_means,reaction_time_class-method} 5 | \alias{compare_means_reaction_time} 6 | \title{compare_means} 7 | \usage{ 8 | \S4method{compare_means}{reaction_time_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{reaction_time_class object.} 12 | 13 | \item{...}{fit2 - a second reaction_time_class object, fits - a list of reaction_time_class objects, rope - region of practical equivalence, par - specific parameter of comparison (mu or lambda).} 14 | } 15 | \value{ 16 | Comparison results or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{compare_means} prints difference in reaction times between two groups or multiple groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?reaction_time_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/reaction_time_class-get_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{get_parameters,reaction_time_class-method} 4 | \alias{get_parameters,reaction_time_class-method} 5 | \alias{get_parameters_reaction_time} 6 | \title{get_parameters} 7 | \usage{ 8 | \S4method{get_parameters}{reaction_time_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{reaction_time_class object.} 12 | } 13 | \value{ 14 | A data frame with parameter values. 15 | } 16 | \description{ 17 | \code{get_parameters} returns a dataframe with values of fitted parameters. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?reaction_time_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/reaction_time_class-get_subject_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{get_subject_parameters,reaction_time_class-method} 4 | \alias{get_subject_parameters,reaction_time_class-method} 5 | \alias{get_subject_parameters_reaction_time} 6 | \title{get_subject_parameters} 7 | \usage{ 8 | \S4method{get_subject_parameters}{reaction_time_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{reaction_time_class object.} 12 | } 13 | \value{ 14 | A data frame with parameter values. 15 | } 16 | \description{ 17 | \code{get_subject_parameters} returns a dataframe with values of fitted parameters for each subject in the hierarchical model. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?reaction_time_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/reaction_time_class-plot_distributions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{plot_distributions,reaction_time_class-method} 4 | \alias{plot_distributions,reaction_time_class-method} 5 | \alias{plot_distributions_reaction_time} 6 | \title{plot_distributions} 7 | \usage{ 8 | \S4method{plot_distributions}{reaction_time_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{reaction_time_class object.} 12 | 13 | \item{...}{fit2 - a second reaction_time_class object, fits - a list of reaction_time_class objects.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_distributions} a visualization of the fitted distribution, for one, two or multiple fits. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?reaction_time_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/reaction_time_class-plot_distributions_difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{plot_distributions_difference,reaction_time_class-method} 4 | \alias{plot_distributions_difference,reaction_time_class-method} 5 | \alias{plot_distributions_difference_reaction_time} 6 | \title{plot_distributions_difference} 7 | \usage{ 8 | \S4method{plot_distributions_difference}{reaction_time_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{reaction_time_class object.} 12 | 13 | \item{...}{fit2 - a second reaction_time_class object, fits - a list of reaction_time_class objects, rope - region of practical equivalence, bins - number of bins in the histogram.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_distributions_difference} a visualization of the difference between the distribution of the first group and the second group or between multiple groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?reaction_time_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/reaction_time_class-plot_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{plot_fit,reaction_time_class-method} 4 | \alias{plot_fit,reaction_time_class-method} 5 | \alias{plot_fit_reaction_time} 6 | \title{plot_fit} 7 | \usage{ 8 | \S4method{plot_fit}{reaction_time_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{reaction_time_class object.} 12 | 13 | \item{...}{subjects - plot fits on a subject level (default = TRUE).} 14 | } 15 | \value{ 16 | A ggplot visualization. 17 | } 18 | \description{ 19 | \code{plot_fit} plots fitted model against the data. Use this function to explore the quality of your fit. You can plot on the subjects level (subjects=TRUE) or on the group level (subjects=FALSE). 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?reaction_time_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/reaction_time_class-plot_means.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{plot_means,reaction_time_class-method} 4 | \alias{plot_means,reaction_time_class-method} 5 | \alias{plot_means_reaction_time} 6 | \title{plot_means} 7 | \usage{ 8 | \S4method{plot_means}{reaction_time_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{reaction_time_class object.} 12 | 13 | \item{...}{fit2 - a second reaction_time_class object, fits - a list of reaction_time_class objects, par - plot a specific parameter (mu or lambda).} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_means} plots density of means for one, two or multiple groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?reaction_time_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/reaction_time_class-plot_means_difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{plot_means_difference,reaction_time_class-method} 4 | \alias{plot_means_difference,reaction_time_class-method} 5 | \alias{plot_means_difference_reaction_time} 6 | \title{plot_means_difference} 7 | \usage{ 8 | \S4method{plot_means_difference}{reaction_time_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{reaction_time_class object.} 12 | 13 | \item{...}{fit2 - a second reaction_time_class object, fits - a list of reaction_time_class objects, rope - region of practical equivalence, bins - number of bins in the histogram, par - specific parameter of comparison (mu or lambda).} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_means_difference} a visualization of the difference between two groups or multiple groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?reaction_time_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/reaction_time_class-plot_trace.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{plot_trace,reaction_time_class-method} 4 | \alias{plot_trace,reaction_time_class-method} 5 | \alias{plot_trace_reaction_time} 6 | \title{plot_trace} 7 | \usage{ 8 | \S4method{plot_trace}{reaction_time_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{reaction_time_class object.} 12 | } 13 | \value{ 14 | A ggplot visualization. 15 | } 16 | \description{ 17 | \code{plot_trace} traceplot for main fitted model parameters. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?reaction_time_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/show-color_class-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{show,color_class-method} 4 | \alias{show,color_class-method} 5 | \title{show} 6 | \usage{ 7 | \S4method{show}{color_class}(object) 8 | } 9 | \arguments{ 10 | \item{object}{color_class object.} 11 | } 12 | \description{ 13 | \code{show} prints a more detailed summary of the Bayesian color fit. 14 | } 15 | \examples{ 16 | # to use the function you first have to prepare the data and fit the model 17 | # see class documentation for an example of the whole process 18 | # along with an example of how to use this function 19 | ?color_class 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/show-linear_class-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{show,linear_class-method} 4 | \alias{show,linear_class-method} 5 | \title{show} 6 | \usage{ 7 | \S4method{show}{linear_class}(object) 8 | } 9 | \arguments{ 10 | \item{object}{linear_class object.} 11 | } 12 | \description{ 13 | \code{show} prints a more detailed summary of the Bayesian linear model fit. 14 | } 15 | \examples{ 16 | # to use the function you first have to prepare the data and fit the model 17 | # see class documentation for an example of the whole process 18 | # along with an example of how to use this function 19 | ?linear_class 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/show-reaction_time_class-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{show,reaction_time_class-method} 4 | \alias{show,reaction_time_class-method} 5 | \title{show} 6 | \usage{ 7 | \S4method{show}{reaction_time_class}(object) 8 | } 9 | \arguments{ 10 | \item{object}{reaction_time_class object.} 11 | } 12 | \description{ 13 | \code{show} prints a more detailed summary of the Bayesian reaction time fit. 14 | } 15 | \examples{ 16 | # to use the function you first have to prepare the data and fit the model 17 | # see class documentation for an example of the whole process 18 | # along with an example of how to use this function 19 | ?reaction_time_class 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/show-success_rate_class-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{show,success_rate_class-method} 4 | \alias{show,success_rate_class-method} 5 | \title{show} 6 | \usage{ 7 | \S4method{show}{success_rate_class}(object) 8 | } 9 | \arguments{ 10 | \item{object}{success_rate_class object.} 11 | } 12 | \description{ 13 | \code{show} prints a more detailed summary of the Bayesian success rate fit. 14 | } 15 | \examples{ 16 | # to use the function you first have to prepare the data and fit the model 17 | # see class documentation for an example of the whole process 18 | # along with an example of how to use this function 19 | ?success_rate_class 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/show-ttest_class-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ttest_class.R 3 | \name{show,ttest_class-method} 4 | \alias{show,ttest_class-method} 5 | \title{show} 6 | \usage{ 7 | \S4method{show}{ttest_class}(object) 8 | } 9 | \arguments{ 10 | \item{object}{ttest_class object.} 11 | } 12 | \description{ 13 | \code{show} prints a more detailed summary of the Bayesian ttest fit. 14 | } 15 | \examples{ 16 | # to use the function you first have to prepare the data and fit the model 17 | # see class documentation for an example of the whole process 18 | # along with an example of how to use this function 19 | ?ttest_class 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/success_rate_class-compare_distributions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{compare_distributions,success_rate_class-method} 4 | \alias{compare_distributions,success_rate_class-method} 5 | \alias{compare_distributions_success_rate} 6 | \title{compare_distributions} 7 | \usage{ 8 | \S4method{compare_distributions}{success_rate_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{success_rate_class object.} 12 | 13 | \item{...}{fit2 - a second success_rate_class object, fits - a list of success_rate_class objects, rope - region of practical equivalence.} 14 | } 15 | \value{ 16 | Comparison results or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{compare_distributions} draws samples from distribution of the first group and compares them against samples drawn from the distribution of the second group or from samples drawn from distributions of multiple groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?success_rate_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/success_rate_class-compare_means.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{compare_means,success_rate_class-method} 4 | \alias{compare_means,success_rate_class-method} 5 | \alias{compare_means_success_rate} 6 | \title{compare_means} 7 | \usage{ 8 | \S4method{compare_means}{success_rate_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{success_rate_class object.} 12 | 13 | \item{...}{fit2 - a second success_rate_class object, fits - a list of success_rate_class objects, rope - region of practical equivalence.} 14 | } 15 | \value{ 16 | Comparison results or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{compare_means} prints difference in success rate between two groups or multiple groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?success_rate_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/success_rate_class-get_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{get_parameters,success_rate_class-method} 4 | \alias{get_parameters,success_rate_class-method} 5 | \alias{get_parameters_success_rate_class} 6 | \title{get_parameters} 7 | \usage{ 8 | \S4method{get_parameters}{success_rate_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{success_rate_class object.} 12 | } 13 | \value{ 14 | A data frame with parameter values. 15 | } 16 | \description{ 17 | \code{get_parameters} returns a dataframe with values of fitted parameters. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?success_rate_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/success_rate_class-get_subject_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{get_subject_parameters,success_rate_class-method} 4 | \alias{get_subject_parameters,success_rate_class-method} 5 | \alias{get_subject_parameters_success_rate_class} 6 | \title{get_subject_parameters} 7 | \usage{ 8 | \S4method{get_subject_parameters}{success_rate_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{success_rate_class object.} 12 | } 13 | \value{ 14 | A data frame with parameter values. 15 | } 16 | \description{ 17 | \code{get_subject_parameters} returns a dataframe with values of fitted parameters for each subject in the hierarchical model. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?success_rate_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/success_rate_class-plot_distributions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{plot_distributions,success_rate_class-method} 4 | \alias{plot_distributions,success_rate_class-method} 5 | \alias{plot_distributions_success_rate} 6 | \title{plot_distributions} 7 | \usage{ 8 | \S4method{plot_distributions}{success_rate_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{success_rate_class object.} 12 | 13 | \item{...}{fit2 - a second success_rate_class object, fits - a list of success_rate_class objects.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_distributions} a visualization of the fitted distribution, for one, two or multiple fits. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?success_rate_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/success_rate_class-plot_distributions_difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{plot_distributions_difference,success_rate_class-method} 4 | \alias{plot_distributions_difference,success_rate_class-method} 5 | \alias{plot_distributions_difference_success_rate} 6 | \title{plot_distributions_difference} 7 | \usage{ 8 | \S4method{plot_distributions_difference}{success_rate_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{success_rate_class object.} 12 | 13 | \item{...}{fit2 - a second success_rate_class object, fits - a list of success_rate_class objects, rope - region of practical equivalence, bins - number of bins in the histogram.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_distributions_difference} a visualization of the difference between the distribution of the first group and the second group or between multiple groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?success_rate_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/success_rate_class-plot_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{plot_fit,success_rate_class-method} 4 | \alias{plot_fit,success_rate_class-method} 5 | \alias{plot_fit_success_rate} 6 | \title{plot_fit} 7 | \usage{ 8 | \S4method{plot_fit}{success_rate_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{success_rate_class object.} 12 | 13 | \item{...}{subjects - plot fits on a subject level (default = TRUE).} 14 | } 15 | \value{ 16 | A ggplot visualization. 17 | } 18 | \description{ 19 | \code{plot_fit} plots fitted model against the data. Use this function to explore the quality of your fit. You can plot on the subjects level (subjects=TRUE) or on the group level (subjects=FALSE). 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?success_rate_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/success_rate_class-plot_means.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{plot_means,success_rate_class-method} 4 | \alias{plot_means,success_rate_class-method} 5 | \alias{plot_means_success_rate} 6 | \title{plot_means} 7 | \usage{ 8 | \S4method{plot_means}{success_rate_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{success_rate_class object.} 12 | 13 | \item{...}{fit2 - a second success_rate_class object, fits - a list of success_rate_class objects.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_means} plots density of means for one, two or multiple groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?success_rate_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/success_rate_class-plot_means_difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{plot_means_difference,success_rate_class-method} 4 | \alias{plot_means_difference,success_rate_class-method} 5 | \alias{plot_means_difference_success_rate} 6 | \title{plot_means_difference} 7 | \usage{ 8 | \S4method{plot_means_difference}{success_rate_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{success_rate_class object.} 12 | 13 | \item{...}{fit2 - a second success_rate_class object, fits - a list of success_rate_class objects, rope - region of practical equivalence, bins - number of bins in the histogram.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_means_difference} a visualization of the difference between two groups or multiple groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?success_rate_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/success_rate_class-plot_trace.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{plot_trace,success_rate_class-method} 4 | \alias{plot_trace,success_rate_class-method} 5 | \alias{plot_trace_success_rate} 6 | \title{plot_trace} 7 | \usage{ 8 | \S4method{plot_trace}{success_rate_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{success_rate_class object.} 12 | } 13 | \value{ 14 | A ggplot visualization. 15 | } 16 | \description{ 17 | \code{plot_trace} traceplot for main fitted model parameters. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?success_rate_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/summary-color_class-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_class.R 3 | \name{summary,color_class-method} 4 | \alias{summary,color_class-method} 5 | \title{summary} 6 | \usage{ 7 | \S4method{summary}{color_class}(object) 8 | } 9 | \arguments{ 10 | \item{object}{color_class object.} 11 | } 12 | \description{ 13 | \code{summary} prints summary of the Bayesian color fit. 14 | } 15 | \examples{ 16 | # to use the function you first have to prepare the data and fit the model 17 | # see class documentation for an example of the whole process 18 | # along with an example of how to use this function 19 | ?color_class 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/summary-linear_class-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/linear_class.R 3 | \name{summary,linear_class-method} 4 | \alias{summary,linear_class-method} 5 | \title{summary} 6 | \usage{ 7 | \S4method{summary}{linear_class}(object) 8 | } 9 | \arguments{ 10 | \item{object}{linear_class object.} 11 | } 12 | \description{ 13 | \code{summary} prints a summary of the Bayesian linear model fit. 14 | } 15 | \examples{ 16 | # to use the function you first have to prepare the data and fit the model 17 | # see class documentation for an example of the whole process 18 | # along with an example of how to use this function 19 | ?linear_class 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/summary-reaction_time_class-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reaction_time_class.R 3 | \name{summary,reaction_time_class-method} 4 | \alias{summary,reaction_time_class-method} 5 | \title{summary} 6 | \usage{ 7 | \S4method{summary}{reaction_time_class}(object) 8 | } 9 | \arguments{ 10 | \item{object}{reaction_time_class object.} 11 | } 12 | \description{ 13 | \code{summary} prints a summary of the Bayesian reaction time fit. 14 | } 15 | \examples{ 16 | # to use the function you first have to prepare the data and fit the model 17 | # see class documentation for an example of the whole process 18 | # along with an example of how to use this function 19 | ?reaction_time_class 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/summary-success_rate_class-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/success_rate_class.R 3 | \name{summary,success_rate_class-method} 4 | \alias{summary,success_rate_class-method} 5 | \title{summary} 6 | \usage{ 7 | \S4method{summary}{success_rate_class}(object) 8 | } 9 | \arguments{ 10 | \item{object}{success_rate_class object.} 11 | } 12 | \description{ 13 | \code{summary} prints a summary of the Bayesian success rate fit. 14 | } 15 | \examples{ 16 | # to use the function you first have to prepare the data and fit the model 17 | # see class documentation for an example of the whole process 18 | # along with an example of how to use this function 19 | ?success_rate_class 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/summary-ttest_class-method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ttest_class.R 3 | \name{summary,ttest_class-method} 4 | \alias{summary,ttest_class-method} 5 | \title{summary} 6 | \usage{ 7 | \S4method{summary}{ttest_class}(object) 8 | } 9 | \arguments{ 10 | \item{object}{ttest_class object.} 11 | } 12 | \description{ 13 | \code{summary} prints a summary of the Bayesian ttest fit. 14 | } 15 | \examples{ 16 | # to use the function you first have to prepare the data and fit the model 17 | # see class documentation for an example of the whole process 18 | # along with an example of how to use this function 19 | ?ttest_class 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/ttest_class-compare_distributions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ttest_class.R 3 | \name{compare_distributions,ttest_class-method} 4 | \alias{compare_distributions,ttest_class-method} 5 | \alias{compare_distributions_ttest} 6 | \title{compare_distributions} 7 | \usage{ 8 | \S4method{compare_distributions}{ttest_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{ttest_class object.} 12 | 13 | \item{...}{fit2 - a second ttest_class object, fits - a list of ttest_class objects, mu - mean value, sigma - standard deviation, rope - region of practical equivalence.} 14 | } 15 | \value{ 16 | Comparison results or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{compare_distributions} draws samples from distribution of the first group and compares them against samples drawn from the distribution of the second group, against samples drawn from distributions of multiple groups, against a mean value or against samples from a normal distribution with a defined mean value and variance. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?ttest_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/ttest_class-compare_means.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ttest_class.R 3 | \name{compare_means,ttest_class-method} 4 | \alias{compare_means,ttest_class-method} 5 | \alias{compare_means_ttest} 6 | \title{compare_means} 7 | \usage{ 8 | \S4method{compare_means}{ttest_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{ttest_class object.} 12 | 13 | \item{...}{fit2 - a second ttest_class object, mu - mean value, sigma - standard deviation, fits - a list of ttest_class objects, rope - region of practical equivalence, par - execute comparison through the sigma or nu parameter.} 14 | } 15 | \value{ 16 | Comparison results or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{compare_means} prints difference/equality of the first group against the second group, against multiple groups, against a mean value or against a normal distribution with a defined mean value and variance. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?ttest_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/ttest_class-get_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ttest_class.R 3 | \name{get_parameters,ttest_class-method} 4 | \alias{get_parameters,ttest_class-method} 5 | \alias{get_parameters_ttest_class} 6 | \title{get_parameters} 7 | \usage{ 8 | \S4method{get_parameters}{ttest_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{ttest_class object.} 12 | } 13 | \value{ 14 | A data frame with parameter values. 15 | } 16 | \description{ 17 | \code{get_parameters} returns a dataframe with values of fitted parameters. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?ttest_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/ttest_class-plot_distributions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ttest_class.R 3 | \name{plot_distributions,ttest_class-method} 4 | \alias{plot_distributions,ttest_class-method} 5 | \alias{plot_distributions_ttest} 6 | \title{plot_distributions} 7 | \usage{ 8 | \S4method{plot_distributions}{ttest_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{ttest_class object.} 12 | 13 | \item{...}{fit2 - a second ttest_class object, fits - a list of ttest_class objects, mu - mean value, sigma - standard deviation.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_distributions} visualizes distributions underlying tested groups. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?ttest_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/ttest_class-plot_distributions_difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ttest_class.R 3 | \name{plot_distributions_difference,ttest_class-method} 4 | \alias{plot_distributions_difference,ttest_class-method} 5 | \alias{plot_distributions_difference_ttest} 6 | \title{plot_distributions_difference} 7 | \usage{ 8 | \S4method{plot_distributions_difference}{ttest_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{ttest_class object.} 12 | 13 | \item{...}{fit2 - a second ttest_class object, fits - a list of ttest_class objects, mu - mean value, sigma - standard deviation, rope - region of practical equivalence, bins - number of bins in the histogram.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_distributions_difference} a visualization of the difference between the distribution of the first group, the distribution or a constant value for the second group or between multiple distributions. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?ttest_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/ttest_class-plot_fit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ttest_class.R 3 | \name{plot_fit,ttest_class-method} 4 | \alias{plot_fit,ttest_class-method} 5 | \alias{plot_fit_ttest} 6 | \title{plot_fit} 7 | \usage{ 8 | \S4method{plot_fit}{ttest_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{ttest_class object.} 12 | } 13 | \value{ 14 | A ggplot visualization. 15 | } 16 | \description{ 17 | \code{plot_fit} plots fitted model against the data. Use this function to explore the quality of your fit. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?ttest_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /man/ttest_class-plot_means.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ttest_class.R 3 | \name{plot_means,ttest_class-method} 4 | \alias{plot_means,ttest_class-method} 5 | \alias{plot_means_ttest} 6 | \title{plot_means} 7 | \usage{ 8 | \S4method{plot_means}{ttest_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{ttest_class object.} 12 | 13 | \item{...}{fit2 - a second ttest_class object, mu - mean value, fits - a list of ttest_class objects, par - plot the sigma or nu parameter.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_means} plots density of means, the first and the second group means, means of multiple groups or a mean value in case second group is defined as a constant. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?ttest_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/ttest_class-plot_means_difference.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ttest_class.R 3 | \name{plot_means_difference,ttest_class-method} 4 | \alias{plot_means_difference,ttest_class-method} 5 | \alias{plot_means_difference_ttest} 6 | \title{plot_means_difference} 7 | \usage{ 8 | \S4method{plot_means_difference}{ttest_class}(object, ...) 9 | } 10 | \arguments{ 11 | \item{object}{ttest_class object.} 12 | 13 | \item{...}{fit2 - a second ttest_class object, fits - a list of ttest_class objects, mu - mean value, rope - region of practical equivalence, bins - number of bins in the histogram, par - compare through the sigma or nu parameter.} 14 | } 15 | \value{ 16 | A ggplot visualization or an error if something went wrong. 17 | } 18 | \description{ 19 | \code{plot_means_difference} a visualization of the difference of the first group against the second group, against multiple groups, against a mean value or against a normal distribution with a defined mean value and variance. 20 | } 21 | \examples{ 22 | # to use the function you first have to prepare the data and fit the model 23 | # see class documentation for an example of the whole process 24 | # along with an example of how to use this function 25 | ?ttest_class 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/ttest_class-plot_trace.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ttest_class.R 3 | \name{plot_trace,ttest_class-method} 4 | \alias{plot_trace,ttest_class-method} 5 | \alias{plot_trace_ttest} 6 | \title{plot_trace} 7 | \usage{ 8 | \S4method{plot_trace}{ttest_class}(object) 9 | } 10 | \arguments{ 11 | \item{object}{ttest_class object.} 12 | } 13 | \value{ 14 | A ggplot visualization. 15 | } 16 | \description{ 17 | \code{plot_trace} traceplot for main fitted model parameters. 18 | } 19 | \examples{ 20 | # to use the function you first have to prepare the data and fit the model 21 | # see class documentation for an example of the whole process 22 | # along with an example of how to use this function 23 | ?ttest_class 24 | 25 | } 26 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(bayes4psy) 3 | 4 | test_check("bayes4psy") 5 | -------------------------------------------------------------------------------- /tests/testthat/test_bootstrap.R: -------------------------------------------------------------------------------- 1 | library(bayes4psy) 2 | 3 | # set seed 4 | seed <- 0 5 | set.seed(0) 6 | 7 | # set tolerance 8 | tol <- 0.2 9 | 10 | # linear function of seqence vs. response 11 | lm_statistic <- function(data) { 12 | lm(sequence ~ response, data)$coef 13 | } 14 | 15 | # load data 16 | data <- adaptation_level_small 17 | 18 | # bootstrap 19 | data_bootstrap <- b_bootstrap(data, lm_statistic, n1=1000, n2=1000) 20 | 21 | # get_parameters 22 | test_that("bootstrap", { 23 | expect_equal(mean(data_bootstrap$response), -0.479, tolerance=tol) 24 | expect_equal(mean(data_bootstrap$`(Intercept)`), 8.754, tolerance=tol) 25 | }) 26 | -------------------------------------------------------------------------------- /tests/testthat/test_color.R: -------------------------------------------------------------------------------- 1 | library(bayes4psy) 2 | 3 | # set seed 4 | seed <- 0 5 | set.seed(0) 6 | 7 | # set tolerance 8 | tol <- 0.2 9 | 10 | # priors for rgb 11 | mu_prior <- b_prior(family="uniform", pars=c(0, 255)) 12 | sigma_prior <- b_prior(family="uniform", pars=c(0, 100)) 13 | 14 | # attach priors to relevant parameters 15 | priors_rgb <- list(c("mu_r", mu_prior), 16 | c("sigma_r", sigma_prior), 17 | c("mu_g", mu_prior), 18 | c("sigma_g", sigma_prior), 19 | c("mu_b", mu_prior), 20 | c("sigma_b", sigma_prior)) 21 | 22 | 23 | # generate data (rgb) and fit 24 | r <- as.integer(rnorm(50, mean=250, sd=20)) 25 | r[r > 255] <- 255 26 | r[r < 0] <- 0 27 | 28 | g <- as.integer(rnorm(50, mean=20, sd=20)) 29 | g[g > 255] <- 255 30 | g[g < 0] <- 0 31 | 32 | b <- as.integer(rnorm(50, mean=40, sd=20)) 33 | b[b > 255] <- 255 34 | b[b < 0] <- 0 35 | 36 | colors <- data.frame(r=r, g=g, b=b) 37 | 38 | fit1 <- b_color(colors=colors, priors=priors_rgb, chains=1, seed=seed, refresh=0) 39 | 40 | 41 | # priors for hsv 42 | h_prior <- b_prior(family="uniform", pars=c(0, 2*pi)) 43 | sv_prior <- b_prior(family="uniform", pars=c(0, 1)) 44 | kappa_prior <- b_prior(family="uniform", pars=c(0, 500)) 45 | sigma_prior <- b_prior(family="uniform", pars=c(0, 1)) 46 | 47 | # attach priors to relevant parameters 48 | priors_hsv <- list(c("mu_h", h_prior), 49 | c("kappa_h", kappa_prior), 50 | c("mu_s", sv_prior), 51 | c("sigma_s", sigma_prior), 52 | c("mu_v", sv_prior), 53 | c("sigma_v", sigma_prior)) 54 | 55 | # generate data (hsv) and fit 56 | h <- rnorm(100, mean=2*pi/3, sd=0.5) 57 | h[h > 2*pi] <- 2*pi 58 | h[h < 0] <- 0 59 | 60 | s <- rnorm(100, mean=0.9, sd=0.2) 61 | s[s > 1] <- 1 62 | s[s < 0] <- 0 63 | 64 | v <- rnorm(100, mean=0.9, sd=0.2) 65 | v[v > 1] <- 1 66 | v[v < 0] <- 0 67 | 68 | colors <- data.frame(h=h, s=s, v=v) 69 | 70 | fit2 <- b_color(colors=colors, hsv=TRUE, priors=priors_hsv, chains=1, seed=seed, refresh=0) 71 | 72 | 73 | # summary 74 | test_that("color summary", { 75 | expect_output(summary(fit1), regexp="mu_h") 76 | expect_output(summary(fit1), regexp="kappa_h") 77 | }) 78 | 79 | 80 | # print and show 81 | test_that("color print and show", { 82 | expect_output(print(fit1), regexp="mu_h") 83 | expect_output(print(fit1), regexp="kappa_h") 84 | }) 85 | 86 | 87 | # get_parameters 88 | test_that("color get_parameters", { 89 | parameters <- get_parameters(fit1) 90 | expect_equal(mean(parameters$h), -0.06, tolerance=tol) 91 | expect_equal(mean(parameters$s), 0.93, tolerance=tol) 92 | expect_equal(mean(parameters$v), 0.96, tolerance=tol) 93 | }) 94 | 95 | 96 | # compare_means two fits 97 | test_that("color compare_means two fits", { 98 | o <- capture.output(output <- compare_means(fit1, fit2=fit2)) 99 | r <- c(0, 1, NA) 100 | g <- c(1, 0, NA) 101 | b <- c(1, 0, NA) 102 | h <- c(1, 0, NA) 103 | s <- c(0, 1, NA) 104 | v <- c(0, 1, NA) 105 | compare <- rbind(r, g, b, h, s, v) 106 | expect_equal(output, compare, tolerance=tol) 107 | }) 108 | 109 | 110 | # compare_distributions two fits 111 | test_that("color compare_distributions two fits", { 112 | o <- capture.output(output <- compare_distributions(fit1, fit2=fit2)) 113 | r <- c(0.00, 1.00, NA) 114 | g <- c(1.00, 0.00, NA) 115 | b <- c(0.72, 0.28, NA) 116 | h <- c(1.00, 0.00, NA) 117 | s <- c(0.32, 0.68, NA) 118 | v <- c(0.27, 0.73, NA) 119 | compare <- rbind(r, g, b, h, s, v) 120 | expect_equal(output, compare, tolerance=tol) 121 | }) 122 | -------------------------------------------------------------------------------- /tests/testthat/test_linear.R: -------------------------------------------------------------------------------- 1 | library(bayes4psy) 2 | 3 | # set seed 4 | seed <- 0 5 | set.seed(0) 6 | 7 | # set tolerance 8 | tol <- 0.5 9 | 10 | # priors 11 | mu_prior <- b_prior(family="normal", pars=c(0, 100)) 12 | sigma_prior <- b_prior(family="uniform", pars=c(0, 500)) 13 | 14 | # attach priors to relevant parameters 15 | priors <- list(c("mu_a", mu_prior), 16 | c("sigma_a", sigma_prior), 17 | c("mu_b", mu_prior), 18 | c("sigma_b", sigma_prior), 19 | c("mu_s", sigma_prior), 20 | c("sigma_s", sigma_prior)) 21 | 22 | 23 | # generate data and fit 24 | x <- vector() 25 | y <- vector() 26 | s <- vector() 27 | for (i in 1:5) { 28 | x <- c(x, rep(1:10)) 29 | y <- c(y, rnorm(10, mean=1:10, sd=2)) 30 | s <- c(s, rep(i, 10)) 31 | } 32 | 33 | fit1 <- b_linear(x=x, y=y, s=s, priors=priors, chains=1, seed=seed, refresh=0) 34 | 35 | fit2 <- b_linear(x=x, y=-2*y, s=s, priors=priors, chains=1, seed=seed, refresh=0) 36 | 37 | 38 | # summary 39 | test_that("linear summary", { 40 | expect_output(summary(fit1), regexp="intercept") 41 | expect_output(summary(fit1), regexp="slope") 42 | expect_output(summary(fit1), regexp="sigma") 43 | }) 44 | 45 | 46 | # print and show 47 | test_that("linear print and show", { 48 | expect_output(print(fit1), regexp="mu_a") 49 | expect_output(print(fit1), regexp="mu_b") 50 | expect_output(print(fit1), regexp="mu_s") 51 | }) 52 | 53 | 54 | # get_parameters 55 | test_that("linear get_parameters", { 56 | parameters <- get_parameters(fit1) 57 | expect_equal(mean(parameters$slope), 0.2, tolerance=tol) 58 | expect_equal(mean(parameters$intercept), 0.97, tolerance=tol) 59 | expect_equal(mean(parameters$sigma), 1.94, tolerance=tol) 60 | }) 61 | 62 | 63 | # get_subject_parameters 64 | test_that("linear get_subject_parameters", { 65 | parameters <- get_subject_parameters(fit1) 66 | expect_equal(mean(parameters$slope), 0.19, tolerance=tol) 67 | expect_equal(mean(parameters$intercept), 0.97, tolerance=tol) 68 | expect_equal(mean(parameters$sigma), 1.92, tolerance=tol) 69 | }) 70 | 71 | 72 | # compare_means two fits 73 | test_that("linear compare_means two fits", { 74 | o <- capture.output(output <- compare_means(fit1, fit2=fit2)) 75 | intercept <- c(0.32, 0.68, NA) 76 | slope <- c(0, 1, NA) 77 | compare <- rbind(intercept, slope) 78 | expect_equal(output, compare, tolerance=tol) 79 | }) 80 | 81 | 82 | # compare_distributions two fits 83 | test_that("linear compare_distributions two fits", { 84 | o <- capture.output(output <- compare_distributions(fit1, fit2=fit2)) 85 | intercept <- c(0.32, 0.68, NA) 86 | slope <- c(0.0, 1.0, NA) 87 | compare <- rbind(intercept, slope) 88 | expect_equal(output, compare, tolerance=tol) 89 | }) 90 | -------------------------------------------------------------------------------- /tests/testthat/test_reaction_time.R: -------------------------------------------------------------------------------- 1 | library(bayes4psy) 2 | 3 | # set seed 4 | seed <- 0 5 | set.seed(0) 6 | 7 | # set tolerance 8 | tol <- 0.2 9 | 10 | # priors 11 | mu_prior <- b_prior(family="normal", pars=c(0, 100)) 12 | sigma_prior <- b_prior(family="uniform", pars=c(0, 500)) 13 | lambda_prior <- b_prior(family="uniform", pars=c(0.05, 5)) 14 | 15 | # attach priors to relevant parameters 16 | priors <- list(c("mu_m", mu_prior), 17 | c("sigma_m", sigma_prior), 18 | c("mu_s", sigma_prior), 19 | c("sigma_s", sigma_prior), 20 | c("mu_l", lambda_prior), 21 | c("sigma_l", sigma_prior)) 22 | 23 | 24 | # subjects 25 | s <- rep(1:5, 10) 26 | 27 | # generate data and fit 28 | rt1 <- emg::remg(50, mu=10, sigma=1, lambda=0.4) 29 | fit1 <- b_reaction_time(t=rt1, s=s, priors=priors, chains=1, seed=seed, refresh=0) 30 | 31 | rt2 <- emg::remg(50, mu=20, sigma=2, lambda=0.1) 32 | fit2 <- b_reaction_time(t=rt2, s=s, priors=priors, chains=1, seed=seed, refresh=0) 33 | 34 | rt3 <- emg::remg(50, mu=10, sigma=2, lambda=1) 35 | fit3 <- b_reaction_time(t=rt3, s=s, priors=priors, chains=1, seed=seed, refresh=0) 36 | 37 | # fit list 38 | fit_list <- list(fit2, fit3) 39 | 40 | 41 | # summary 42 | test_that("reaction_time summary", { 43 | expect_output(summary(fit1), regexp="rt") 44 | expect_output(summary(fit1), regexp="mu") 45 | expect_output(summary(fit1), regexp="sigma") 46 | expect_output(summary(fit1), regexp="lambda") 47 | }) 48 | 49 | 50 | # print and show 51 | test_that("reaction_time print and show", { 52 | expect_output(print(fit1), regexp="mu_m") 53 | expect_output(print(fit1), regexp="mu_l") 54 | expect_output(print(fit1), regexp="mu_s") 55 | }) 56 | 57 | 58 | # get_parameters 59 | test_that("reaction_time get_parameters", { 60 | parameters <- get_parameters(fit1) 61 | expect_equal(mean(parameters$rt), 11.90, tolerance=tol) 62 | }) 63 | 64 | 65 | # get_subject_parameters 66 | test_that("reaction_time get_subject_parameters", { 67 | parameters <- get_subject_parameters(fit1) 68 | expect_equal(mean(parameters$rt), 12.00, tolerance=tol) 69 | }) 70 | 71 | 72 | # compare_means two fits 73 | test_that("reaction_time compare_means two fits", { 74 | o <- capture.output(output <- compare_means(fit1, fit2=fit2)) 75 | expect_equal(output[1, 2], 0, tolerance=tol) 76 | expect_equal(output[2, 1], 1, tolerance=tol) 77 | }) 78 | 79 | 80 | # compare_means multiple fits 81 | test_that("reaction_time compare_means multiple fits", { 82 | o <- capture.output(output <- compare_means(fit1, fits=fit_list)) 83 | expect_equal(output$comparison_matrix[1,], c(NA, 0, 0.94), tolerance=tol) 84 | expect_equal(output$smallest_largest$smallest, c(0.06, 0, 0.94), tolerance=tol) 85 | }) 86 | 87 | 88 | # compare_distributions two fits 89 | test_that("reaction_time compare_distributions two fits", { 90 | o <- capture.output(output <- compare_distributions(fit1, fit2=fit2)) 91 | expect_equal(output[1, 2], 0.03, tolerance=tol) 92 | expect_equal(output[2, 1], 0.97, tolerance=tol) 93 | }) 94 | 95 | 96 | # compare_distributions multiple fits 97 | test_that("reaction_time compare_distributions multiple fits", { 98 | o <- capture.output(output <- compare_distributions(fit1, fits=fit_list)) 99 | expect_equal(output$comparison_matrix[1,], c(NA, 0.03, 0.66), tolerance=tol) 100 | expect_equal(output$smallest_largest$smallest, c(0.33, 0.01, 0.65), tolerance=tol) 101 | }) 102 | -------------------------------------------------------------------------------- /tests/testthat/test_success_rate.R: -------------------------------------------------------------------------------- 1 | library(bayes4psy) 2 | 3 | # set seed 4 | seed <- 0 5 | set.seed(0) 6 | 7 | # set tolerance 8 | tol <- 0.2 9 | 10 | # priors 11 | p_prior <- b_prior(family="beta", pars=c(1, 1)) 12 | tau_prior <- b_prior(family="uniform", pars=c(0, 500)) 13 | 14 | # attach priors to relevant parameters 15 | priors <- list(c("p", p_prior), 16 | c("tau", tau_prior)) 17 | 18 | # subjects 19 | s <- rep(1:5, 20) 20 | 21 | # generate data and fit 22 | data1 <- rbinom(100, size=1, prob=0.6) 23 | fit1 <- b_success_rate(r=data1, s=s, priors=priors, chains=1, seed=seed, refresh=0) 24 | 25 | data2 <- rbinom(100, size=1, prob=0.1) 26 | fit2 <- b_success_rate(r=data2, s=s, priors=priors, chains=1, seed=seed, refresh=0) 27 | 28 | data3 <- rbinom(100, size=1, prob=0.5) 29 | fit3 <- b_success_rate(r=data3, s=s, priors=priors, chains=1, seed=seed, refresh=0) 30 | 31 | # fit list 32 | fit_list <- list(fit2, fit3) 33 | 34 | 35 | # summary 36 | test_that("success_rate summary", { 37 | expect_output(summary(fit1), regexp="Success rate") 38 | }) 39 | 40 | 41 | # print and show 42 | test_that("success_rate print and show", { 43 | expect_output(print(fit1), regexp="p0") 44 | expect_output(print(fit1), regexp="tau") 45 | }) 46 | 47 | 48 | # get_parameters 49 | test_that("success_rate get_parameters", { 50 | parameters <- get_parameters(fit1) 51 | expect_equal(mean(parameters$p), 0.57, tolerance=tol) 52 | }) 53 | 54 | 55 | # get_subject_parameters 56 | test_that("success_rate get_subject_parameters", { 57 | parameters <- get_subject_parameters(fit1) 58 | expect_equal(mean(parameters$p), 0.57, tolerance=tol) 59 | }) 60 | 61 | 62 | # compare_means two fits 63 | test_that("success_rate compare_means two fits", { 64 | o <- capture.output(output <- compare_means(fit1, fit2=fit2)) 65 | expect_equal(output[1, 2], 1, tolerance=tol) 66 | expect_equal(output[2, 1], 0, tolerance=tol) 67 | }) 68 | 69 | 70 | # compare_means multiple fits 71 | test_that("success_rate compare_means multiple fits", { 72 | o <- capture.output(output <- compare_means(fit1, fits=fit_list)) 73 | expect_equal(output$comparison_matrix[1,], c(NA, 1.00, 0.96), tolerance=tol) 74 | expect_equal(output$smallest_largest$smallest, c(0, 1, 0), tolerance=tol) 75 | }) 76 | 77 | 78 | # compare_distributions two fits 79 | test_that("success_rate compare_distributions two fits", { 80 | o <- capture.output(output <- compare_distributions(fit1, fit2=fit2)) 81 | expect_equal(output[1, 2], 1, tolerance=tol) 82 | expect_equal(output[2, 1], 0, tolerance=tol) 83 | }) 84 | 85 | 86 | # compare_distributions multiple fits 87 | test_that("success_rate compare_distributions multiple fits", { 88 | o <- capture.output(output <- compare_distributions(fit1, fits=fit_list)) 89 | expect_equal(output$comparison_matrix[1,], c(NA, 1, 1), tolerance=tol) 90 | expect_equal(output$smallest_largest$smallest, c(0, 1, 0), tolerance=tol) 91 | }) 92 | -------------------------------------------------------------------------------- /tests/testthat/test_ttest.R: -------------------------------------------------------------------------------- 1 | library(bayes4psy) 2 | 3 | # set seed 4 | seed <- 0 5 | set.seed(0) 6 | 7 | # set tolerance 8 | tol <- 0.2 9 | 10 | # priors 11 | mu_prior <- b_prior(family="normal", pars=c(0, 1000)) 12 | sigma_prior <- b_prior(family="uniform", pars=c(0, 500)) 13 | 14 | # attach priors to relevant parameters 15 | priors <- list(c("mu", mu_prior), 16 | c("sigma", sigma_prior)) 17 | 18 | # generate data and fit 19 | data1 <- rnorm(20, mean=150, sd=20) 20 | fit1 <- b_ttest(data=data1, priors=priors, chains=1, seed=seed, refresh=0) 21 | 22 | data2 <- rnorm(20, mean=200, sd=20) 23 | fit2 <- b_ttest(data=data2, priors=priors, chains=1, seed=seed, refresh=0) 24 | 25 | data3 <- rnorm(20, mean=150, sd=40) 26 | fit3 <- b_ttest(data=data3, priors=priors, chains=1, seed=seed, refresh=0) 27 | 28 | # fit list 29 | fit_list <- list(fit2, fit3) 30 | 31 | 32 | # summary 33 | test_that("ttest summary", { 34 | expect_output(summary(fit1), regexp="mu") 35 | expect_output(summary(fit1), regexp="sigma") 36 | expect_output(summary(fit1), regexp="nu") 37 | }) 38 | 39 | 40 | # print and show 41 | test_that("ttest print and show", { 42 | expect_output(summary(fit1), regexp="mu") 43 | expect_output(summary(fit1), regexp="sigma") 44 | expect_output(summary(fit1), regexp="nu") 45 | }) 46 | 47 | 48 | # get_parameters 49 | test_that("ttest get_parameters", { 50 | parameters <- get_parameters(fit1) 51 | expect_equal(mean(parameters$mu), 149.58, tolerance=tol) 52 | expect_equal(mean(parameters$sigma), 21.16, tolerance=tol) 53 | expect_equal(mean(parameters$nu), 33.58, tolerance=tol) 54 | }) 55 | 56 | 57 | # compare_means two fits 58 | test_that("ttest compare_means two fits", { 59 | o <- capture.output(output <- compare_means(fit1, fit2=fit2)) 60 | expect_equal(output[1, 2], 0, tolerance=tol) 61 | expect_equal(output[2, 1], 1, tolerance=tol) 62 | }) 63 | 64 | 65 | # compare_means fit and mu 66 | test_that("ttest compare_means fit and mu", { 67 | o <- capture.output(output <- compare_means(fit1, mu=150)) 68 | expect_equal(output[1, 2], 0.47, tolerance=tol) 69 | expect_equal(output[2, 1], 0.53, tolerance=tol) 70 | }) 71 | 72 | 73 | # compare_means multiple fits 74 | test_that("ttest compare_means multiple fits", { 75 | o <- capture.output(output <- compare_means(fit1, fits=fit_list)) 76 | expect_equal(output$comparison_matrix[1,], c(NA, 0.0, 0.39), tolerance=tol) 77 | expect_equal(output$smallest_largest$smallest, c(0.6, 0, 0.4), tolerance=tol) 78 | }) 79 | 80 | 81 | # compare_distributions two fits 82 | test_that("ttest compare_distributions two fits", { 83 | o <- capture.output(output <- compare_distributions(fit1, fit2=fit2)) 84 | expect_equal(output[1, 2], 0.03, tolerance=tol) 85 | expect_equal(output[2, 1], 0.97, tolerance=tol) 86 | }) 87 | 88 | 89 | # compare_distributions multiple fits 90 | test_that("ttest compare_distributions multiple fits", { 91 | o <- capture.output(output <- compare_distributions(fit1, fits=fit_list)) 92 | expect_equal(output$comparison_matrix[1,], c(NA, 0.03, 0.47), tolerance=tol) 93 | expect_equal(output$smallest_largest$smallest, c(0.52, 0.01, 0.47), tolerance=tol) 94 | }) 95 | -------------------------------------------------------------------------------- /vignettes/adaptation_level.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Analysis of the adaptation level experiment data using the Bayesian linear model" 3 | author: "Jure Demšar, Erik Štrumbelj and Grega Repovš" 4 | date: "`r Sys.Date()`" 5 | output: 6 | html_vignette: 7 | toc: yes 8 | --- 9 | 10 | 15 | 16 | ```{r, message=FALSE, warning=FALSE, echo=FALSE} 17 | # knitr options 18 | knitr::opts_chunk$set(fig.width=6, fig.height=4.5) 19 | options(width=800) 20 | ``` 21 | 22 | # Introduction 23 | 24 | In the adaptation level experiment participants had to assess weights of the objects placed in their hands by using a verbal scale: very very light, very light, light, medium light, medium, medium heavy, heavy, very heavy and very very heavy. The task was to assess the weight of an object that was placed on the palm of their hand. To standardize the procedure the participants had to place the elbow on the desk, extend the palm and assess the weight of the object after it was placed on their palm by slight up and down movements of their arm. During the experiment participants were blinded by using non-transparent fabric. In total there were 15 objects of the same shape and size but different mass (photo film canisters filled with metallic balls). Objects were grouped into three sets: 25 | 26 | * light set: 45 g, 55 g, 65 g, 75 g, 85 g (weights 1 to 5), 27 | * medium set: 95 g, 105 g, 115 g, 125 g, 135 g (weights 6 to 10), 28 | * heavy set: 145 g, 155 g, 165 g, 175 g, 185 g (weights 11 to 15). 29 | 30 | The experimenter sequentially placed weights in the palm of the participant and recorded the trial index, the weight of the object and participant's response. The participants were divided into two groups, in group 1 the participants first assessed the weights of the light set in ten rounds within which all five weights were weighted in a random order. After completing the 10 rounds with the light set, the experimenter switched to the medium set, without any announcement or break. The participant then weighted the medium set across another 10 rounds of weighting the five weights in a random order within each round. In group 2 the overall procedure was the same, the only difference being that they started with the 10 rounds of the heavy set and then performed another 10 rounds of weighting of the medium set. Importantly, the weights within each set were given in random order and the experimenter switched between sets seamlessly without any break or other indication to the participant. 31 | 32 | We will use the **bayes4psy** package to show that the two groups provide different assessment of the weights in the second part of the experiment even though both groups are responding to weights from the same (medium) set. The difference is very pronounced at first but then fades away with subsequent assessments of medium weights. This is congruent with the hypothesis that each group formed a different adaptation level during the initial phase of the task, the formed adaptation level then determined the perceptual experience of the same set of weights at the beginning of the second part of the task. 33 | 34 | We will conduct the analysis by using the hierarchical linear model. First we have to construct fits for the second part of the experiment for each group independently. The code below loads and prepares the data, just like in the previous example, subject indexes have to be mapped to a [1, n] interval. We will use to **ggplot2** package to fine-tune graph axes and properly annotate graphs returned by the **bayes4psy** package. 35 | 36 | ```{r, message=FALSE, warning=FALSE} 37 | # libs 38 | library(bayes4psy) 39 | library(dplyr) 40 | library(ggplot2) 41 | 42 | # load data 43 | data <- adaptation_level 44 | 45 | # separate groups and parts 46 | group1_part2 <- data %>% filter(group == 1 & part == 2) 47 | group2_part2 <- data %>% filter(group == 2 & part == 2) 48 | ``` 49 | 50 | Once the data is prepared we can fit the Bayesian models, the input data comes in the form of three vectors, $x$ stores indexes of the measurements, $y$ subject's responses and $s$ indexes of subjects. Note here that, due to vignette limitations, all fits are built using only one chain, using more chains in parallel is usually more efficient. Also to increase the building speed of vignettes we greatly reduced the amount of iterations, use an appropriate amount of iterations when executing actual analyses! 51 | 52 | ```{r, message=FALSE, warning=FALSE, results = 'hide'} 53 | # fit 54 | fit1 <- b_linear(x=group1_part2$sequence, 55 | y=group1_part2$response, 56 | s=group1_part2$subject, 57 | iter=200, warmup=100, chains=1) 58 | 59 | fit2 <- b_linear(x=group2_part2$sequence, 60 | y=group2_part2$response, 61 | s=group2_part2$subject, 62 | iter=200, warmup=100, chains=1) 63 | ``` 64 | 65 | The fitting process is always followed by the quality analysis. 66 | 67 | ```{r, message=FALSE, warning=FALSE} 68 | # trace plots 69 | plot_trace(fit1) 70 | plot_trace(fit2) 71 | 72 | # the commands below are commented out for the sake of brevity 73 | #print(fit1) 74 | #print(fit2) 75 | 76 | # visual inspection 77 | plot(fit1) 78 | plot(fit2) 79 | ``` 80 | 81 | The trace plot showed no MCMC related issues, effective sample sizes of parameters relevant for our analysis ($\mu_a$, $\mu_b$ and $\mu_s$) are large enough. Since the visual inspection of the fit also looks good we can continue with our analysis. To get a quick description of fits we can take a look at the summary statistics of model's parameters. 82 | 83 | ```{r, message=FALSE, warning=FALSE} 84 | summary(fit1) 85 | summary(fit2) 86 | ``` 87 | 88 | Values of intercept suggest that our initial hypothesis about adaptation level is true. Subject's that weighted lighter object in the first part of the experiment (**fit1**) find medium objects at the beginning of experiment's second part heavier than subjects that weighted heavier objects in the first part (**fit2**). We can confirm this assumption by using functions that perform a more detailed analysis (e.g. **compare\_means** and **plot\_means\_difference**, see the outputs below). 89 | 90 | ```{r, message=FALSE, warning=FALSE} 91 | comparison_results <- compare_means(fit1, fit2=fit2) 92 | 93 | plot_means_difference(fit1, fit2=fit2, par="intercept") 94 | ``` 95 | 96 | The fact that the slope for the first group is very likely to be negative (the whole 95\% HDI lies below 0) and positive for the second group (the whole 95\% HDI lies above 0) suggests that the adaptation level phenomenon fades away with time. We can visualize this by plotting means and distributions underlying both fits. The plotting functions in the **bayes4psy** package return regular **ggplot2** plot objects, so we can use the same techniques to annotate or change the look and feel of graphs as we would with the usual **ggplot2** visualizations. 97 | 98 | ```{r, message=FALSE, warning=FALSE} 99 | plot_distributions(fit1, fit2) + 100 | labs(title="Part II", x="measurement number", y="") + 101 | theme(legend.position="none") + 102 | scale_x_continuous(limits=c(1, 10), breaks=seq(1:10)) + 103 | ylim(0, 10) 104 | ``` 105 | 106 | Based on the analysis above, the hypothesis that each group formed a different adaptation level during the initial phase of the task seems to be true. Group that switches from heavy to medium weights assesses weights as lighter than they really are while for the group that switches from light to medium the weights appear heavier. With time these adaptation levels fade away and assessments converge to similar estimates of weight. 107 | --------------------------------------------------------------------------------