posterior: Posterior distribution on Bayesian networks.

Description Usage Arguments Value See Also Examples

View source: R/post.R

Description

Use one of a number of methods to get the posterior distribution.

Usage

1
2
3
4
5
6
7
  posterior(data, method = "mc3",
    prior = priorUniform(initial),
    logScoreFUN = logScoreMultDirFUN(),
    logScoreParameters = list(hyperparameters = "bdeu"),
    constraint = NULL, maxNumberParents = NULL,
    nSamples = 50000, time = F, nBurnin = 10000,
    initial = empty(ncol(data), "bn"), verbose = T)

Arguments

data

The data.

method

One of "exact", "mc3", "gibbs", "mj-mcmc". "mh-mcmc" is a synonym of "mc3".

prior

A list of functions of the same length as initial that returns the local prior score of the corresponding node, given a numeric vector of parents. The default value NULL uses an improper uniform prior.

logScoreFUN

A list of four elements:

offline

A function that computes the logScore of a Bayesian Network

online

A function that incrementally computes the logScore of a Bayesian Network

local

A function that computes the local logScore of a Bayesian Network

prepare

A function that prepares the data, and any further pre-computation required by the logScore functions.

For Multinomial-Dirichlet models, logScoreMultDirFUN returns the appropriate list; for Normal models with Zellner g-priors, logScoreNormalFUN returns the appropriate list.

logScoreParameters

A list of parameters that are passed to logScoreFUN.

constraint

A matrix of dimension ncol(data) x ncol(data) giving constraints to the sample space. The (i, j) element is 1 if the edge i -> j is required -1 if the edge i -> is excluded. 0 if the edge i -> j is not constrained. The diagonal of constraint must be all 0.

maxNumberParents

Integer of length 1. The maximum number of parents of any node. Default value is left to the MCMC sampler when mcmcposterior is user, or exactposterior for exact computation.

nSamples

The number of samples to be draw. Set this to FALSE if using the time argument. (Only applies to MCMC.)

time

The number of seconds to spend drawing samples. Set this to FALSE if using the nSamples argument. (Only applies to MCMC.)

nBurnin

The number of samples to discard from the beginning of the sample. (Only applies to MCMC.)

initial

An object of class 'bn'. The starting value of the MCMC. (Only applies to MCMC.)

verbose

A logical. Should a progress bar be displayed?

Value

Either a bnpost or a bnpostmcmc object.

See Also

For more control, use the MCMC sampler directly, e.g. BNSampler. Example priors priorGraph, priorUniform.

Examples

1
2
3
4
5
6
7
8
x1 <- factor(c("a", "a", "g", "c", "c", "a", "g", "a", "a"))
x2 <- factor(c(2, 2, 4, 3, 1, 4, 4, 4, 1))
x3 <- factor(c(FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE))
x <- data.frame(x1 = x1, x2 = x2, x3 = x3)

set.seed(1234)
mcmc <- posterior(data = x, "mc3", nSamples = 500, nBurnin = 100)
ep(mcmc)

rjbgoudie/structmcmc documentation built on Nov. 3, 2020, 3:41 a.m.