This question has already been somewhat addressed already in the past on this site, but the answers provided are not fully helpful to me. Here are the details of my questions that are actually somewhat different from what has already been discussed here:
After working hard on this, I remained unable to understand how I can define my own user-specified link function in R for glm
. I have several questions on this.
First of all, I understand I have to write my own function (likely modifying one that already exists), and - in it - I need to define the following elements:
linkfun
: the link function.linkinv
: the inverse of the link function, as a function of "eta".mu.eta
: the first derivative of the invlink respect to eta.valideta
: that must return TRUE if the value of eta are in the correct interval
And return all of this in a list element.
So far, so good.
Here is the first set of my questions:
The link function is sometimes defined as a function of "y" and sometimes as a function of "mu". What must be done in this respect?
Let's take an example, and type
make.link("sqrt")
. We then indeed discover that linkfun issqrt(mu)
, linkinv iseta^2
, mu.eta is2*eta
. So far, so good. However, if you look atmake.link("log")
, mu.eta is not simplyexp(eta)
as it should, butpmax(exp(eta), .Machine$double.eps)
(i.e., the maximal values of the first derivative for all the eta vector). Why? I remained unable to understand this.Just for my curiosity, why the algorithm needs the first derivative of the invlink respect to eta? This is not fully clear to me.
In my specific case, I need a quasi-logistic regression for binomial data. Instead of having a standard logit function
log(p/(1-p))
, I need to have the slightly modified link function (if p is defined as Y/N):log((Y+0.5)/(N-Y+0.5))
.My other question in this case is:
I remained unable to built this.. Can someone give me some hints?
Where can I find a detailed explanation of all of this? I have looked at the good old Chambers & Hastie book (1992), but the explanation is not sufficient. Are there any detailed courses available on the web, etc.?