cpf: Calculate conditional probabilities

Description Usage Arguments Details Value Author(s) References Examples

View source: R/cpf.R

Description

Calculate conditional probabilities of a matrix from the joint and marginal probabilities.

Usage

1
cpf(pxy, margin)

Arguments

pxy

A matrix, array, or data frame of numeric values representing the joint distribution across all interactions of X and Y (must sum to 1) in the form:

p(x,y) X
0.06 0.06 0.06 ...
Y 0.14 0.14 0.14 ...
0.12 0.12 0.14 ...
... ... ... ...
margin

a character argument that can be either "p(row|col)" or "p(col|row)" indicating if the desired conditional probability is p(row|col) or p(col|row). In these example data p(row|col) corresponds to p(to|from).

Details

cpf calculates the conditional probabilities p(Y|X) across all discrete interactions of the two variables. Let PXY be a matrix of joint probabilities with rows j and columns i and let PX_i represent a vector of marginal probabilities. The probability of event Y under the condition that X has already occurred is found by:

PXX_i,j / PX_i = PX_Yi,j

wherever PX_i is greater than zero.

Value

Returns a matrix of conditional probabilities with the same number of rows and columns as input matrix PXY and has the form:

p(y|x) X
0.19 0.19 0.18 ...
Y 0.44 0.44 0.41 ...
0.38 0.38 0.41 ...
... ... ... ...

Author(s)

Bjorn J. Brooks, Lars Y. Pomara, Danny C. Lee

References

PAPER TITLE.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data(transitions)                 # Load example data
b <- brkpts(transitions$phenofr,  # 4 probabilistically
            4)                    #  equivalent breakpoints
m <- xt(transitions,              # Make transition matrix
        fr.col=2, to.col=3,
        cnt.col=4, brk=b)
pxy <- jpmf(m)                    # Joint distribution
r_c <- cpf(pxy,                   # Conditional probabilites
           margin='p(row|col)')   #  (row | col)
colSums(r_c)                      # Check that each column sums to 1

bjornbrooks/landat documentation built on May 17, 2019, 7:32 p.m.