Learn R Programming

msme (version 0.5.3)

irls: Function to fit generalized linear models using IRLS.

Description

This function fits a wide range of generalized linear models using the iteratively reweighted least squares algorithm. The intended benefit of this function is for teaching. Its scope is similar to that of R's glm function, which should be preferred for operational use.

Usage

irls(formula, data, family, link, tol = 1e-06, offset = 0, m = 1, a = 1, verbose = 0)

Arguments

formula

an object of class '"formula"' (or one that can be coerced to that class): a symbolic description of the model to be fitted. (See the help for 'glm' for more details).

data

a data frame containing the variables in the model.

family

a description of the error distribution be used in the model. This must be a character string naming a family.

link

a description of the link function be used in the model. This must be a character string naming a link function.

tol

an optional quantity to use as the convergence criterion for the change in deviance.

offset

this can be used to specify an _a priori_ known component to be included in the linear predictor during fitting. This should be 0 or a numeric vector of length equal to the number of cases.

m

the number of cases per observation for binomial regression.

a

the scale for negative binomial regression.

verbose

a flag to control the amount of output printed by the function.

Value

coefficients

parameter estimates.

se.beta.hat

standard errors of parameter estimates.

model

the final, weighted linear model.

call

the function call used to create the object.

nobs

the number of observations.

eta

the linear predictor at the final iteration.

mu

the estimated mean at the final iteration.

df.residual

the residual degrees of freedom.

df.null

the degrees of freedom for the null model.

deviance

the residual deviance.

null.deviance

a place-holder for the null deviance - returned as NA

p.dispersion

Pearsons's Chi-squared statistic.

pearson

Pearson's deviance.

loglik

the maximized log-likelihood.

family

the chosen family.

X

the design matrix.

i

the number of iterations required for convergence.

residuals

the deviance residuals.

aic

Akaike's Information Criterion.

Details

The containing package, msme, provides the needed functions to use the irls function to fit the Poisson, negative binomial (2), Bernoulli, and binomial families, and supports the use of the identity, log, logit, probit, complementary log-log, inverse, inverse^2, and negative binomial link functions. All statistics are computed at the final iteration of the IRLS algorithm. The convergence criterion is the magnitude of the change in deviance. The object returned by the function is designed to be reported by the print.glm function.

References

Hilbe, J.M., and Robinson, A.P. 2013. Methods of Statistical Model Estimation. Chapman & Hall / CRC.

See Also

glm, ml_glm

Examples

Run this code
# NOT RUN {
data(medpar)

irls.poi <- irls(los ~ hmo + white,
                 family = "poisson",
                 link = "log",
                 data = medpar)
summary(irls.poi)

irls.probit <- irls(died ~ hmo + white,
                    family = "binomial",
                    link = "probit",
                    data = medpar)
summary(irls.probit)

# }

Run the code above in your browser using DataLab