glm1path(y, X, family = "negative.binomial", lambdas = NULL,
penalty = c(0, rep(1, dim(X)[2]-1)), df.max = sum(y > 0), n.lambda = 25, lam.max = NULL,
lam.min = NULL, k = log(length(y)), b.init = NA, phi.init = NA, phi.iter = 1, ...)
family
. Negative binomial with unknown overdispersion can be specified as "negative.binomial", and is the default.penalty
. By default, a geometric sequence of values will be constructed with n.
lambdas
).lambdas
).lambdas
).log(length(y))
, gives BIC (known to be consistent, for adaptive LASSO), changing it to 2
would give AIC (which is not so gglm1
.glm1path
with the following components:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]glm1
function, which uses a local linearisation approach as in Osborne et al (2000), nested inside iteratively reweighted (penalised) least squares, and using results from the previous fit as initial estimates. Look it's not the fastest thing going around, try glmnet if you want something faster (and possibly rougher as an approximation). The main advantage of the glm1path
function is that it has been written to accept any glm family argument (although not yet tested beyond discrete data!), and also the negative binomial distribution, which is especially useful for modelling overdispersed counts.
For negative binomial with unknown overdispersion use "negative.binomial"
, or if overdispersion is to be specified, use negative.binomial(theta)
as in the MASS
package. Note that the output refers to phi=1/theta, i.e. the overdispersion is parameterised in output such that the variance is mu+phi*mu^2. Hence values of phi close to zero suggest little overdispersion, values over one suggest a lot.
You can use the residuals
and plot
functions on glm1path
objects in order to compute Dunn-Smyth residuals and a plots of these residuals against linear predictors, as for manyglm
.glm1
, glm
, family
, residuals.manyglm
, plot.manyany
data(spider)
Alopacce <- spider$abund[,1]
X <- cbind(1,spider$x)
# fit a LASSO-penalised negative binomial regression:
ft = glm1path(Alopacce,X)
# have a look at the BICS for all models:
plot(ft$bics~ft$lambdas, log="x")
#the action seems to be at lambda above 0.1, re-do with a minimum lambda at 0.1 and more lambdas:
ft2 = glm1path(Alopacce,X,lam.min=0.1,n.lambda=100)
plot(ft2$bics~ft2$lambdas, log="x")
# return the slope estimates for the best-fitting model:
coef(ft2)
# look at a residual plot:
plot(ft2)
Run the code above in your browser using DataLab