I think you want
linkfun <- function(mu){mu/varcol}
linkinv <- function(eta){eta*varcol)}
etc, that is a function of a single argument. Also, you can use lexical
scope to capture varcol, as in the above: it will be in the environment of
linkfun/inv. You did not set its environment as MASS does, and you do not
need to. (MASS could have been written differently if it did not share
code with S.)
On Tue, 9 Mar 2004, Stephane DRAY wrote:
> Hello,
> I would like to create my own family for glm modelling
>
> If we consider a matrix Y, I would like to model Yij/var(Yj) with an
> inverse variance link.
> I have create my own family inspired by the negative.binomial of MASS:
>
> #########################################################
> myfamily=function (varcol)
> {
> env <- new.env(parent = .GlobalEnv)
>
> assign(".varcol",varcol,envir=env)
> famname="myfamily"
> link="inv col var"
> linkfun=function(.varcol,mu){mu/(.varcol)}
> linkinv=function(.varcol,eta){eta*(.varcol)}
> variance <- function (mu) rep.int(1, length(mu))
> validmu <- function (mu) TRUE
>
> dev.resids <- function (y, mu, wt) wt * ((y - mu)^2)
> aic <- function (y, n, mu, wt, dev) sum(wt) * (log(dev/sum(wt) * 2
*
> pi) + 1) + 2
> mu.eta=function (eta) rep.int(1, length(eta))
> initialize <- expression({
> n <- rep.int(1, nobs)
> mustart <- y
> })
>
> environment(variance) <- environment(validmu) <-
> environment(dev.resids) <- environment(aic) <- env
>
> structure(list(family = famname, link = link, linkfun = linkfun,
> linkinv = linkinv, variance = variance, dev.resids = dev.resids,
> aic = aic, mu.eta = mu.eta, initialize = initialize,
> validmu = validmu), class = "family")
> }
> #####################################################
>
> But it does not work when I try it
>
> > Y=matrix(runif(50),10,5)
> > glm(as.vector(t(Y))~x,family=myfamily(rep(apply(Y,2,var),10)))
> Error in family$linkfun(mustart) : Argument "mu" is missing, with
no default
> >
>
> Hope that someone could help me,
>
> Thanks in advances,
> Sincerely.
>
> St?phane DRAY
>
--------------------------------------------------------------------------------------------------
>
> D?partement des Sciences Biologiques
> Universit? de Montr?al, C.P. 6128, succursale centre-ville
> Montr?al, Qu?bec H3C 3J7, Canada
>
> Tel : 514 343 6111 poste 1233
> E-mail : stephane.dray at umontreal.ca
>
--------------------------------------------------------------------------------------------------
>
> Web
http://www.steph280.freesurf.fr/
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595