Apologies if the answer is obvious but I've spent quite some time trying to use a custom link function in mgcv.gam
In short,
- I want to use a modified probit link from package psyphy ( I want to use psyphy.probit_2asym, I call it
custom_link
) I can create a {stats}family object with this link and use it in the 'family' argument of glm.
m <- glm(y~x, family=binomial(link=custom_link), ... )
It does not work when used as an argument for {mgcv}gam
m <- gam(y~s(x), family=binomial(link=custom_link), ... )
I get the error
Error in fix.family.link.family(family) : link not recognised
I do not get the reason for this error, both glm and gam work if I specify the standard link=probit
.
So my question can be summarized as:
what is missing in this custom link that works for glm but not for gam?
Thanks in advance if you can give me a hint on what I should do.
Link function
probit.2asym <- function(g, lam) {
if ((g < 0 ) || (g > 1))
stop("g must in (0, 1)")
if ((lam < 0) || (lam > 1))
stop("lam outside (0, 1)")
linkfun <- function(mu) {
mu <- pmin(mu, 1 - (lam + .Machine$double.eps))
mu <- pmax(mu, g + .Machine$double.eps)
qnorm((mu - g)/(1 - g - lam))
}
linkinv <- function(eta) {
g + (1 - g - lam) *
pnorm(eta)
}
mu.eta <- function(eta) {
(1 - g - lam) * dnorm(eta) }
valideta <- function(eta) TRUE
link <- paste("probit.2asym(", g, ", ", lam, ")", sep = "")
structure(list(linkfun = linkfun, linkinv = linkinv,
mu.eta = mu.eta, valideta = valideta, name = link),
class = "link-glm")
}