Description Usage Arguments Details Value Examples
Obtain a marginal distribution of a random variable in an rvtable.
1 | marginalize(x, margin, density.args, sample.args)
|
x |
an rvtable. |
margin |
variable(s) in rvtable to marginalize over. |
density.args |
optional arguments passed to |
sample.args |
optional arguments used when sampling. If supplied, overrides the |
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.
an rvtable.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.