Commit 67690336 authored by Andreas Tille's avatar Andreas Tille

Update upstream source from tag 'upstream/0.9.12-4'

Update to upstream version '0.9.12-4'
with Debian dir 6ea21f3db691201055d006aed1230a3d124d39f0
parents 6baa6a88 44347e67
Makefile
BayesFactor-intro.Rnw
\ No newline at end of file
Package: BayesFactor
Type: Package
Title: Computation of Bayes Factors for Common Designs
Version: 0.9.12-2
Date: 2015-09-19
Version: 0.9.12-4
Date: 2018-05-06
Authors@R: c(person("Richard D.", "Morey", role = c("aut", "cre"), email =
"richarddmorey@gmail.com"), person("Jeffrey N.", "Rouder", role = "aut",
email = "rouderj@missouri.edu"), person("Tahira", "Jamil", role = "ctb",
......@@ -13,20 +13,21 @@ Description: A suite of functions for computing
linear regression.
License: GPL-2
VignetteBuilder: knitr
Depends: R (>= 3.0.2), coda, Matrix (>= 1.1-1)
Depends: R (>= 3.2.0), coda, Matrix (>= 1.1-1)
Imports: pbapply, mvtnorm, stringr, utils, graphics, gtools,
MatrixModels, Rcpp (>= 0.11.2), methods
MatrixModels, Rcpp (>= 0.11.2), methods, hypergeo
Suggests: doMC, foreach, testthat, knitr, markdown, arm, lme4, xtable,
languageR
URL: http://bayesfactorpcl.r-forge.r-project.org/
URL: https://richarddmorey.github.io/BayesFactor/
BugReports: https://github.com/richarddmorey/BayesFactor/issues
LazyLoad: yes
LinkingTo: Rcpp (>= 0.11.2), RcppEigen (>= 0.3.2.2.0)
RoxygenNote: 6.0.1
NeedsCompilation: yes
Packaged: 2015-09-19 10:57:22 UTC; richard
Packaged: 2018-05-07 17:04:16 UTC; richard
Author: Richard D. Morey [aut, cre],
Jeffrey N. Rouder [aut],
Tahira Jamil [ctb]
Maintainer: Richard D. Morey <richarddmorey@gmail.com>
Repository: CRAN
Date/Publication: 2015-09-19 19:50:23
Date/Publication: 2018-05-07 20:51:29 UTC
This diff is collapsed.
useDynLib(BayesFactor)
export(logMeanExpLogs,
export(logMeanExpLogs,
logCumMeanExpLogs,
BFInfo,
ttest.tstat,
oneWayAOV.Fstat,
linearReg.R2stat,
oneWayAOV.Fstat,
linearReg.R2stat,
nWayAOV,
ttestBF,
lmBF,
......@@ -22,7 +22,8 @@ export(logMeanExpLogs,
logSummaryStats,
newPriorOdds,
"priorOdds<-",
"priorLogodds<-")
"priorLogodds<-",
correlationBF)
importFrom(methods, show)
importFrom(utils, head)
......@@ -40,10 +41,10 @@ importFrom("methods", ".hasSlot", "S3Part", "S3Part<-", "as", "is",
"new", "slot", "slot<-", "slotNames")
importFrom("stats", "aov", "dbinom", "dnorm", "dt", "formula",
"integrate", "lm", "nlm", "optim", "pcauchy", "plogis",
"pt", "qlogis", "rgamma", "sd", "t.test", "terms", "var")
"pt", "qlogis", "rgamma", "sd", "t.test", "terms", "var", "dlogis")
importFrom("utils", "combn", "setTxtProgressBar", "txtProgressBar",
"vignette")
importFrom("stats", "cor", "dbeta", "pbeta", "pnorm")
exportClasses("BFmodel", "BFBayesFactor","BFlinearModel", "BFodds")
exportClasses("BFBayesFactorList", "BFoneSample","BFindepSample","BFcontingencyTable")
......
CHANGES IN BayesFactor VERSION 0.9.12-4
CHANGES
* Fixed issue with numerical integration in proportionBF with large N
* New function correlationBF - implements Jeffreys' correlation Bayes factor tests
* Fixed rare bug that prevented sampling posteriors in some circumstances
* Sampling regression models now provides estimate intercept. This may break some old code if you were referring to columns by number instead of name.
* Fixed bug preventing recompute() from working in some cases.
* Replaced Matrix::cBind (deprecated) with cbind
CHANGES IN BayesFactor VERSION 0.9.12-2
CHANGES
* Added feature allowing fine-tuning of priors on a per-effect basis: see new argument
* Added feature allowing fine-tuning of priors on a per-effect basis: see new argument
rscaleEffects of lmBF, anovaBF, and generalTestBF
* Fixed bug that disallowed logical indexing of probability objects
* Fixed minor typos in documentation
......@@ -69,8 +79,8 @@ CHANGES
CHANGES
* Fixed bugs in model enumeration code
* Fixed bug leading to wrong computation of number of covariate when interactions between continuous variables were included
* Corrected typos/old information in the documentation
* Fixed a memory allocation bug that affected computing Bayes factors with lots of data
* Corrected typos/old information in the documentation
* Fixed a memory allocation bug that affected computing Bayes factors with lots of data
* Added meta-analytic Bayes factor for t tests (see meta.ttestBF)
* Fixed bug in ttestBF that yielded Bayes factor of NaN for very extreme posterior interval probabilities
* Fixed several bugs causing infinite integrals; generally improved integration
......@@ -110,7 +120,7 @@ CHANGES
* Fixed bug computing the Bayes factor of unbalanced one-way ANOVA with two levels - caused function to fail
* Fixed occasional problem where optimization for the importance sampler would fail, giving a numerically singular matrix
* Fixed problem where extremely rare large or small g values from the sampler would cause the Bayes factor to be NA (again, creating a singular numerically singular matrix). These very rare samples are now disregarded.
* Added global option to turn progress bars on or off; use options(BFprogress = TRUE) or options(BFprogress = FALSE)
* Added global option to turn progress bars on or off; use options(BFprogress = TRUE) or options(BFprogress = FALSE)
* Added MCMC chain thinning to nWayAOV - to use, pass "thin" argument to posterior() or lmBF()
* Added MCMC chain column filtering, useful for low memory systems. To use, pass "columnFilter" argument to posterior() or lmBF(). See the help for posterior() for more details.
* Added function generalTestBF(), which allows testing of restrictions on a full model in a manner similar to regressionBF() and anovaBF().
......@@ -120,7 +130,7 @@ CHANGES
CHANGES IN BayesFactor VERSION 0.9.3
CHANGES
* Restricted to R 3.0.0 (due to vignette compilation).
* Restricted to R 3.0.0 (due to vignette compilation).
CHANGES IN BayesFactor VERSION 0.9.2
......@@ -133,7 +143,7 @@ CHANGES
* When error is missing from the BayesFactor object, plot prints "?" next to the bar to indicate no error estimate is available
* Default prior scale setting changed for continuous covariates; scale now defaults to sqrt(2)/4, which corresponds to the ANOVA "medium" setting (and will give the same Bayes factor in special cases where they should)
* Default prior scale setting in one-sample t changed to 1/2 (it was erroneously changed to sqrt(2)/2). Two-sample t test default setting remains the same, at sqrt(2)/2
* Added new prior scale settings for random effects; default to "nuisance", which is the same as the old default (r=1)
* Added new prior scale settings for random effects; default to "nuisance", which is the same as the old default (r=1)
* New prior scale setting: "ultrawide"
* Fixed bug with BFManual() which caused it not to start if dynamic help had not been started yet
* When doing an Bayes factor analysis that requires sampling, the new default setting (method="auto") will automatically try to select the best sampler for you so that you get the most efficient samples.
......
......@@ -3,19 +3,21 @@
#'Functions to compute Bayes factor hypothesis tests for common research designs
#'and hypotheses.
#'
#'This package contains function to compute Bayes factors for a number of
#'research designs and hypotheses, including t tests, ANOVA, and linear
#'regression, and contingency tables.
#'This package contains function to compute Bayes factors for a number of
#'research designs and hypotheses, including t tests, ANOVA, and linear
#'regression, correlations, proportions, and contingency tables.
#'
#'\tabular{ll}{ Package: \tab BayesFactor\cr Type: \tab Package\cr Version: \tab
#'0.9.12\cr Date: \tab 2015-4-20\cr License: \tab GPL 2.0\cr LazyLoad: \tab
#'0.9.12-4\cr Date: \tab 2015-2-20\cr License: \tab GPL 2.0\cr LazyLoad: \tab
#'yes\cr } The following methods are currently implemented, with more to follow:
#'
#'general linear models (including linear mixed effects models): \code{\link{generalTestBF}}, \code{\link{lmBF}}
#'
#'linear regression: \code{\link{regressionBF}}, \code{\link{lmBF}},
#'linear regression: \code{\link{regressionBF}}, \code{\link{lmBF}},
#'\code{\link{linearReg.R2stat}};
#'
#'linear correlation: \code{\link{correlationBF}};
#'
#'t tests: \code{\link{ttestBF}}, \code{\link{ttest.tstat}};
#'
#'meta-analytic t tests: \code{\link{meta.ttestBF}}
......@@ -26,8 +28,8 @@
#'
#'single proportions: \code{\link{proportionBF}};
#'
#'Other useful functions: \code{\link{posterior}}, for sampling from posterior
#'distributions; \code{\link{recompute}}, for re-estimating a Bayes factor or
#'Other useful functions: \code{\link{posterior}}, for sampling from posterior
#'distributions; \code{\link{recompute}}, for re-estimating a Bayes factor or
#'posterior distribution; \code{\link{compare}}, to compare two model
#'posteriors; and \code{\link{plot.BFBayesFactor}}, for plotting Bayes factor
#'objects.
......@@ -36,21 +38,21 @@
#'@aliases BayesFactor-package BayesFactor
#'@docType package
#'@author Richard D. Morey and Jeffrey N. Rouder (with contributions from Tahira Jamil)
#'
#'
#' Maintainer: Richard D. Morey <richarddmorey@@gmail.com>
#'@references Liang, F. and Paulo, R. and Molina, G. and Clyde, M. A. and
#' Berger, J. O. (2008). Mixtures of g-priors for Bayesian Variable Selection.
#'@references Liang, F. and Paulo, R. and Molina, G. and Clyde, M. A. and
#' Berger, J. O. (2008). Mixtures of g-priors for Bayesian Variable Selection.
#' Journal of the American Statistical Association, 103, pp. 410-423
#'
#' Rouder, J. N., Speckman, P. L., Sun, D., Morey, R. D., \& Iverson, G.
#' (2009). Bayesian t-tests for accepting and rejecting the null hypothesis.
#'
#' Rouder, J. N., Speckman, P. L., Sun, D., Morey, R. D., \& Iverson, G.
#' (2009). Bayesian t-tests for accepting and rejecting the null hypothesis.
#' Psychonomic Bulletin & Review, 16, 225-237
#'
#' Rouder, J. N., Morey, R. D., Speckman, P. L., Province, J. M., (2012)
#'
#' Rouder, J. N., Morey, R. D., Speckman, P. L., Province, J. M., (2012)
#' Default Bayes Factors for ANOVA Designs. Journal of Mathematical Psychology.
#' 56. p. 356-374.
#'
#' Perception and Cognition Lab (University of Missouri): Bayes factor
#'
#' Perception and Cognition Lab (University of Missouri): Bayes factor
#' calculators. \url{http://pcl.missouri.edu/bayesfactor}
#'@keywords htest
#'@examples
......@@ -103,14 +105,14 @@ NULL
#'
#'Hraba and Grant (1970) describe a replication of Clark and Clark (1947) in which
#'black and white children from Lincoln, Nebraska were shown dolls that were either black
#'or white. They were then asked a series of questions, including "Give me the doll that is
#'or white. They were then asked a series of questions, including "Give me the doll that is
#'a nice doll." This data set contains the frequency of children giving the same-race or different race doll in
#'response to this question.
#'@name raceDolls
#'@docType data
#'@format A matrix with 2 rows and 2 columns. Rows give doll preference; colums give the
#'@format A matrix with 2 rows and 2 columns. Rows give doll preference; colums give the
#'race of the child.
#'@source Hraba, J. and Grant, G. (1970). Black is Beautiful: A reexamination of
#'@source Hraba, J. and Grant, G. (1970). Black is Beautiful: A reexamination of
#'racial preference and identification. Journal of Personality and Social Psychology, 16, 398-402.
#'
#'@keywords datasets
......
# This file was generated by Rcpp::compileAttributes
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
hFunc <- function(rho, n, r, hg_checkmod, hg_iter) {
.Call('_BayesFactor_hFunc', PACKAGE = 'BayesFactor', rho, n, r, hg_checkmod, hg_iter)
}
jeffreys_approx_corr <- function(rho, n, r) {
.Call('_BayesFactor_jeffreys_approx_corr', PACKAGE = 'BayesFactor', rho, n, r)
}
metropCorrRcpp_jeffreys <- function(r, n, a_prior, b_prior, approx, iterations, doInterval, intervalz, intervalCompl, nullModel, progress, callback, callbackInterval) {
.Call('_BayesFactor_metropCorrRcpp_jeffreys', PACKAGE = 'BayesFactor', r, n, a_prior, b_prior, approx, iterations, doInterval, intervalz, intervalCompl, nullModel, progress, callback, callbackInterval)
}
dinvgamma1_Rcpp <- function(x, a, b) {
.Call('BayesFactor_dinvgamma1_Rcpp', PACKAGE = 'BayesFactor', x, a, b)
.Call('_BayesFactor_dinvgamma1_Rcpp', PACKAGE = 'BayesFactor', x, a, b)
}
dinvgamma1_logx_Rcpp <- function(x, a, b) {
.Call('BayesFactor_dinvgamma1_logx_Rcpp', PACKAGE = 'BayesFactor', x, a, b)
.Call('_BayesFactor_dinvgamma1_logx_Rcpp', PACKAGE = 'BayesFactor', x, a, b)
}
ddinvgamma1_Rcpp <- function(x, a, b) {
.Call('BayesFactor_ddinvgamma1_Rcpp', PACKAGE = 'BayesFactor', x, a, b)
.Call('_BayesFactor_ddinvgamma1_Rcpp', PACKAGE = 'BayesFactor', x, a, b)
}
d2dinvgamma1_Rcpp <- function(x, a, b) {
.Call('BayesFactor_d2dinvgamma1_Rcpp', PACKAGE = 'BayesFactor', x, a, b)
.Call('_BayesFactor_d2dinvgamma1_Rcpp', PACKAGE = 'BayesFactor', x, a, b)
}
genhypergeo_series_pos <- function(U, L, z, tol, maxiter, check_mod, check_conds, polynomial) {
.Call('_BayesFactor_genhypergeo_series_pos', PACKAGE = 'BayesFactor', U, L, z, tol, maxiter, check_mod, check_conds, polynomial)
}
jzs_sampler <- function(iterations, y, X, rscale, gMap, incCont, importanceMu, importanceSig, progress, callback, callbackInterval, which) {
.Call('BayesFactor_jzs_sampler', PACKAGE = 'BayesFactor', iterations, y, X, rscale, gMap, incCont, importanceMu, importanceSig, progress, callback, callbackInterval, which)
.Call('_BayesFactor_jzs_sampler', PACKAGE = 'BayesFactor', iterations, y, X, rscale, gMap, incCont, importanceMu, importanceSig, progress, callback, callbackInterval, which)
}
jzs_log_marginal_posterior_logg <- function(q, sumSq, N, XtCnX0, CnytCnX0, rscale, gMap, gMapCounts, priorX, incCont, limit, limits, which) {
.Call('BayesFactor_jzs_log_marginal_posterior_logg', PACKAGE = 'BayesFactor', q, sumSq, N, XtCnX0, CnytCnX0, rscale, gMap, gMapCounts, priorX, incCont, limit, limits, which)
.Call('_BayesFactor_jzs_log_marginal_posterior_logg', PACKAGE = 'BayesFactor', q, sumSq, N, XtCnX0, CnytCnX0, rscale, gMap, gMapCounts, priorX, incCont, limit, limits, which)
}
jzs_Gibbs <- function(iterations, y, X, rscale, sig2start, gMap, gMapCounts, incCont, nullModel, ignoreCols, thin, progress, callback, callbackInterval) {
.Call('BayesFactor_jzs_Gibbs', PACKAGE = 'BayesFactor', iterations, y, X, rscale, sig2start, gMap, gMapCounts, incCont, nullModel, ignoreCols, thin, progress, callback, callbackInterval)
.Call('_BayesFactor_jzs_Gibbs', PACKAGE = 'BayesFactor', iterations, y, X, rscale, sig2start, gMap, gMapCounts, incCont, nullModel, ignoreCols, thin, progress, callback, callbackInterval)
}
GibbsLinearRegRcpp <- function(iterations, y, X, r, sig2start, nullModel, progress, callback, callbackInterval) {
.Call('BayesFactor_GibbsLinearRegRcpp', PACKAGE = 'BayesFactor', iterations, y, X, r, sig2start, nullModel, progress, callback, callbackInterval)
.Call('_BayesFactor_GibbsLinearRegRcpp', PACKAGE = 'BayesFactor', iterations, y, X, r, sig2start, nullModel, progress, callback, callbackInterval)
}
log_determinant_pos_def <- function(A) {
.Call('BayesFactor_log_determinant_pos_def', PACKAGE = 'BayesFactor', A)
.Call('_BayesFactor_log_determinant_pos_def', PACKAGE = 'BayesFactor', A)
}
logSummaryStats <- function(x) {
.Call('BayesFactor_logSummaryStats', PACKAGE = 'BayesFactor', x)
.Call('_BayesFactor_logSummaryStats', PACKAGE = 'BayesFactor', x)
}
log1pExp <- function(x) {
.Call('BayesFactor_log1pExp', PACKAGE = 'BayesFactor', x)
.Call('_BayesFactor_log1pExp', PACKAGE = 'BayesFactor', x)
}
logExpXplusExpY <- function(x, y) {
.Call('BayesFactor_logExpXplusExpY', PACKAGE = 'BayesFactor', x, y)
.Call('_BayesFactor_logExpXplusExpY', PACKAGE = 'BayesFactor', x, y)
}
logExpXminusExpY <- function(x, y) {
.Call('BayesFactor_logExpXminusExpY', PACKAGE = 'BayesFactor', x, y)
.Call('_BayesFactor_logExpXminusExpY', PACKAGE = 'BayesFactor', x, y)
}
metropMetaTRcpp <- function(t, n1, n2, twoSample, rscale, iterations, doInterval, interval, intervalCompl, nullModel, progress, callback, callbackInterval) {
.Call('BayesFactor_metropMetaTRcpp', PACKAGE = 'BayesFactor', t, n1, n2, twoSample, rscale, iterations, doInterval, interval, intervalCompl, nullModel, progress, callback, callbackInterval)
.Call('_BayesFactor_metropMetaTRcpp', PACKAGE = 'BayesFactor', t, n1, n2, twoSample, rscale, iterations, doInterval, interval, intervalCompl, nullModel, progress, callback, callbackInterval)
}
metropProportionRcpp <- function(y, n, p0, rscale, iterations, doInterval, interval, intervalCompl, nullModel, progress, callback, callbackInterval) {
.Call('BayesFactor_metropProportionRcpp', PACKAGE = 'BayesFactor', y, n, p0, rscale, iterations, doInterval, interval, intervalCompl, nullModel, progress, callback, callbackInterval)
.Call('_BayesFactor_metropProportionRcpp', PACKAGE = 'BayesFactor', y, n, p0, rscale, iterations, doInterval, interval, intervalCompl, nullModel, progress, callback, callbackInterval)
}
gibbsTwoSampleRcpp <- function(ybar, s2, N, rscale, iterations, doInterval, interval, intervalCompl, nullModel, progress, callback, callbackInterval) {
.Call('BayesFactor_gibbsTwoSampleRcpp', PACKAGE = 'BayesFactor', ybar, s2, N, rscale, iterations, doInterval, interval, intervalCompl, nullModel, progress, callback, callbackInterval)
.Call('_BayesFactor_gibbsTwoSampleRcpp', PACKAGE = 'BayesFactor', ybar, s2, N, rscale, iterations, doInterval, interval, intervalCompl, nullModel, progress, callback, callbackInterval)
}
gibbsOneSampleRcpp <- function(ybar, s2, N, rscale, iterations, doInterval, interval, intervalCompl, nullModel, progress, callback, callbackInterval) {
.Call('BayesFactor_gibbsOneSampleRcpp', PACKAGE = 'BayesFactor', ybar, s2, N, rscale, iterations, doInterval, interval, intervalCompl, nullModel, progress, callback, callbackInterval)
.Call('_BayesFactor_gibbsOneSampleRcpp', PACKAGE = 'BayesFactor', ybar, s2, N, rscale, iterations, doInterval, interval, intervalCompl, nullModel, progress, callback, callbackInterval)
}
# Register entry points for exported C++ functions
methods::setLoadAction(function(ns) {
.Call('_BayesFactor_RcppExport_registerCCallable', PACKAGE = 'BayesFactor')
})
......@@ -5,10 +5,10 @@
#' General S4 classes for representing models for comparison
#'
#' The \code{BFmodel} is a general S4 class for representing models for comparison. The more classes
#' \code{BFlinearModel}, \code{BFindepSample}, and \code{BFoneSample} inherit directly from \code{BFmodel}.
#'
#'
#' The \code{BFmodel} is a general S4 class for representing models for comparison. The more classes
#' \code{BFlinearModel}, \code{BFindepSample}, and \code{BFoneSample} inherit directly from \code{BFmodel}.
#'
#' \describe{
#' These model classes all have the following slots defined:
#' \item{type}{Model type}
......@@ -34,7 +34,11 @@ setClass("BFmodel", representation(
version = "character"
))
#' @name BFcontingencyTable-class
#' @name BFcorrelation-class
#' @rdname model-classes
setClass("BFcorrelation", contains = "BFmodel")
#' @name BFproportion-class
#' @rdname model-classes
setClass("BFproportion", contains = "BFmodel")
......@@ -59,11 +63,11 @@ setClass("BFmetat", contains = "BFmodel")
setClass("BFindepSample", contains = "BFlinearModel")
#' General S4 class for representing multiple Bayes factor model comparisons, all against the same model
#'
#'
#' The \code{BFBayesFactor} class is a general S4 class for representing models model comparison via Bayes factor.
#'
#'
#' \code{BFBayesFactor} objects can be inverted by taking the reciprocal and can
#' be divided by one another, provided both objects have the same denominator. In addition,
#' be divided by one another, provided both objects have the same denominator. In addition,
#' the \code{t} (transpose) method can be used to invert Bayes factor objects.
#' \describe{
......@@ -80,18 +84,18 @@ setClass("BFindepSample", contains = "BFlinearModel")
#' ## Compute some Bayes factors to demonstrate division and indexing
#' data(puzzles)
#' bfs <- anovaBF(RT ~ shape*color + ID, data = puzzles, whichRandom = "ID", progress=FALSE)
#'
#'
#' ## First and second models can be separated; they remain BFBayesFactor objects
#' b1 = bfs[1]
#' b2 = bfs[2]
#' b1
#'
#'
#' ## We can invert them, or divide them to obtain new model comparisons
#' 1/b1
#' b1 / b2
#'
#'
#' ## Use transpose to create a BFBayesFactorList
#' t(bfs)
#' t(bfs)
setClass("BFBayesFactor", representation(
numerator = "list",
denominator = "BFmodel",
......@@ -100,19 +104,19 @@ setClass("BFBayesFactor", representation(
version = "character"
))
#' General S4 class for representing a collection of Bayes factor model
#' General S4 class for representing a collection of Bayes factor model
#' comprisons, each against a different denominator
#'
#' The \code{BFBayesFactorList} class is a general S4 class for representing
#'
#' The \code{BFBayesFactorList} class is a general S4 class for representing
#' models model comparison via Bayes factor. See the examples for demonstrations
#' of BFBayesFactorList methods.
#'
#'
#' \describe{ \code{BFBayesFactorList} objects inherit from lists, and contain a
#' single slot:
#'
#'
#' \item{version}{character string giving the version and revision number of the
#' package that the model was created in}
#'
#'
#' Each element of the list contains a single
#' \code{"\link[=BFBayesFactor-class]{BFBayesFactor}"} object. Each element of
#' the list must have the same numerators, in the same order, as all the others.
......@@ -123,18 +127,18 @@ setClass("BFBayesFactor", representation(
#' ## Compute some Bayes factors to demonstrate Bayes factor lists
#' data(puzzles)
#' bfs <- anovaBF(RT ~ shape*color + ID, data = puzzles, whichRandom = "ID", progress=FALSE)
#'
#'
#' ## Create a matrix of Bayes factors
#' bfList <- bfs / bfs
#' bfList
#'
#'
#' ## Use indexing to select parts of the 'matrix'
#' bfList[1,]
#' bfList[,1]
#'
#'
#' ## We can use the t (transpose) function as well, to get back a BFBayesFactor
#' t(bfList[2,])
#'
#'
#' ## Or transpose the whole matrix
#' t(bfList)
setClass("BFBayesFactorList", contains = "list", representation(version="character"))
......@@ -149,11 +153,11 @@ setClass("BFmcmc", contains = "mcmc", representation(model="BFmodel",data = "dat
setClassUnion("BFOrNULL", members = c("BFBayesFactor", "NULL"))
#' General S4 class for representing multiple odds model comparisons, all against the same model
#'
#'
#' The \code{BFodds} class is a general S4 class for representing models model comparison via prior or posterior odds.
#'
#'
#' \code{BFodds} objects can be inverted by taking the reciprocal and can
#' be divided by one another, provided both objects have the same denominator. In addition,
#' be divided by one another, provided both objects have the same denominator. In addition,
#' the \code{t} (transpose) method can be used to invert odds objects.
#' \describe{
......@@ -175,9 +179,9 @@ setClass("BFodds", representation(
))
#' General S4 class for representing multiple model probability comparisons
#'
#'
#' The \code{BFprobability} class is a general S4 class for representing models model comparison via prior or posterior probabilities.
#'
#'
#' \describe{
#' The \code{BFprobability} class has the following slots defined:
#' \item{odds}{A BFodds object containing the models from which to compute the probabilities}
......
......@@ -8,12 +8,12 @@ setGeneric("%same%", function(x, y) standardGeneric("%same%"))
#' Find a model term in a vector of model terms
#' @param x the terms to be matched
#' @param table the terms to be matched against
#' @return A logical vector of the same length as x, indicating if a
#' @return A logical vector of the same length as x, indicating if a
#' match was located for each element of x.
setGeneric("%termin%", function(x, table) standardGeneric("%termin%"))
#' Compare two models, with respect to some data
#'
#'
#' This method is used primarily in the backend, and will only rarely be called
#' by the end user. But see the examples below for a demonstration.
#' @param numerator first model
......@@ -25,7 +25,7 @@ setGeneric("%termin%", function(x, table) standardGeneric("%termin%"))
#' @export
#' @docType methods
#' @rdname compare-methods
#' @aliases compare,BFoneSample,missing,data.frame-method
#' @aliases compare,BFoneSample,missing,data.frame-method
#' compare,BFlinearModel,BFlinearModel,data.frame-method
#' compare,BFindepSample,missing,data.frame-method
#' compare,BFlinearModel,missing,data.frame-method
......@@ -33,39 +33,40 @@ setGeneric("%termin%", function(x, table) standardGeneric("%termin%"))
#' compare,BFproportion,missing,data.frame-method
#' compare,BFcontingencyTable,BFcontingencyTable,data.frame-method
#' compare,BFcontingencyTable,missing,data.frame-method
#' compare,BFcorrelation,missing,data.frame-method
#' compare,BFmcmc,BFmcmc,ANY-method
#' compare,BFmcmc,missing,ANY-method
#' @examples
#' ## Sample from the posteriors for two models
#' data(puzzles)
#'
#' ## Main effects model; result is a BFmcmc object, inheriting
#'
#' ## Main effects model; result is a BFmcmc object, inheriting
#' ## mcmc from the coda package
#' mod1 = lmBF(RT ~ shape + color + ID, data = puzzles, whichRandom = "ID",
#' mod1 = lmBF(RT ~ shape + color + ID, data = puzzles, whichRandom = "ID",
#' progress = FALSE, posterior = TRUE, iterations = 1000)
#'
#'
#' plot(mod1)
#'
#'
#' ## Full model
#' mod2 = lmBF(RT ~ shape*color + ID, data = puzzles, whichRandom = "ID",
#' mod2 = lmBF(RT ~ shape*color + ID, data = puzzles, whichRandom = "ID",
#' progress = FALSE, posterior = TRUE, iterations = 1000)
#'
#'
#' ## Each BFmcmc object contains the model used to generate it, so we
#' ## can compare them (data is not needed, it is contained in the objects):
#'
#' compare(mod1, mod2)
#'
#' compare(mod1, mod2)
setGeneric("compare", function(numerator, denominator, data, ...) standardGeneric("compare"))
#' Recompute a Bayes factor computation or MCMC object.
#'
#' Take an object and redo the computation (useful for sampling). In cases where sampling is
#' Recompute a Bayes factor computation or MCMC object.
#'
#' Take an object and redo the computation (useful for sampling). In cases where sampling is
#' used to compute the Bayes factor, the estimate of the precision of new samples will be added
#' to the estimate precision of the old sample will be added to produce a new estimate of the
#' to the estimate precision of the old sample will be added to produce a new estimate of the
#' precision.
#' @param x object to recompute
#' @param progress report progress of the computation?
#' @param multicore Use multicore, if available
#' @param callback callback function for third-party interfaces
#' @param callback callback function for third-party interfaces
#' @param ... arguments passed to and from related methods
#' @return Returns an object of the same type, after repeating the sampling (perhaps with more iterations)
#' @export
......@@ -74,41 +75,41 @@ setGeneric("compare", function(numerator, denominator, data, ...) standardGeneri
#' @examples
#' ## Sample from the posteriors for two models
#' data(puzzles)
#'
#' ## Main effects model; result is a BFmcmc object, inheriting
#'
#' ## Main effects model; result is a BFmcmc object, inheriting
#' ## mcmc from the coda package
#' bf = lmBF(RT ~ shape + color + ID, data = puzzles, whichRandom = "ID",
#' bf = lmBF(RT ~ shape + color + ID, data = puzzles, whichRandom = "ID",
#' progress = FALSE)
#'
#' ## recompute Bayes factor object
#'
#' ## recompute Bayes factor object
#' recompute(bf, iterations = 1000, progress = FALSE)
#'
#'
#' ## Sample from posterior distribution of model above, and recompute:
#' chains = posterior(bf, iterations = 1000, progress = FALSE)
#' newChains = recompute(chains, iterations = 1000, progress=FALSE)
setGeneric("recompute", function(x, progress=options()$BFprogress, multicore = FALSE, callback = function(...) as.integer(0), ...) standardGeneric("recompute"))
#' newChains = recompute(chains, iterations = 1000, progress=FALSE)
setGeneric("recompute", function(x, progress=getOption('BFprogress', interactive()), multicore = FALSE, callback = function(...) as.integer(0), ...) standardGeneric("recompute"))
#' Sample from the posterior distribution of one of several models.
#'
#' This function samples from the posterior distribution of a \code{BFmodel},
#' which can be obtained from a \code{BFBayesFactor} object. If there is more
#' than one numerator in the \code{BFBayesFactor} object, the \code{index}
#'
#' This function samples from the posterior distribution of a \code{BFmodel},
#' which can be obtained from a \code{BFBayesFactor} object. If there is more
#' than one numerator in the \code{BFBayesFactor} object, the \code{index}
#' argument can be passed to select one numerator.
#'
#' The data argument is used internally, and will y not be needed by
#'
#' The data argument is used internally, and will y not be needed by
#' end-users.
#'
#' Note that if there are fixed effects in the model, the reduced
#' parameterzation used internally (see help for \code{\link{anovaBF}}) is
#' unreduced. For a factor with two levels, the chain will contain two effect
#'
#' Note that if there are fixed effects in the model, the reduced
#' parameterzation used internally (see help for \code{\link{anovaBF}}) is
#' unreduced. For a factor with two levels, the chain will contain two effect
#' estimates that sum to 0.
#'
#' Two useful arguments that can be passed to related methods are \code{thin}
#' and \code{columnFilter}, currently implemented for methods using
#' \code{nWayAOV} (models with more than one categorical covariate, or a mix of
#' categorical and continuous covariates). \code{thin}, an integer, will keep
#' only every \code{thin} iterations. The default is \code{thin=1}, which keeps
#' all iterations. Argument \code{columnFilter} is either \code{NULL} (for no
#'
#' Two useful arguments that can be passed to related methods are \code{thin}
#' and \code{columnFilter}, currently implemented for methods using
#' \code{nWayAOV} (models with more than one categorical covariate, or a mix of
#' categorical and continuous covariates). \code{thin}, an integer, will keep
#' only every \code{thin} iterations. The default is \code{thin=1}, which keeps
#' all iterations. Argument \code{columnFilter} is either \code{NULL} (for no
#' filtering) or a character vector of extended regular expressions (see
#' \link{regex} help for details). Any column from an effect that matches one of
#' the filters will not be saved.
......@@ -117,7 +118,7 @@ setGeneric("recompute", function(x, progress=options()$BFprogress, multicore = F
#' @param data the data to be conditioned on
#' @param iterations the number of iterations to sample
#' @param ... arguments passed to and from related methods
#' @return Returns an object containing samples from the posterior distribution
#' @return Returns an object containing samples from the posterior distribution
#' of the specified model
#' @export
#' @docType methods
......@@ -125,15 +126,15 @@ setGeneric("recompute", function(x, progress=options()$BFprogress, multicore = F
#' @examples
#' ## Sample from the posteriors for two models
#' data(sleep)
#'
#' bf = lmBF(extra ~ group + ID, data = sleep, whichRandom="ID", progress=FALSE)
#'
#'
#' bf = lmBF(extra ~ group + ID, data = sleep, whichRandom="ID", progress=FALSE)
#'
#' ## sample from the posterior of the numerator model
#' ## data argument not needed - it is included in the Bayes factor object
#' ## data argument not needed - it is included in the Bayes factor object
#' chains = posterior(bf, iterations = 1000, progress = FALSE)
#'
#'
#' plot(chains)
#'
#'
#' ## demonstrate column filtering by filtering out participant effects
#' data(puzzles)
#' bf = lmBF(RT ~ shape + color + shape:color + ID, data=puzzles)
......@@ -152,10 +153,10 @@ setGeneric("posterior", function(model, index, data, iterations, ...) standardGe
#' @examples
#' ## Sample from the posteriors for two models
#' data(puzzles)
#'
#' bf = lmBF(RT ~ shape*color + ID, data = puzzles, whichRandom="ID", progress=FALSE)
#'
#' extractBF(bf)
#'
#' bf = lmBF(RT ~ shape*color + ID, data = puzzles, whichRandom="ID", progress=FALSE)
#'
#' extractBF(bf)
setGeneric("extractBF", function(x, logbf=FALSE, onlybf=FALSE) standardGeneric("extractBF"))
#' Extract the odds from an object
......
......@@ -12,8 +12,9 @@ enumerateAnovaModels = function(fmla, whichModels, data){
trms <- attr(terms(fmla, data = data), "term.labels")
ntrms <- length(trms)
dv = stringFromFormula(fmla[[2]])
dv = composeTerm(dv)
if(ntrms == 1 ) whichModels = "all"
if(whichModels=="top"){
lst = combn2( trms, ntrms - 1 )
}else if(whichModels=='bottom'){
......@@ -37,24 +38,26 @@ enumerateAnovaModels = function(fmla, whichModels, data){
createFixedAnovaModel <- function(dataTypes, formula){
fixedFactors <- names(dataTypes[dataTypes=="fixed"])
fixedPart <- paste(fixedFactors,collapse="*")
fixedPart <- paste(composeTerms(fixedFactors),collapse="*")
# get LHS of formula
dv = stringFromFormula(formula[[2]])
dv = composeTerm(dv)
formula(paste(dv, "~", fixedPart, collapse=""))
}
addRandomModelPart <- function(formula, dataTypes, null = FALSE){