marg {sparta}R Documentation

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 class 'sparta'
marg(x, y, flow = "sum")

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

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"

Value

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

Examples


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"))

[Package sparta version 0.8.4 Index]