BayesPsychometric is a package designed for researchers primarily in
the field of psychology, though others may still find it useful. It
provides a set of tools for fitting psychometric (psychophysical)
functions with mixed continuous and categorical data using a Bayesian
framework built on top of
Stan
.
Since BayesPsychometric depends on RStan, it is best to install that
first using the directions on the RStan github
page.
From their page, it is recommended that you first remove anying existing
RStan
remove.packages("rstan")
if (file.exists(".RData")) file.remove(".RData")
Then, restart R
In most cases, you can simply type (exactly like this)
install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
You’ll really want to check on the installation page for post-installation steps (like setting up the C++ toolchain if required).
Then you can install BayesPsychometric via
devtools::install_github("adknudson/BayesPsychometric")
# Or the development branch
devtools::install_github("adknudson/BayesPsychometric", ref = "develop")
The main function for fitting is bayesPF (which stands for Bayes
Psychometric Function). The syntax is very similar to that of the base
glm function, but with a slight twist. The function can handle data
that is either in binary format (outcome is 0 or 1) or binomial
format ((k) success in (n) trials).
There are two built-in synthetic data sets called
Sample_Data_Bernoulli (binary) and Sample_Data_Binomial (binomial)
that can be used to test the functionality of this package.
Binary data syntax:
bayesPF(y ~ x1 + gender + age, data = Sample_Data_Bernoulli, link = "logit")
Binomial data syntax:
bayesPF(y|k ~ x1 + gender + age, data = Sample_Data_Binomial, link = "logit")
The only real difference is that for binomial data, the response is
specified as the number of success, (y), given a number of trials,
(k). Estimates for each combination of factors can be extracted using
extractFactorSamples(fit) (see Model Assumptions).
This package assumes a basic model shown below
where (F) is the link function (either logit or probit). Where factor (or categorical) variables are included in the model, they will automatically contribute to the slope and intercept (varying slope, varying intercept model). Using the binary response example above, the model would be
This model assumption extends to situations where there are more than one continuous predictor. The default (and currently only) behavior is to treat factor variables as contributing to changes in the slope and intercept (though the intercept can be specified to be excluded). E.g. the general model is
where x1, x2, … are continuous predictors specified in the model.
Adaptive pooling is a functionality that allows for multilevel (heirarchical) modeling. It essentially allows information to be shared across different levels in the presence of factor variables (see McElreath, Statistical Rethinking). This feature generally has the benefit of acting as a regularization among parameters, and in some cases it can overcome the problem of complete separation among categories and the response.
If you happen to use this package for research or other projects, please share with me so I can get more ideas of how to expand the functionality of this package, and feature examples of how this package is being used!
I started writing this package as a way to simplify the tools that I’m using as I contribute to research at my school.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.