Giter VIP home page Giter VIP logo

reggie's Issues

Error in reg(ChickWeight, weight ~ Time + Diet, vcov_cluster = ~ Chick, vcov_type = "boot")

As you mentioned in the README, this regression does not work and this is the error message:

object of type 'closure' is not subsettable

I believe it's probably from line 52:

data = data[sample(seq_len(nrow(data)), nrow(data), TRUE), ], ...))

data is a function to load example datasets, and I think that this is where it goes wrong (you're trying to subset a function). I tried replacing data with dataset and when running the unit tests this is what I get:

==> devtools::test()

Loading reggie
Loading required package: testthat
Testing reggie
✔ | OK F W S | Context
✖ |  0 1     | Correct Data Structures Returned [3.5 s]
─────────────────────────────────────────────────────────────────────────────────────────────────────────
tests.R:19: error: (unknown)
object 'dataset' not found
1: reg(ChickWeight, weight ~ Time + Diet, vcov_cluster = ~Chick, vcov_type = "boot") at /home/bro/Documents/reggie/tests/testthat/tests.R:19
2: sandwich::vcovBS(x = mod, cluster = cluster_vec, R = boot_iterations) at /home/bro/Documents/reggie/R/reg.R:43
3: vcovBS.default(x = mod, cluster = cluster_vec, R = boot_iterations)
4: eval(up, envir = env, enclos = parent.frame())
5: eval(up, envir = env, enclos = parent.frame())
6: stats::glm(formula = formula, data = dataset, subset = .vcovBSenv$.vcovBSsubset)
7: eval(mf, parent.frame())
8: eval(mf, parent.frame())
9: stats::model.frame(formula = formula, data = dataset, subset = .vcovBSenv$.vcovBSsubset, drop.unused.levels = TRUE)
10: model.frame.default(formula = formula, data = dataset, subset = .vcovBSenv$.vcovBSsubset, drop.unused.levels = TRUE)
11: is.data.frame(data)

I don't know if this helps, but thought I'd mention.

Reconsider Data / Formula order in call

I get the point of the experiment with argument order, but I'm not sure %>% pipelines will be the dominant use case. And if they are not, then it's probably not a good idea to mess with a strong convention that is maintained by most model-fitting R packages.

Plus, the benefit of breaking convention doesn't seem very high, given that one can just do this:

dat %>% lm(y ~ x, .)

Proof of concept: reggie and texreg

This morning, another student came to my office asking how to produce tables with clustered standard errors. So here I am again.

I just wanted to point out a neat feature that I contributed to texreg a little while ago: When the package doesn't recognize the model type, it tries to extract info using broom. Thanks to that, we can easily present side-by-side estimates from reggie by creating a couple very simple broom helpers:

library(reggie)
library(texreg)
library(broom)

# Broom Helper Functions
tidy.reg <- function(x, ...) {
    ret <- data.frame('term' = row.names(x$coefficients),
                      'estimate' = x$coefficients[, 1], 
                      'std.error' = x$coefficients[, 2], 
                      'statistic' = x$coefficients[, 3], 
                      'p.value' = x$coefficients[, 4], 
                      row.names = NULL,
  stringsAsFactors = FALSE)
    return(ret)
}
glance.reg <- function(x, ...) {
    ret <- glance(x$model)
    return(ret)
}

# Simulated Data
dat <- data.frame('x' = rnorm(1000),
                  'z' = sample(letters, 1000, replace = TRUE))
dat$y <- ifelse(dat$x + rnorm(1000) > 0, 1, 0)

# Fitting models
models <- list()
models[['GLM']] <- glm(y ~ x, data = dat, family = binomial())
models[['Cluster']] <- reg(y ~ x, data = dat, family = binomial(), vcov_cluster = ~ z)
models[['HC1']] <- reg(y ~ x, data = dat, family = binomial(), vcov_type = 'HC1')

# Summary
screenreg(models, digits = 4)

============================================================
                 GLM            Cluster        HC1 
------------------------------------------------------------
(Intercept)        -0.1355        -0.1355        -0.1355
                   (0.0774)       (0.0762)       (0.0774)
x                   1.6487 ***     1.6487 ***     1.6487 *** 
                   (0.1099)       (0.1060)       (0.1138)
------------------------------------------------------------
AIC              1013.3481      1013.3481      1013.3481
BIC              1023.1637      1023.1637      1023.1637
Log Likelihood   -504.6741      -504.6741      -504.6741
Deviance         1009.3481      1009.3481      1009.3481
Num. obs.        1000
Deviance (Null)                 1382.6922      1382.6922
df.null                          999            999 
DF Resid.                        998            998 
============================================================
*** p < 0.001, ** p < 0.01, * p < 0.05

Not perfect, but pretty close...

Model support

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.