Binomial-extensions {countreg} | R Documentation |
Score function, hessian, mean, and variance
for the binomial distribution
with parameters prob
and size
.
sbinom(x, prob, size, parameter = "prob", drop = TRUE) hbinom(x, prob, size, parameter = "prob", drop = TRUE) mean_binom(prob, size, drop = TRUE) var_binom(prob, size, drop = TRUE)
x |
vector of quantiles. |
prob |
probability of success on each trial. |
size |
number of trials (zero or more). |
parameter |
character. Derivatives are computed wrt this
paramter. Note: Only |
drop |
logical. Should the result be a matrix ( |
The binomial distribution with size
= n and
prob
= p has density
p(x) = choose(n, x) p^x (1-p)^(n-x)
for x = 0, …, n.
The score function is
s(p) = x/p - (n-x)/(1-p)
The hessian is
h(p) = - x/p^2 - (n-x)/(1-p)^2
sbinom
gives the score function, i.e., the 1st
derivative of the log-density wrt prob and
hbinom
gives the hessian, i.e., the 2nd
derivative of the log-density wrt prob.
mean
and var
give the mean and
variance, respectively.
Binomial encompassing dbinom
, pbinom
,
qbinom
and rbinom
.
## Simulate some data set.seed(123) y <- rbinom(50, size = 1, prob = 0.3) ## Plot log-likelihood function par(mfrow = c(1,3)) ll <- function(x) {sum(dbinom(y, size = 1, prob = x, log = TRUE))} curve(sapply(x, ll), xlab = expression(pi), ylab = "", main = "Log-likelihood") abline(v = 0.3, lty = 3) ## Plot score function curve(sapply(x, function(x) sum(sbinom(y, size = 1, x))), xlab = expression(pi), ylab = "", main = "Score") abline(h = 0, lty = 3) abline(v = 0.3, lty = 3) ## Plot hessian curve(sapply(x, function(x) sum(hbinom(y, size = 1, x))), xlab = expression(pi), ylab = "", main = "Hessian") abline(v = 0.3, lty = 3)