Learn R Programming

analogue (version 0.17-7)

bayesF: Bayes factors

Description

Calculates Bayes factors or likelihood ratios of analogue and no-analogue results.

Usage

bayesF(x, prior = rep(0.5, 2))

# S3 method for bayesF plot(x, group = "all", xlab = NULL, ylab = "Pr (A+ | d)", col = "red", abline.col = "lightgrey", abline.lty = "dashed", ...)

Value

For plot.bayesF a plot on the currently active device.

For bayesF, a list containing the results of computing Bayes factors for each group in x. Each component of this list is itself a list with the following components:

bayesF, posterior.odds, posterior.probs, prior.prob

Bayes factors, posterior odds and probabilities and prior probabilities of true analogue and true non-analogue events. Each components is a list with two components; pos (for true analogue events) and neg (for true non-analogue events). The components of prior.prob are vectors of length 1, whilst components of the other lists are numeric vectors.

roc.points

numeric; the points at which the ROC curve was evaluated.

optimal

numeric; the optimal dissimilarity as assessed by the ROC curve.

max.roc

numeric; the position along the ROC curve at which the slope of the ROC curve is maximal. This is the index of this point on the curve, and can be used to extract the element of bayesF, posterior.odds and posterior.probs for the optimal dissimilarity.

Arguments

x

for bayesF an object of class roc. For the plot method, an object of class bayesF, usually the result of a call to bayesF.

prior

numeric; the prior probabilities of analogue and no-analogue, provided as a vector of length 2 whose elements sum to 1. If not provided, the function will use the relative occurences of analogue and no analogue situations used to evaluate the ROC curve.

group

character vector of length 1 giving the name of the group to plot, or "all" to plot all groups in x.

xlab,ylab

the x- and y-axis labels for the plot.

col

colour of the line used to draw the posterior probability.

abline.col

colour of the vertical line drawn to indicate the optimal dissimilarity determined from the ROC curve.

abline.lty

Line type for indicator of optimal ROC dissimilarity threshold. See par for the allowed line types.

...

other plot arguments passed to plotting functions. Currently ignored.

Author

Gavin L. Simpson

Details

LR(+), is the likelihood ratio of a positive test result, that the value of d assigns the sample to the group it belongs to. LR(-) is the likelihood ratio of a negative test result, that the value of d assigns the sample to the wrong group.

LR(+) is defined as \(LR(+) = TPF / FPF\) (or sensitivity / (1 - specificity)), and LR(-) is defined as \(LR(-) = FPF / TNF\) (or (1 - sensitivity) / specificity), in Henderson (1993).

The posterior probability of analogue given a dissimilarity is the LR(+) likelihood ratio values multiplied by the prior odds of analogue, for given values of the dissimilarity, and is then converted to a probability.

The plotting function currently only draws the posterior probability of analogue based on the Bayes factor or likelihood ratio of a positive event (analogue).

References

Brown, C.D., and Davis, H.T. (2006) Receiver operating characteristics curves and related decision measures: A tutorial. Chemometrics and Intelligent Laboratory Systems 80, 24--38.

Gavin, D.G., Oswald, W.W., Wahl, E.R. and Williams, J.W. (2003) A statistical approach to evaluating distance metrics and analog assignments for pollen records. Quaternary Research 60, 356--367.

Henderson, A.R. (1993) Assessing test accuracy and its clinical consequences: a primer for receiver operating characteristic curve analysis. Annals of Clinical Biochemistry 30, 834--846.

See Also

roc and plot.bayesF.

Examples

Run this code
## load the example data
data(swapdiat, swappH, rlgh)

## merge training and test set on columns
dat <- join(swapdiat, rlgh, verbose = TRUE)

## extract the merged data sets and convert to proportions
swapdiat <- dat[[1]] / 100
rlgh <- dat[[2]] / 100

## fit an analogue matching (AM) model using the squared chord distance
## measure - need to keep the training set dissimilarities
swap.ana <- analog(swapdiat, rlgh, method = "SQchord",
                   keep.train = TRUE)

## fit the ROC curve to the SWAP diatom data using the AM results
## Generate a grouping for the SWAP lakes
METHOD <- if (getRversion() < "3.1.0") {"ward"} else {"ward.D"}
clust <- hclust(as.dist(swap.ana$train), method = METHOD)
grps <- cutree(clust, 12)

## fit the ROC curve
swap.roc <- roc(swap.ana, groups = grps)
swap.roc

## calculate the Bayes factors of analogue and no-analogue
## (uses observed probabilities of analogue/no-analogue
swap.bayes <- bayesF(swap.roc)
swap.bayes

## plot the probability of analogue
plot(swap.bayes)

if (FALSE) {
## calculate the Bayes factors of analogue and no-analogue
## with prior probabilities c(0.5, 0.05)
swap.bayes2 <- bayesF(swap.roc, prior = c(0.5, 0.05))
swap.bayes

## plot the probability of analogue
plot(swap.bayes2)
}

Run the code above in your browser using DataLab