[Rd] Error in glm(..., family=quasi(..., variance=list(...)))

Wollschlaeger, Daniel wo||@ch|@eger @end|ng |rom un|-m@|nz@de
Fri Apr 26 17:13:36 CEST 2019


In a glm() call using a quasi() family, one may define a custom variance function in the form of a "list containing components varfun, validmu, dev.resids, initialize and name" (quoting the help page for family). In trying to do so, I run into the following issue that I have not seen discussed previously:

x  <- runif(1000, min=0, max=1)
y  <- x + rnorm(1000, mean=0, sd=1)*x^(3/4)
vf <- function(mu) { abs(mu)^(3/4) }
vm <- function(mu) { rep(TRUE, length(mu)) }
dr <- function(y, mu, wt) { (y-mu)^2 }
it <- expression({ n <- rep.int(1, nobs); mustart <- y })
glm(y ~ x, family=quasi(link="identity", variance=list(varfun=vf, validmu=vm, dev.resids=dr, initialize=it, name="custom")))

This gives "Error in switch(vtemp, constant = { : EXPR must be a length 1 vector" from line 576 in file family.R (https://github.com/wch/r-source/blob/5a156a0865362bb8381dcd69ac335f5174a4f60c/src/library/stats/R/family.R#L576). I believe this is due to line 573 "vtemp <- substitute(variance)" and 574 "if (!is.character(vtemp)) vtemp <- deparse(vtemp)" where vtemp becomes a length 2 character vector because, by default, deparse() breaks lines at width.cutoff = 60L characters. In stepping through quasi() during debug, setting vtemp <- (vtemp, collapse=" ") on line 576 avoids the error.

A workaround from https://tolstoy.newcastle.edu.au/R/help/05/06/6795.html appears to be to define one's own complete quasi2() function with the desired variance function pre-stored.

Is this known/expected, or should I file a bug?

Many thanks and best regards

Daniel

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 14393)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.6.0



More information about the R-devel mailing list