R model fitting routine fails to run in a function -



R model fitting routine fails to run in a function -

i'm using firth , turner's bradleyterry2 bundle paired comparisons have run mysterious problem using main fitting function btm. here minimal info setup own example:

data(citations, bundle = "bradleyterry2") citations.sf <- countstobinomial(citations) names(citations.sf)[1:2] <- c("journal1", "journal2")

so @ console next works:

citemodel <- btm(cbind(win1, win2), journal1, journal2, info = citations.sf)

but next not work

f1 <- function(x){ btm(cbind(win1, win2), journal1, journal2, data=x) } f1(citations.sf)

while (statistically nonsensical but) structurally similar linear model illustration does work, expect:

f2 <- function(x){ lm(log(win1/win2) ~ journal1, data=x) } f2(citations.sf)

the error f1 "error in eval(substitute(expr), data, enclos = parent.frame()): invalid 'envir' argument". not telling me can understand.

thoughts?

thanks linking post on existing bug study [#2294] objects not found when btm not called in global environment.

when setting info internally, btm looks objects in environment of formula , in global environment. if formula not specified btm, formula defined internally and, implemented, inherits environment constructed when btm called, rather environment btm called.

until round fixing this, there simple work-around - specify formula when using btm within function, environment of formula created when function called. e.g.

> f1 <- function(x){ btm(cbind(win1, win2), journal1, journal2, ~.., data=x) } > f1(citations.sf) bradley terry model fit glm.fit call: btm(outcome = cbind(win1, win2), player1 = journal1, player2 = journal2, formula = ~.., info = x) coefficients: ..comm statist ..jasa ..jrss-b -2.9491 -0.4796 0.2690 degrees of freedom: 6 total (i.e. null); 3 residual null deviance: 1925 residual deviance: 4.293 aic: 46.39

r

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

How do you set up a perforce server to work over the internet? -

ios - Lagging ScrollView with UIWebview inside -