marginalize: Marginal Distributions

Description Usage Arguments Details Value Examples

View source: R/merging.R

Description

Obtain a marginal distribution of a random variable in an rvtable.

Usage

1
marginalize(x, margin, density.args, sample.args)

Arguments

x

an rvtable.

margin

variable(s) in rvtable to marginalize over.

density.args

optional arguments passed to density. If supplied, overrides the density.args attribute of x.

sample.args

optional arguments used when sampling. If supplied, overrides the sample.args attribute of x.

Details

Grouping variables are ignored when marginalizing the distribution of a random variable over explicit categorical variables. Unlike merge_rvtable, marginalize will not merge ungrouped ID variables. It will only marginalize over the ID variables specified in margin. It will also account for unequal weighting of an ID variable's levels, taken from the weights attribute of an rvtable, whereas merge_rvtable is a simpler function that ignores weights.

Value

an rvtable.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Not run: 
library(dplyr)
x <- data.frame(
  id1=rep(LETTERS[1:5], each=4),
  id2=factor(c("low", "high")),
  id3=rep(1:2, each=2),
  Val=rep(1:10, each=20), Prob=rep(sqrt(1:10), each=20)) %>% rvtable
marginalize(x, c("id1", "id2"))

get_levels(x, "id1")
get_weights(x, "id1")
marginalize(x, "id1")
wts <- data.frame(levels=LETTERS[1:5], weights=c(1, 1.5, 2, 4, 1))
x <- set_weights(x, "id1", wts)
get_weights(x, "id1")
marginalize(x, "id1")

## End(Not run)

leonawicz/rvtable documentation built on May 21, 2019, 5:09 a.m.