Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/bstatcomp/bayes4psy into…
Browse files Browse the repository at this point in the history
… develop

# Conflicts:
#	vignettes/adaptation_level.Rmd
#	vignettes/afterimages.Rmd
  • Loading branch information
demsarjure committed Dec 13, 2019
2 parents 499d9f0 + 8f08f42 commit a6c3320
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 41 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
cran-comments.md
^doc$
^Meta$
^CRAN-RELEASE$
2 changes: 2 additions & 0 deletions CRAN-RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This package was submitted to CRAN on 2019-12-09.
Once it is accepted, delete this file and tag the release (commit a74156ffe8).
3 changes: 2 additions & 1 deletion R/color_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ setMethod(f="show", signature(object="color_class"), definition=function(object)

#' @title plot
#' @description \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).
#' @param object color_class object.
#' @param x color_class object.
#' @param y empty dummy variable, ignore this.
#' @param ... pars - components of comparison, a subset of (r, g, b, h, s, v).
#' @exportMethod plot
#'
Expand Down
22 changes: 13 additions & 9 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#' Datasets for bayes4psy examples
#' Example datasets for use in \pkg{rstanarm} examples and vignettes.
#' The datasets were extracted from the internal MBLab \url{http://www.mblab.si} repository.
#' MBLab is a research lab at the Faculty of Arts, Department of Psychology, University of Ljubljana, Slovenia.
#'
#' @name bayes4psy-datasets
#' @aliases adaptation_level_small
#' @aliases adaptation_level_small adaptation_level after_images_opponent_process after_images_stimuli after_images_trichromatic after_images flanker stroop_extended stroop_simple
#'
#' @format
#' \describe{
#' \item{\code{adaptation_level_small}}{
#' Small dataset on subjects picking up weights and determining their weights from 1..10.
#'
#' Source: Internal MBLab repository.
#'
#' 50 obs. of 3 variables
#' \itemize{
#' \item \code{sequence} sequence index.
Expand All @@ -19,7 +23,7 @@
#' \item{\code{adaptation_level}}{
#' Data on subjects picking up weights and determining their weights from 1..10.
#'
#' Source: Internal MBLab \url{www.mblab.si} repository.
#' Source: Internal MBLab repository.
#'
#' 2900 obs. of 6 variables
#' \itemize{
Expand All @@ -34,7 +38,7 @@
#' #' \item{\code{after_images_opponent_process}}{
#' Colors predicted by the opponent process theory.
#'
#' Source: Internal MBLab \url{www.mblab.si} repository.
#' Source: Internal MBLab repository.
#'
#' 6 obs. of 7 variables
#' \itemize{
Expand All @@ -50,7 +54,7 @@
#' #' \item{\code{after_images_opponent_stimuli}}{
#' Stimuli used in the after images experiment.
#'
#' Source: Internal MBLab \url{www.mblab.si} repository.
#' Source: Internal MBLab repository.
#'
#' 6 obs. of 7 variables
#' \itemize{
Expand All @@ -66,7 +70,7 @@
#' #' \item{\code{after_images_trichromatic}}{
#' Colors predicted by the trichromatic theory.
#'
#' Source: Internal MBLab \url{www.mblab.si} repository.
#' Source: Internal MBLab repository.
#'
#' 6 obs. of 7 variables
#' \itemize{
Expand All @@ -82,7 +86,7 @@
#' #' \item{\code{after_images}}{
#' Data gathered by the after images experiment.
#'
#' Source: Internal MBLab \url{www.mblab.si} repository.
#' Source: Internal MBLab repository.
#'
#' 1311 obs. of 12 variables
#' \itemize{
Expand All @@ -103,7 +107,7 @@
#' #' \item{\code{flanker}}{
#' Data gathered by the flanker experiment.
#'
#' Source: Internal MBLab \url{www.mblab.si} repository.
#' Source: Internal MBLab repository.
#'
#' 8256 obs. of 5 variables
#' \itemize{
Expand All @@ -117,7 +121,7 @@
#' #' \item{\code{stroop_extended}}{
#' All the data gathered by the Stroop experiment.
#'
#' Source: Internal MBLab \url{www.mblab.si} repository.
#' Source: Internal MBLab repository.
#'
#' 41068 obs. of 5 variables
#' \itemize{
Expand All @@ -131,7 +135,7 @@
#' #' \item{\code{stroop_simple}}{
#' All the data gathered by the Stroop experiment.
#'
#' Source: Internal MBLab \url{www.mblab.si} repository.
#' Source: Internal MBLab repository.
#'
#' 61 obs. of 5 variables
#' \itemize{
Expand Down
2 changes: 1 addition & 1 deletion R/linear_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ setMethod(f="show", signature(object="linear_class"), definition=function(object

#' @title plot
#' @description \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).
#' @param object linear_class object.
#' @param x linear_class object.
#' @param ... subjects - plot fits on a subject level (default = TRUE).
#' @exportMethod plot
#'
Expand Down
3 changes: 2 additions & 1 deletion R/reaction_time_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ setMethod(f="show", signature(object="reaction_time_class"), definition=function

#' @title plot
#' @description \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).
#' @param object reaction_time_class object.
#' @param x reaction_time_class object.
#' @param y empty dummy variable, ignore this.
#' @param ... subjects - plot fits on a subject level (default = TRUE).
#' @exportMethod plot
#'
Expand Down
3 changes: 2 additions & 1 deletion R/success_rate_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ setMethod(f="show", signature(object="success_rate_class"), definition=function(

#' @title plot
#' @description \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).
#' @param object success_rate_class object.
#' @param x success_rate_class object.
#' @param y empty dummy variable, ignore this.
#' @param ... subjects - plot fits on a subject level (default = TRUE).
#' @exportMethod plot
#'
Expand Down
4 changes: 2 additions & 2 deletions R/ttest_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ setMethod(f="show", signature(object="ttest_class"), definition=function(object)

#' @title plot
#' @description \code{plot} plots fitted model against the data. Use this function to explore the quality of your fit.
#' @param object ttest_class object.
#' @param x ttest_class object.
#' @exportMethod plot
#'
#' @examples
Expand Down Expand Up @@ -780,7 +780,7 @@ setMethod(f="plot_means", signature(object="ttest_class"), definition=function(o
x_min <- min(x_min, par2)
x_max <- max(x_max, par2)
}

diff <- x_max - x_min
x_min <- x_min - 0.1*diff
x_max <- x_max + 0.1*diff
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bayes4psy

[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/bayes4psy?color=blue)](http://cran.r-project.org/package=bayes4psy)[![Downloads](http://cranlogs.r-pkg.org/badges/bayes4psy?color=blue)](http://cran.rstudio.com/package=bayes4psy)
[![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)

## The package

Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Revisions

### CRAN submission 18. 6. 2019
### CRAN submission 28. 6. 2019

Everything was OK.

Expand Down
32 changes: 23 additions & 9 deletions man/bayes4psy-datasets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/plot-color_class-missing-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/plot-linear_class-missing-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/plot-reaction_time_class-missing-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/plot-success_rate_class-missing-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plot-ttest_class-missing-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions vignettes/adaptation_level.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ We will conduct the analysis by using the hierarchical linear model. First we ha
# libs
library(bayes4psy)
library(ggplot2)
library(plyr)
library(dplyr)
# load data
Expand All @@ -50,18 +51,18 @@ group1_part2 <- data %>% filter(group == 1 & part == 2)
group2_part2 <- data %>% filter(group == 2 & part == 2)
```

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. The **warmup** and **iter** parameters are set in order to achieve an effective sample size of 10,000.
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.

```{r, message=FALSE, warning=FALSE}
fit1 <- b_linear(x=group1_part2$sequence,
y=group1_part2$response,
s=group1_part2$subject,
iter=10000, warmup=500)
iter=2000, warmup=500)
fit2 <- b_linear(x=group2_part2$sequence,
y=group2_part2$response,
s=group2_part2$subject,
iter=10000, warmup=500)
iter=2000, warmup=500)
```

The fitting process is always followed by the quality analysis.
Expand Down
7 changes: 4 additions & 3 deletions vignettes/afterimages.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ We start our analysis by loading the experiment and stimuli data. The experiment
library(bayes4psy)
library(dplyr)
library(ggplot2)
library(cowplot)
# load data
data_all <- after_images
Expand Down Expand Up @@ -232,9 +233,9 @@ plot_magenta <- plot_magenta + ggtitle("Magenta") +
We can then use the **cowplot** library to combine the plots into a single figure.

```{r, message=FALSE, warning=FALSE}
cowplot::plot_grid(plot_red, plot_green, plot_blue,
plot_yellow, plot_cyan, plot_magenta,
ncol=3, nrow=2, scale=0.9)
plot_grid(plot_red, plot_green, plot_blue,
plot_yellow, plot_cyan, plot_magenta,
ncol=3, nrow=2, scale=0.9)
```

This last figure features the comparison of predictions between the thrichromatic and the oponent-process color coding. The long solid line visualizes the trichromatic color coding prediction while the dashed line visualizes the opponent-process color coding. Short solid line represents the mean hue of the fit and the the colored band the 95% HDI of the distribution underlying the fit. The small colored circle visualizes the color of the presented stimuli. In the case of blue and yellow stimuli the dashed line is not visible because both color codings predict the same outcome. The prediction based on the thrichromatic color coding seems more accurate as its prediction is always inside the 95% of the most probable subject's responses and is always closer to the mean predicted hue than the opponent-process prediction. The opponent-process prediction is outside of the 95% of the most probable subject's responses in cases of red and green stimuli.

0 comments on commit a6c3320

Please sign in to comment.