| NegBin | R Documentation |
Creates the functions needed to fit a Negative Binomial generalized smooth model via gsm with or without a known theta parameter. Adapted from the negative.binomial function in the MASS package.
NegBin(theta = NULL, link = "log")
theta |
the |
link |
the link function. Must be |
The Negative Binomial distribution has mean \mu and variance \mu + \mu^2/\theta, where the size parameter \theta is the inverse of the dispersion parameter. See NegBinomial for details.
An object of class "family" with the functions and expressions needed to fit the gsm. In addition to the standard values (see family), this also produces the following:
logLik |
function to evaluate the log-likelihood |
canpar |
function to compute the canonical parameter |
cumulant |
function to compute the cumulant function |
theta |
the specified |
fixed.theta |
logical specifying if |
Nathaniel E. Helwig <helwig@umn.edu>
Venables, W. N. and Ripley, B. D. (1999) Modern Applied Statistics with S-PLUS. Third Edition. Springer.
https://www.rdocumentation.org/packages/MASS/versions/7.3-51.6/topics/negative.binomial
https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/NegBinomial
gsm for fitting generalized smooth models with Negative Binomial responses
theta.mle for maximum likelihood estimation of theta
# generate data
n <- 1000
x <- seq(0, 1, length.out = n)
fx <- 3 * x + sin(2 * pi * x) - 1.5
# negative binomial (size = 1/2, log link)
set.seed(1)
y <- rnbinom(n = n, size = 1/2, mu = exp(fx))
# fit model (known theta)
mod <- gsm(y ~ x, family = NegBin(theta = 1/2), knots = 10)
mean((mod$linear.predictors - fx)^2)
mod$family$theta # fixed theta
# fit model (unknown theta)
mod <- gsm(y ~ x, family = NegBin, knots = 10)
mean((mod$linear.predictors - fx)^2)
mod$family$theta # estimated theta
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.