Last chance! 50% off unlimited learning
Sale ends in
glmc
is used to fit generalised linear models
where the parameters are subject to population constraints.
The model is specified by giving a symbolic description of
the linear predictor, a description of the error distribution,
and a matrix of constraints on the parameters.
glmc(formula,family = gaussian, data, na.action,
start = NULL,etastart, mustart, offset,control = glmc.control(…),
model = TRUE,glm.method= "glm.fit",optim.method="Nelder-Mead",
emplik.method="Owen",optim.hessian=FALSE,x = FALSE, y = TRUE,
Amat=NULL, confn=NULL,…)
a symbolic description of the model to be fit. The details of model specification are given below.
a description of the error distribution and link
function to be used in the model. This can be a character string
naming a family function, a family function or the result of a call
to a family function. (See family
for details of
family functions.)
an optional data frame containing the variables
in the model. By default the variables are taken from
environment(formula)
, typically the environment from which
glmc
is called. All variables named constraints
is automatically assumed to be the value of the population constraints.
starting values for the parameters in the linear predictor.
starting values for the linear predictor.
starting values for the vector of means.
this can be used to specify an a priori known component to be included in the linear predictor during fitting.
a list of parameters for controlling the fitting
process. See the documentation for glmc.control
for details.
a logical value indicating whether model frame should be included as a component of the returned value.
the method to be used in fitting the model.
The default method "glm.fit"
uses iteratively re-weighted
least squares (IWLS). The only current alternative is
"model.frame"
which returns the model frame and does no fitting.
the method used to maximise the empirical likelihood to compute the weights. The default is "Owen"
, due to Art Owen. Current alternative is "CSW"
, due to Chen, Sitter and Wu.
the method used to maximise over the parameters. See optim
for more details.
Logical. If True returns a numerically calculated Hessian Matrix from the optim step.
For glmc
:
logical values indicating whether the response
vector and model matrix used in the fitting process
should be returned as components of the returned value.
For glmc.fit
: x
is a design matrix of dimension n
* p
, and y
is a vector of observations of length n
.
a matrix of population constraints on the parameters.
a function returning the value of the population constraints on the parameter. Allows parameter dependent population constraints.
further arguments passed to or from other methods.
glmc
returns an object of class inheriting from "glmc"
which inherits from the class "lm"
. See later in this section.
The generic accessor functions coefficients
,
effects
, fitted.values
and residuals
can be used to
extract various useful features of the value returned by glmc
.
An object of class "glmc"
is a list containing at least the
following components:
a named vector of coefficients
the working residuals, that is the residuals in the final iteration of the IWLS fit.
the fitted mean values, obtained by transforming the linear predictors by the inverse of the link function.
the numeric rank of the fitted linear model.
the family
object used.
the linear fit on link scale.
up to a constant, minus twice the maximised log-likelihood. Where sensible, the constant is chosen so that a saturated model has deviance zero.
Akaike's An Information Criterion, minus twice the maximised log-likelihood plus twice the number of coefficients (so assuming that the dispersion is known.)
The deviance for the null model, comparable with
deviance
. The null model will include the offset, and an
intercept if there is one in the model
the number of iterations of IWLS used.
the working weights, that is the weights in the final iteration of the IWLS fit from the glm step (if there is one).
the weights maximising the empirical likelihood
the residual degrees of freedom.
the residual degrees of freedom for the null model.
the y
vector used. (It is a vector even for a binomial
model.)
logical. Was the IWLS algorithm judged to have converged?
logical. Is the fitted value on the boundary of the attainable values?
the matched call.
the formula supplied.
the terms
object used.
the data argument
.
the offset vector used.
the value of the control
argument used.
the name of the fitter function used in the final glm
call, in R always
"glm.fit"
.
the name of the method used to maximise the empirical likelihood.
the name of the method supplied to the optim function for the outer maximisation over the parameters.
(where relevant) a record of the levels of the factors used in fitting.
In addition, non-empty fits will have components qr, R and effects relating to the final weighted linear fit.
Objects of class "glmc" are normally of class c("glmc","glm", "lm"), that is inherit from class "lm", and well-designed methods for class "lm" will be applied to the weighted linear model at the final iteration of IWLS. However, care is needed, as extractor functions for class "glmc" such as residuals and weights do not just pick out the component of the fit with the same name. In-fact no "type" specification in weights retirns the weights which maximises the empirical likelihood. A call of wieghts with type="prior" returns a vector of 1 of length equaling the number of odsevations.
% If a \code{\link{binomial}} \code{glmc} model is specified by giving a % two-column response, the weights returned by \code{prior.weights} are % the total numbers of cases (factored by the supplied case weights) and % the component \code{y} of the result is the proportion of successes.
A typical predictor has the form response ~ terms
where
response
is the (numeric) response vector and terms
is a
series of terms which specifies a linear predictor for response
.
A terms specification of the form
first + second
indicates all the terms in first
together
with all the terms in second
with duplicates removed. A specification of the form first:second
indicates the
the set of terms obtained by taking the interactions of
all terms in first
with all terms in second
.
The specification first*second
indicates the cross
of first
and second
.
This is the same as first + second + first:second
.
glmc
uses closely follows glm
, uses glm.fit
, optim
and el.test
form the emplik
library.
If more than one of etastart
, start
and mustart
is specified, the first in the list will be used.
Owen, A. B. (2001) Empirical Likelihood. Boca Raton, Fla : Chapman \& Hall/CRC.
Dobson, A. J. (1990) An Introduction to Generalized Linear Models. London: Chapman and Hall.
Hastie, T. J. and Pregibon, D. (1992) Generalized linear models. Chapter 6 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth \& Brooks/Cole.
McCullagh P. and Nelder, J. A. (1989) Generalized Linear Models. London: Chapman and Hall.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. New York: Springer.
glmc
methods,
and the generic functions anova
, summary
,
effects
, fitted.values
,
and residuals
. optim
, el.test
, the fitting procedure used by glmc
. Further, lm
for non-generalised linear models.
# NOT RUN {
library(glmc)
#Specify the data.
n <- rbind(c(5903,230),c(5157,350))
mat <- matrix(0,nrow=sum(n),ncol=2)
mat <- rbind(matrix(1,nrow=n[1,1],ncol=1)%*%c(0,0),
matrix(1,nrow=n[1,2],ncol=1)%*%c(0,1),
matrix(1,nrow=n[2,1],ncol=1)%*%c(1,0),
matrix(1,nrow=n[2,2],ncol=1)%*%c(1,1))
#Specifying the population constraints.
gfr <- .06179*matrix(1,nrow=nrow(mat),ncol=1)
g <- matrix(1,nrow=nrow(mat),ncol=1)
amat <- matrix(mat[,2]*g-gfr,ncol=1)
# Method 1. Defining constraints in the data frame.
hrh <- data.frame(birth=mat[,2], child=mat[,1], constraints=amat)
gfit <- glmc(birth~child, data=hrh, family="binomial",emplik.method="Owen",
control=glmc.control(maxit.glm=10,maxit.weights=200,
itertrace.weights=TRUE,gradtol.weights=10^(-6)))
summary.glmc(gfit)
# Method 2. Defining constraints through a matrix.
gfit<- glmc(mat[,2]~mat[,1],family=binomial(link=logit),
emplik.method="Owen",control=glmc.control(maxit.glm=10,
maxit.weights=200,itertrace.weights=TRUE,gradtol.weights=10^(-10)),
Amat=amat,confn=NULL)
summary.glmc(gfit)
# }
# NOT RUN {
# Method 3. Defining constraints through a function.
fn <- function(t,Y,X){
grf <- .06179*matrix(1,nrow=nrow(as.matrix(X)),ncol=1)
g <- matrix(1,nrow=nrow(X),ncol=1)
amat <- matrix(Y*g-grf,ncol=1)
return(amat)
}
gfit <- glmc(birth~child,data=hrh,family=binomial(link=logit),
optim.method="BFGS",emplik.method="Owen",
control=glmc.control(maxit.glm=10,maxit.optim=10^(8),
reltol.optim=10^(-10),trace.optim=9,REPORT.optim=1,
maxit.weights=200,gradtol.weights=10^(-6),itertrace.weights=FALSE),
optim.hessian=TRUE,Amat=NULL,confn=fn)
summary.glmc(gfit)
# }
Run the code above in your browser using DataLab