
Last chance! 50% off unlimited learning
Sale ends in
Family function for a hypergeometric distribution where either the number of white balls or the total number of white and black balls are unknown.
hyperg(N = NULL, D = NULL, lprob = "logitlink", iprob = NULL)
An object of class "vglmff"
(see vglmff-class
).
The object is used by modelling functions such as
vglm
,
vgam
,
rrvglm
,
cqo
,
and cao
.
Total number of white and black balls in the urn.
Must be a vector with positive values, and is recycled, if necessary,
to the same length as the response.
One of N
and D
must be specified.
Number of white balls in the urn.
Must be a vector with positive values, and is recycled, if necessary,
to the same length as the response.
One of N
and D
must be specified.
Link function for the probabilities.
See Links
for more choices.
Optional initial value for the probabilities. The default is to choose initial values internally.
Thomas W. Yee
No checking is done to ensure that certain values are within range,
e.g.,
Consider the scenario from
dhyper
where there
are N
is D
is
Depending on which one of N
and D
is inputted, the
estimate of the other parameter can be obtained from the equation
prob = D/N
. However,
the log-factorials are computed using lgamma
and both trunc(Nhat)
and ceiling(Nhat)
where Nhat
is the (real) estimate of
Forbes, C., Evans, M., Hastings, N. and Peacock, B. (2011). Statistical Distributions, Hoboken, NJ, USA: John Wiley and Sons, Fourth edition.
dhyper
,
binomialff
.
nn <- 100
m <- 5 # Number of white balls in the population
k <- rep(4, len = nn) # Sample sizes
n <- 4 # Number of black balls in the population
y <- rhyper(nn = nn, m = m, n = n, k = k)
yprop <- y / k # Sample proportions
# N is unknown, D is known. Both models are equivalent:
fit <- vglm(cbind(y,k-y) ~ 1, hyperg(D = m), trace = TRUE, crit = "c")
fit <- vglm(yprop ~ 1, hyperg(D = m), weight = k, trace = TRUE, crit = "c")
# N is known, D is unknown. Both models are equivalent:
fit <- vglm(cbind(y, k-y) ~ 1, hyperg(N = m+n), trace = TRUE, crit = "l")
fit <- vglm(yprop ~ 1, hyperg(N = m+n), weight = k, trace = TRUE, crit = "l")
coef(fit, matrix = TRUE)
Coef(fit) # Should be equal to the true population proportion
unique(m / (m+n)) # The true population proportion
fit@extra
head(fitted(fit))
summary(fit)
Run the code above in your browser using DataLab