1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
# https://stat.ethz.ch/pipermail/r-devel/2010-May/057506.html
## for 'i' in x[i] or A[i,] : (numeric = {double, integer})
# setClassUnion("index", members = c("numeric", "logical", "character"))
#' 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}.
#'
#' \describe{
#' These model classes all have the following slots defined:
#' \item{type}{Model type}
#' \item{identifier}{a list uniquely identifying the model from other models of the same type}
#' \item{prior}{list giving appropriate prior settings for the model}
#' \item{dataTypes}{a character vector whose names are possible columns in the data; elements specify the corresponding data type, currently one of c("fixed","random","continuous")}
#' \item{shortName}{a short, readable identifying string}
#' \item{longName}{a longer, readable identifying string}
#' \item{analysis}{object storing information about a previous analysis of this model}
#' \item{version}{character string giving the version and revision number of the package that the model was created in}
#' }
#' @name BFmodel-class
#' @rdname model-classes
#' @export
setClass("BFmodel", representation(
type = "character",
identifier = "list",
prior = "list",
dataTypes = "character",
shortName = "character",
longName = "character",
analysis = "list",
version = "character"
))
#' @name BFcorrelation-class
#' @rdname model-classes
setClass("BFcorrelation", contains = "BFmodel")
#' @name BFproportion-class
#' @rdname model-classes
setClass("BFproportion", contains = "BFmodel")
#' @name BFcontingencyTable-class
#' @rdname model-classes
setClass("BFcontingencyTable", contains = "BFmodel")
#' @name BFlinearModel-class
#' @rdname model-classes
setClass("BFlinearModel", contains = "BFmodel")
#' @name BFoneSample-class
#' @rdname model-classes
setClass("BFoneSample", contains = "BFlinearModel")
#' @name BFoneSample-class
#' @rdname model-classes
setClass("BFmetat", contains = "BFmodel")
#' @name BFindepSample-class
#' @rdname model-classes
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,
#' the \code{t} (transpose) method can be used to invert Bayes factor objects.
#' \describe{
#' The \code{BFBayesFactor} class has the following slots defined:
#' \item{numerator}{a list of models all inheriting \code{BFmodel}, each providing a single denominator}
#' \item{denominator}{a single \code{BFmodel} object serving as the denominator for all model comparisons}
#' \item{bayesFactor}{a data frame containing information about the comparison between each numerator and the denominator}
#' \item{data}{a data frame containing the data used for the comparison}
#' \item{version}{character string giving the version and revision number of the package that the model was created in}
#' }
#' @name BFBayesFactor-class
#' @export
#' @examples
#' ## 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)
setClass("BFBayesFactor", representation(
numerator = "list",
denominator = "BFmodel",
bayesFactor = "data.frame",
data = "data.frame",
version = "character"
))
#' 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
#' 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.
#' The list object is displayed as a matrix of Bayes factors. }
#' @name BFBayesFactorList-class
#' @export
#' @examples
#' ## 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"))
#' @name BFBayesFactorTop-class
#' @rdname BFBayesFactor-class
setClass("BFBayesFactorTop", contains = "BFBayesFactor")
setOldClass("mcmc")
setClass("BFmcmc", contains = "mcmc", representation(model="BFmodel",data = "data.frame"))
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,
#' the \code{t} (transpose) method can be used to invert odds objects.
#' \describe{
#' The \code{BFodds} class has the following slots defined:
#' \item{numerator}{a list of models all inheriting \code{BFmodel}, each providing a single numerator}
#' \item{denominator}{a single \code{BFmodel} object serving as the denominator for all model comparisons}
#' \item{logodds}{a data frame containing information about the (log) prior odds between each numerator and the denominator}
#' \item{bayesFactor}{a \code{BFBayesFactor} object (possibly) containing the evidence from the data.}
#' \item{version}{character string giving the version and revision number of the package that the model was created in}
#' }
#' @name BFodds-class
#' @export
setClass("BFodds", representation(
numerator = "list",
denominator = "BFmodel",
logodds = "data.frame",
bayesFactor = "BFOrNULL",
version = "character"
))
#' 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}
#' \item{normalize}{the sum of the probabilities of all models (will often be 1.0)}
#' \item{version}{character string giving the version and revision number of the package that the model was created in}
#' }
#' @name BFprobability-class
#' @export
setClass("BFprobability", representation(
odds = "BFodds",
normalize = "numeric",
version = "character"
))
|