glmc: Fitting Generalised Linear Models Subject to Population...

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

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.

Usage

1
2
3
4
5
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,...) 

Arguments

formula

a symbolic description of the model to be fit. The details of model specification are given below.

family

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.)

data

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.

na.action

a function which indicates what should happen when the data contain NAs. The default is set by the na.action setting of options, and is na.fail if that is unset. The “factory-fresh” default is na.omit.

start

starting values for the parameters in the linear predictor.

etastart

starting values for the linear predictor.

mustart

starting values for the vector of means.

offset

this can be used to specify an a priori known component to be included in the linear predictor during fitting.

control

a list of parameters for controlling the fitting process. See the documentation for glmc.control for details.

model

a logical value indicating whether model frame should be included as a component of the returned value.

glm.method

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.

emplik.method

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.

optim.method

the method used to maximise over the parameters. See optim for more details.

optim.hessian

Logical. If True returns a numerically calculated Hessian Matrix from the optim step.

x, y

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.

Amat

a matrix of population constraints on the parameters.

confn

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.

Details

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.

Value

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:

coefficients

a named vector of coefficients

residuals

the working residuals, that is the residuals in the final iteration of the IWLS fit.

fitted.values

the fitted mean values, obtained by transforming the linear predictors by the inverse of the link function.

rank

the numeric rank of the fitted linear model.

family

the family object used.

linear.predictors

the linear fit on link scale.

deviance

up to a constant, minus twice the maximised log-likelihood. Where sensible, the constant is chosen so that a saturated model has deviance zero.

aic

Akaike's An Information Criterion, minus twice the maximised log-likelihood plus twice the number of coefficients (so assuming that the dispersion is known.)

null.deviance

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

iter

the number of iterations of IWLS used.

weights

the working weights, that is the weights in the final iteration of the IWLS fit from the glm step (if there is one).

final.weights

the weights maximising the empirical likelihood

df.residual

the residual degrees of freedom.

df.null

the residual degrees of freedom for the null model.

y

the y vector used. (It is a vector even for a binomial model.)

converged

logical. Was the IWLS algorithm judged to have converged?

boundary

logical. Is the fitted value on the boundary of the attainable values?

call

the matched call.

formula

the formula supplied.

terms

the terms object used.

data

the data argument.

offset

the offset vector used.

control

the value of the control argument used.

glm.method

the name of the fitter function used in the final glm call, in R always "glm.fit".

emplik.method

the name of the method used to maximise the empirical likelihood.

optim.method

the name of the method supplied to the optim function for the outer maximisation over the parameters.

.

xlevels

(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.

Author(s)

The R implementation of glmc is written by Sanjay Chaudhuri and Mark S Handcock at National University of Singapore and University of Washington, Seattle respectively.

References

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.

See Also

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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)
    
## End(Not run) 

Example output

     Fitting Generalized Linear Models Subject to
                    Constraints
Version      0.3-1 created on      2018-12-11.

'Title:              Fitting Generalized Linear Models Subject to
                    Constraints'
Version Version:            0.3-1 created on Date:               2018-12-11.

copyright (c) 2004, Mark S. Handcock, University of Washington

To cite, see citation("glmc")

Type help(package="glmc") to get started.

[1]   -0.02656434  -14.43904679 1320.26413390    1.00000000
[1]  -0.0220031 -15.3239529 375.8086391   1.0000000
[1]  -0.0217611 -15.3261430  18.0697997   1.0000000
[1]  -0.02176048 -15.32614305   0.04572550   1.00000000
[1] -2.176048e-02 -1.532614e+01  2.958267e-07  9.000000e+00
Warning message:
In model.matrix.default(mt, mf, contrasts) :
  non-list contrasts argument ignored

Call:
glmc(formula = birth ~ child, family = "binomial", data = hrh, 
    control = glmc.control(maxit.glm = 10, maxit.weights = 200, 
        itertrace.weights = TRUE, gradtol.weights = 10^(-6)), 
    emplik.method = "Owen")

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-0.4045  -0.4045  -0.3091  -0.3091   2.4759  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept) -3.01731    0.05199 -58.039  < 2e-16 ***
child        0.55496    0.08700   6.379 1.78e-10 ***
---
Signif. codes:  0***0.001**0.01*0.05.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

Null     deviance: 0.46373  on 11639  degrees of freedom
Residual deviance: 0.45934  on 11638  degrees of freedom
AIC: 4

Number of Fisher Scoring iterations: 6

[1]   -0.02656434  -14.43904679 1320.26413390    1.00000000
[1]  -0.0220031 -15.3239529 375.8086391   1.0000000
[1]  -0.0217611 -15.3261430  18.0697997   1.0000000
[1]  -0.02176048 -15.32614305   0.04572550   1.00000000
[1] -2.176048e-02 -1.532614e+01  2.958267e-07  9.000000e+00
[1] -2.176048e-02 -1.532614e+01  2.945893e-07  1.300000e+01
[1] -2.176048e-02 -1.532614e+01  2.945893e-07  1.300000e+01
[1] -2.176048e-02 -1.532614e+01  2.945893e-07  1.300000e+01
[1] -2.176048e-02 -1.532614e+01  2.945892e-07  0.000000e+00
Warning message:
In model.matrix.default(mt, mf, contrasts) :
  non-list contrasts argument ignored

Call:
glmc(formula = mat[, 2] ~ mat[, 1], family = binomial(link = logit), 
    control = glmc.control(maxit.glm = 10, maxit.weights = 200, 
        itertrace.weights = TRUE, gradtol.weights = 10^(-10)), 
    emplik.method = "Owen", Amat = amat, confn = NULL)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-0.4045  -0.4045  -0.3091  -0.3091   2.4759  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept) -3.01731    0.05199 -58.039  < 2e-16 ***
mat[, 1]     0.55496    0.08700   6.379 1.78e-10 ***
---
Signif. codes:  0***0.001**0.01*0.05.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

Null     deviance: 0.46373  on 11639  degrees of freedom
Residual deviance: 0.45934  on 11638  degrees of freedom
AIC: 4

Number of Fisher Scoring iterations: 6

initial  value 8843.408055 
iter   2 value 368.338941
iter   3 value 180.974974
iter   4 value 26.398217
iter   5 value 25.697260
iter   6 value 16.475018
iter   7 value 16.105789
iter   8 value 15.360107
iter   9 value 15.333173
iter  10 value 15.327196
iter  11 value 15.326147
iter  12 value 15.326145
iter  13 value 15.326144
iter  14 value 15.326144
iter  14 value 15.326144
iter  15 value 15.326144
iter  15 value 15.326144
iter  16 value 15.326143
iter  16 value 15.326143
iter  17 value 15.326143
iter  17 value 15.326143
iter  17 value 15.326143
final  value 15.326143 
converged
Warning message:
In model.matrix.default(mt, mf, contrasts) :
  non-list contrasts argument ignored

Call:
glmc(formula = birth ~ child, family = binomial(link = logit), 
    data = hrh, 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.method = "BFGS", emplik.method = "Owen", optim.hessian = TRUE, 
    Amat = NULL, confn = fn)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-0.4045  -0.4045  -0.3091  -0.3091   2.4759  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept) -3.01735    0.05185 -58.194  < 2e-16 ***
child        0.55503    0.08676   6.397 1.58e-10 ***
---
Signif. codes:  0***0.001**0.01*0.05.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

Null     deviance: 0.46373  on 11639  degrees of freedom
Residual deviance: 0.45934  on 11638  degrees of freedom
AIC: 4

Number of Fisher Scoring iterations: 6

glmc documentation built on May 1, 2019, 10:52 p.m.