readHistory: Reads a file of histories of marginal distributions.

readHistoryR Documentation

Reads a file of histories of marginal distributions.

Description

In running a typical Bayes net engine, as each piece of evidence comes in, updated marginal distributions for several variables are output. This function reads a such a log, expressed as a data frame, and creates a data structure suitable for doing weight of evidence analyses. The probabilities are in the pvec (parseProbVec) format.

Usage

readHistory(histdat, obscol = "Item", valcol = "Result",
  probcol="Probability")

Arguments

histdat

A data frame which has columns corresponding to obscol, valcol and probcol

.

obscol

Name of the column with the name of the observable at each time point.

valcol

Name of the column with the value of the observable at each time point.

probcol

Name of the column with the probabity vectors.

Details

The assumption is that the histdat data frame contains a history of measurements on a latent variable. The probcol column should contain a probability vector of the form: [High:0.527,Medium:0.447,Low:0.025]. This function parses this column (see parseProbVec) and builds a matrix with columns corresponding to the states of the latent variable.

The rows are given names of the form, <obscol>=<valcol>, where <obscol> and <valcol> are the values in the respective columns.

Value

A matrix whose column names are taken from the probability vectors and row names are taken from the obscol and valcol fields.

Note

The previous version (a) directly read the CSV file, and (b) had the names of the columns hard coded. This version will break any code that relied on the old version. However, it is hopefully more generally useful.

Author(s)

Russell Almond

References

http://research.ets.org/~ralmond/StatShop/dataFormats.html

See Also

parseProbVec, woeHist

Examples

  testFiles <- system.file("testFiles",package="CPTtools")
  allcorrect <- readHistory(read.csv(file.path(testFiles,
     "CorrectSequence.csv"),as.is=TRUE),
     probcol="Margin.sequences.")
  woeHist(allcorrect,"High",c("Medium","Low"))
  allincorrect <- readHistory(read.csv(file.path(testFiles, 
    "InCorrectSequence.csv"),as.is=TRUE),
     probcol="Margin.sequences.")

ralmond/CPTtools documentation built on Dec. 27, 2024, 7:15 a.m.