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: jacobwege...@fastmail.fm URL: http://www.people.vcu.edu/~jwegelin

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to