Learn R Programming

sparta (version 1.0.1)

marg: Marginalization of sparse tables

Description

Marginalize a sparse table given a vector of variables to marginalize out

Usage

marg(x, y, flow = "sum")

# S3 method for sparta marg(x, y, flow = "sum")

# S3 method for numeric marg(x, y, flow = "sum")

Value

A sparta object (or scalar if all variables are summed out)

Arguments

x

sparta object or a numeric. If numeric, the value is just returned.

y

character vector of the variables to marginalize out

flow

either "sum" or "max"

Examples

Run this code

x <- array(
 c(1,0,0,2,3,4,0,0),
 dim = c(2,2,2),
 dimnames = list(
   a = c("a1", "a2"),
   b = c("b1", "b2"),
   c = c("c1", "c2")
 )
)

sx <- as_sparta(x)
marg(sx, c("c"))

su <- sparta_unity_struct(dim_names(sx), rank = 3.14)
marg(su, c("a", "b"))

Run the code above in your browser using DataLab