testHypothesis: Perform Hypothesis Test from Cell Means

View source: R/Main.R

testHypothesisR Documentation

Perform Hypothesis Test from Cell Means

Description

This is the primary function in this package. It takes two matrices of prior and posterior cell means, a data.frame containing information about the factor levels in the design, and what effect you want to test. It computes a Bayes factor related to the hypothesis that the effect is present in the cell means.

Usage

testHypothesis(priorCMs, postCMs, factors, testedFactors,
  dmFactors = testedFactors, contrastType = NULL,
  testFunction = testFunction_SDDR, usedFactorLevels = NULL)

Arguments

priorCMs

Numeric matrix. Cell means sampled from the priors. The columns must correspond to the rows of factors but do not need to be named.

postCMs

Numeric matrix. Cell means sampled from the posterior distribution. The columns must correspond to the rows of factors but do not need to be named.

factors

A data.frame containing information about the experimental design. Each column is a factor of the design. Each row contains the levels of the factors that define a cell of the design. No additional columns may be included in factors. Factor names and factor levels must not include period (".") or colon (":").

testedFactors

Character vector. The factors for which to perform the hypothesis test as a vector of factor names. A single factor name results in the test of the main effect of the factor. Multiple factor names result in the test of the interaction of all of those factors. You may provide either a vector with multiple elements, e.g. c('A', 'B'), or a vector with one element where factor names are separated by colon, e.g. 'A:B'.

dmFactors

Character vector or formula. The factors to use to construct the design matrix. Like testedFactors, you may separate factor names with colon. For a fully-crossed (balanced) design using orthogonal contrasts, this can always be equal to testedFactors (the default). For non-fully-crossed designs, you may sometimes want to create a design matrix using a set of factors, but perform a hypothesis test with only some of those factors (testedFactors must be a subset of dmFactors). This constraint is not tested for if a formula is provided. You may supply a formula like that taken by model.matrix which will be used to create the design matrix. The formula should be like ~ A * B, where A and B are factor names with nothing on the left hand side of the "~".

contrastType

Character, function, or list. The contrast to use to create the design matrix. If character, can be any of the function names on the documentation page for contr.sum. For a non-fully-crossed (unbalanced) design, you should use either "contr.treatment" or "contr.SAS". For a balanced design, you can use anything, but psychologists are most used to "contr.sum", which uses sums-to-zero constraints. If a function, it should produce contrasts. If a list, it should be able to be passed directly to the contrasts.arg argument of stats::model.matrix.

testFunction

A function that takes two matrices of prior and posterior effect parameters, in that order. For example, see testFunction_SDDR. You can probably leave this at the default value.

usedFactorLevels

A data.frame with a column for each of the factors in testedFactors. Each row specifies factor levels that should be included in the test. This allows you to do things like pairwise comparisons of specific factor levels. The factor levels that are not in usedFactorLevels are dropped after calculation of the effect parameters, which means that the kept effect parameters are calculated in the context of any effects that are specified by dmFactors.

Value

The return value depends on the choice of testFunction. See testFunction_SDDR for an example.

See Also

See testHypotheses for performing multiple tests at once. See groupEffectParameters for pairwise comparisons of effect parameters.


hardmanko/CMBBHT documentation built on June 9, 2022, 12:44 a.m.