reggie icon indicating copy to clipboard operation
reggie copied to clipboard

Model support

Open leeper opened this issue 8 years ago • 2 comments

Priority areas:

  • [ ] {plm}
  • [ ] Stata's broader xt* family

But, need to decide whether to make these separate functions (named as they are in Stata) or pass a FUN argument specifying which estimation function to call.

leeper avatar Jan 23 '18 20:01 leeper

Option (b) basically sounds like what Zelig tried to do. My reading of that project, is that a major impediment to maintaining a useable package was continually following up on updates to the underlying packages.

The benefit of the separate named functions approach is that reggie can really be a slim wrapper.

The disadvantage is that you won't have a "unified" user interface, so the users need to know something about the underlying packages.

I guess it depends on the scope of the project you have in mind. Do you really want to unify function calls from the user's perspective, or are you happy with them looking up the documentation for plm::vcovBK()?

If the latter, you could just add a prefix to the functions you're wrapping: plm -> regplm:

library(plm)
data(EmplUK)
dat <- pdata.frame(EmplUK, c('firm', 'year'))
regvcov <- function(x) UseMethod("regvcov", x, ...)
regvcov.plm <- function(x, vcov_type, ...) {
    if (vcov_type == 'HC') {
        vc <- plm::vcovHC(x, ...)
    } else if (vcov_type == 'G') {
        vc <- plm::vcovG(x, ...)
    } else if (vcov_type == 'BK') {
        vc <- plm::vcovBK(x, ...)
    } else if (vcov_type == 'SCC') {
        vc <- plm::vcovSCC(x, ...)
    } else if (vcov_type == 'NW') {
        vc <- plm::vcovNW(x, ...)
    } else if (vcov_type == 'DC') {
        vc <- plm::vcovDC(x, ...)
    } else {
        stop('Only the following vcov_type are supported for object of class plm: HC, G, BK, SCC, NW, DC')
    }   
    return(vc)
}
regplm <- function(...,  vcov_type = if (is.null(vcov_cluster)) "const" else "HC0", vcov_cluster = NULL, boot_iterations = 1000L, digits = 2L, signif.stars = FALSE) {
    mod <- plm::plm(...)
    mod$vc <- regvcov.plm(mod, vcov_type = vcov_type, vcov_cluster = vcov_cluster, boot_iterations = boot_iterations, ...)
    return(mod)
}
f = emp ~ wage + output
mod = regplm(formula = f, data = dat, model = 'within', vcov_type = 'SCC')

vincentarelbundock avatar Jan 23 '18 23:01 vincentarelbundock

Obviously, if the number of models you want to cover is limited and the underlying packages are mature, this isn't a big deal, maybe.

vincentarelbundock avatar Jan 23 '18 23:01 vincentarelbundock