Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using confint.gnm() inside a function #11

Open
dwoll opened this issue Feb 14, 2019 · 3 comments
Open

Using confint.gnm() inside a function #11

dwoll opened this issue Feb 14, 2019 · 3 comments

Comments

@dwoll
Copy link

dwoll commented Feb 14, 2019

I believe this is related to issue 1. Consider

library(gnm)
f <- function(d) {
    fit <- gnm(Freq ~ vote, eliminate=class, family=poisson, data=d)
    confint(fit)
}
f(as.data.frame(cautres))

For me, this fails because d could not be found - presumably because some function downstream from update.gnm() (called by profile.gnm()) does not search in the correct environment. I'm sorry I'm not able to locate the exact source of the error, but I don't fully understand what's going on with environments in the following evaluated calls to gnm(), gnmTerms() etc.

Thanks for quickly fixing the previous issue and for your ongoing efforts!

@kauedesousa
Copy link

Hi @dwoll

Seems that it works well when you avoid the argument "eliminate". Do you have any especial reason for using this argument?

library(gnm)
f <- function(d) {
fit <- gnm(Freq ~ vote, family = poisson, data = d)
confint(fit)
}
f(as.data.frame(cautres))

@dwoll
Copy link
Author

dwoll commented Feb 14, 2019

@kauedesousa Yes, I need the conditional Poisson regression because I have to stratify for a lot of factors that are, by themselves, uninteresting. However, even without the eliminate option, I still get an error from terms.formula().

@hturner
Copy link
Owner

hturner commented Feb 14, 2019

Okay, this is going to be harder to get right. This is a workaround for your example:

library(gnm)
f <- function(d) {
    fit <- do.call("gnm", list(Freq ~ vote, eliminate=quote(class), family=poisson, data=d))
    confint(fit)
}
f(as.data.frame(cautres))

Hopefully you can adapt that for your application. If you need to specify the eliminated variable you can do it as follows:

f <- function(d, x) {
    fit <- do.call("gnm", list(Freq ~ vote, eliminate=substitute(x), family=poisson, data=d))
    confint(fit)
}
f(as.data.frame(cautres), class)

I think it will be a little while before I can implement a proper fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants