Learn R Programming

bayesRecon (version 0.3.1)

PMF.get_var: Get the variance of the distribution from a PMF object

Description

Returns the variance from the PMF specified by pmf.

Usage

PMF.get_var(pmf)

Value

A numerical value for variance.

Arguments

pmf

the PMF object.

See Also

PMF.get_mean(), PMF.get_quantile(), PMF.sample(), PMF.summary()

Examples

Run this code
library(bayesRecon)

# Let's build the pmf of a Binomial distribution with parameters n and p
n <- 10
p <- 0.6 
pmf_binomial <- apply(matrix(seq(0,10)),MARGIN=1,FUN=function(x) dbinom(x,size=n,prob=p))

# The true variance corresponds to n*p*(1-p)
true_var <- n*p*(1-p)
var_from_PMF <- PMF.get_var(pmf=pmf_binomial)
cat("True variance:", true_var, "\nVariance from PMF:", var_from_PMF)

Run the code above in your browser using DataLab