I'm using Firth and Turner's BradleyTerry2 package for paired comparisons but have run into a mysterious problem using the main fitting function BTm. Here is a minimal data setup from their own example:
data(citations, package = "BradleyTerry2")
citations.sf <- countsToBinomial(citations)
names(citations.sf)[1:2] <- c("journal1", "journal2")
So at the console the following works:
citeModel <- BTm(cbind(win1, win2), journal1, journal2, data = citations.sf)
but the following does not work
f1 <- function(x){ BTm(cbind(win1, win2), journal1, journal2, data=x) }
f1(citations.sf)
while this (statistically nonsensical but) structurally similar linear model example does work, just as I would expect:
f2 <- function(x){ lm(log(win1/win2) ~ journal1, data=x) }
f2(citations.sf)
The error with f1 is "Error in eval(substitute(expr), data, enclos = parent.frame()): invalid 'envir' argument". But this is not telling me anything I can understand.
Thoughts?
traceback()
or debugging withoptions(error=recover)
? - Ari B. FriedmanBTm
andlm
you see thatBTm
uses the functionwith
whereaslm
does not. The use ofwith
inside functions is not advised because of exactly the mismatching of environment difficulties being reported. - IRTFMwith
that's the problem. I have found it surprisingly hard to build modeling packages in R that usedata
arguments and evaluate them correctly in all possible circumstances ... - Ben Bolker