Michael Friendly
2014-Oct-04 16:45 UTC
[R] get names of glm and related families from an object
In a function I'm writing, I want to handle a variety of families of glm() and related models including MASS::glm.nb() and hopefully countreg::hurdle(), zeroinfl(). A central part of the function is a switch() call family <- object$family$family switch(family, "binomial" = { }, "quasibinomial" = { }, "poisson" = { }, "quasipoisson" = { }, "gaussian" = { } ) But I discovered that the object$family$family slot doesn't work the same way with glm.nb -- I get, e.g., > nmes.nbin2$family$family [1] "Negative Binomial(1.2354)" and the countreg functions don't return a family component. I think I have to also use class(object), and a more complicated computation of family, but maybe there's a simpler way? -Michael -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. & Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA