leeper / reggie Goto Github PK
View Code? Open in Web Editor NEWStata-like Regression Functionality for R
License: Other
Stata-like Regression Functionality for R
License: Other
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.
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, .)
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...
reg(mtcars, mpg ~ cyl, weights = runif(nrow(mtcars), 0, 1))
fails with the crazy ..1
error. Will probably need to do some match.call()
magic.
Priority areas:
xt*
familyBut, 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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.