[R] Syntax for fit.contrast

Sorkin, John jsorkin at som.umaryland.edu
Sun Oct 22 15:04:19 CEST 2017


I have a model (run with glm) that has a factor, type. Type has two levels, "general" and "regional". I am trying to get estimates (and SEs) for the model with type="general" and type ="regional" using fit.contrast but I can't get the syntax of the coefficients to use in fit.contrast correct. I hope someone can show me how to use fit.contrast, or some other method to get estimate with SEs. (I know I can use the variance co-variance matrix, but I would rather not have to code the linear contrast my self from the coefficients of the matrix)

Thank  you,

John


My model:

model=glm(events~type,family=poisson(link=log),offset=log(SS),data=data)


Model details:

> summary(data$type)

 general regional
      16       16

> levels(data$type)
[1] "general"  "regional"

> contrasts(data$type)
         regional
general         0
regional        1


I have tried the following syntax for fit.contrast

fit.contrast(model,type,c(1,0))
and get an error:
Error in `[[<-`(`*tmp*`, varname, value = cmat) :
  no such index at level 1


> fit.contrast(model,type,c(0,1),showall=TRUE)
and get an error:
Error in `[[<-`(`*tmp*`, varname, value = cmat) :
  no such index at level 1



> fit.contrast(model,type,c(1,-1),showall=TRUE)
and get an error:
Error in `[[<-`(`*tmp*`, varname, value = cmat) :
  no such index at level 1


> fit.contrast(model,type,c(0))
and get an error:
Error in make.contrasts(coeff, ncol(coeff)) :
  Too many contrasts specified. Must be less than the number of factor levels (columns).

> fit.contrast(model,type,c(1))
Error in make.contrasts(coeff, ncol(coeff)) :
and get an error
  Too many contrasts specified. Must be less than the number of factor levels (columns).








John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)


	[[alternative HTML version deleted]]



More information about the R-help mailing list