[R] confirm family==binomial and link==logistic

Jacob Wegelin jacobwegelin at fastmail.fm
Fri Feb 12 17:33:59 CET 2016


To check that a regression object comes from logistic regression, I employ the following two lines:

 	stopifnot(glmObject$family$family=="binomial")

 	stopifnot(glmObject$family$link=="logit")

For instance:

toyfunction<-function(glmObject) {
 	stopifnot(inherits(glmObject, "glm"))
 	stopifnot(glmObject$family$family=="binomial")
 	stopifnot(glmObject$family$link=="logit")
 	cat("okay, I guess\n")
 	glmObject
}

mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")

someobject<- glm(admit~gre+gpa, data=mydata)

toyfunction(someobject)

someobject<- glm(admit~gre+gpa, data=mydata, family="binomial")

toyfunction(someobject)

But Doug Bates once stated that it's preferable to use extractor functions (and perhaps other ready-made functions?) rather than "deconstructing" an object (his term), as I do here.

Accordingly, is there a smarter way to perform the check that I perform inside toyfunction?

Thanks for any insight

Jacob A. Wegelin
Assistant Professor
C. Kenneth and Dianne Wright Center for Clinical and Translational Research
Department of Biostatistics
Virginia Commonwealth University
830 E. Main St., Seventh Floor
P. O. Box 980032
Richmond VA 23298-0032
U.S.A. 
CTSA grant: UL1TR000058
E-mail: jacobwegelin at fastmail.fm 
URL: http://www.people.vcu.edu/~jwegelin



More information about the R-help mailing list