Roland Deutsch
2013-Nov-07 13:07 UTC
[R] Adding the complementary log-link to binomial() and make.link()
Dear R Help,
in my research I frequently work with binomial response models, which
are of course part of the generalized linear models. While I do use
common link functions such as the logit, probit and cloglog, I often
have the need of invoking the lesser-known Complementary Log link
(Walter W. Piegorsch, 1992, "Complementary Log Regression for
Generalized Linear Models ", The American Statistician , Vol. 46, No. 2,
pp. 94-99 ) which is based on the exponential distribution.
Before the release of R 3.0, I simply could do so by adding the
following lines to the long switch command in make.link(...):
clog = {
linkfun <- function(mu) qexp(mu)
linkinv <- function(eta) pmax(.Machine$double.eps,pexp(eta))
mu.eta <- function(eta) pmax(dexp(eta), .Machine$double.eps)
valideta <- function(eta) all(eta > 0)
},
and then add "clog" to the okLinks vector in binomial(). However, I
recently installed R 3.0.2 and cannot get the clog link to work. I guess
it has to do do with the fact that both make.link and binomial are
residing in the Global environment, and does I do not know how to access
the C routine C_binomial_dev_resids to compute the deviance residuals
within binomial().
While I would appreciate any help on this issue, I also thought it may
benefit other users in my research area to have the complementary log
link included in make.link. Any chance of this happening?
Thanks a lot,
Roland Deutsch
[[alternative HTML version deleted]]
Ken Knoblauch
2013-Nov-07 16:04 UTC
[R] Adding the complementary log-link to binomial() and make.link()
Roland Deutsch <roland.deutsch <at> tuwien.ac.at> writes:> in my research I frequently work with binomialresponse models, which> are of course part of the generalized linearmodels. While I do use> common link functions such as the logit, probitand cloglog, I often> have the need of invoking the lesser-knownComplementary Log link> (Walter W. Piegorsch, 1992, "Complementary LogRegression for> Generalized Linear Models ", The AmericanStatistician , Vol. 46, No. 2,> pp. 94-99 ) which is based on the exponentialdistribution.> > Before the release of R 3.0, I simply coulddo so by adding the> following lines to the long switch commandin make.link(...):> > clog = { > linkfun <- function(mu) qexp(mu) > linkinv <- function(eta) pmax(.Machine$double.eps,pexp(eta)) > mu.eta <- function(eta) pmax(dexp(eta), .Machine$double.eps) > valideta <- function(eta) all(eta > 0) > }, > > and then add "clog" to the okLinks vector inbinomial(). However, I I wouldn't mess with make.link. Why don't you just define your own custom link, for example following the example under help(family)? This is what I did in the psyphy package and I just checked and they all still work under the current version of R.> Thanks a lot, > Roland Deutsch-- Kenneth Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen L?pine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html