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")
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:
function to evaluate the log-likelihood
function to compute the canonical parameter
function to compute the cumulant function
the specified theta
parameter
logical specifying if theta
was provided
the size
parameter for the Negative Binomial distribution. Default of NULL
indicates that theta
should be estimated from the data.
the link function. Must be log
, sqrt
, identity
, or an object of class link-glm
(as generated by make.link
).
Nathaniel E. Helwig <helwig@umn.edu>
The Negative Binomial distribution has mean size
parameter NegBinomial
for details.
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
Run the code above in your browser using DataLab