# -----------------------------------------------------
# Categorical Distribution Example
# -----------------------------------------------------
# Create the distribution
p <- c(0.1, 0.2, 0.7)
D <- Cat(p)
# ------------------
# dpqr Functions
# ------------------
d(D, 2) # density function
x <- r(D, 100) # random generator function
# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself
# ------------------
# Moments
# ------------------
mean(D) # Expectation
mode(D) # Mode
var(D) # Variance
entro(D) # Entropy
finf(D) # Fisher Information Matrix
# List of all available moments
mom <- moments(D)
mom$mean # expectation
# ------------------
# Point Estimation
# ------------------
ll(D, x)
llcat(x, p)
ecat(x, dim = 3, type = "mle")
ecat(x, dim = 3, type = "me")
mle(D, x)
me(D, x)
e(D, x, type = "mle")
mle("cat", dim = 3, x) # the distr argument can be a character
# ------------------
# Estimator Variance
# ------------------
vcat(p, type = "mle")
vcat(p, type = "me")
avar_mle(D)
avar_me(D)
v(D, type = "mle")
Run the code above in your browser using DataLab