Comments (21)
@gavinsimpson When I try to run it on mgcv::bam
, I get:
> tidy(gam.rnn.0)
data frame with 0 columns and 0 rows
> glance(gam.rnn.0)
Error in `$<-.data.frame`(`*tmp*`, logLik, value = -1814706.9989743) :
replacement has 1 row, data has 0
from broom.
Your best bet is to write and contribute this code yourself if you can. Or it might be in https://gavinsimpson.github.io/gratia/ already, I haven't checked in a while.
from broom.
Has there been an update on a linkage between broom and mgcv? broom has been a fantastic package, but this is the one that is missing for my analysis.
from broom.
This is going to be tricky but not impossible and I'll volunteer to write mgcv::gam
methods for tidy()
, augment()
and glance()
. One way to manage this would be to have broom:::tidy.gam()
inspect x
using some simple heuristics to decide which package, gam or mgcv, produced the model fit. Then add a meta class to the object (say mgcv_gam
or gam_gam
) and then dispatch to tidy()
methods for those meta classes.
This would require moving the current code the tidy.gam()
to tidy.gam_gam
(or whatever meta class name was preferred). This way things should continue to work seamlessly not breaking backwards compatibility.
Thoughts? Suggestions for the meta class names?
from broom.
This would be great!
The only place we do something like this is tidy.list, which decides which function of tidy_optim
and tidy_xyz
(which are not exported) to use (see this issue for discussion). So we've used the pattern so far of having the S3 method make a decision of which non-S3 method to call.
Thus, perhaps the convention would be to have two non-exported functions called tidy_mgcv_gam
or tidy_gam_gam
, then:
tidy.gam <- function(x, ...) {
# heuristics to figure out which it is, then ...
if (is_from_mgcv) {
return(tidy_mgcv_gam(x))
} else {
return(tidy_gam_gam(x))
}
}
The docs are the last annoying part; perhaps ?gam_tidiers
should be connected to tidy_gam_gam
, but at the top specify it is just for gam::gam and link to ?mgcv_tidiers
with the rest? I'd rather avoid gam_gam_tidiers
since I am already tired of typing the syllables "gam-gam" this much (video), and since it preserves reverse compatibility of docs.
from broom.
I also suppose that a simpler alternative would be to stick the mgcv things in a separate pkg, importing selectively from broom. (There is bam()
and gamm()
in mgcv that we'd want methods for too but these don't conflict with gam the pkg.)
Whether what you propose is workable (I'm not very familiar with gam::gam()
and the things it returns, whereas I am with mgcv::gam()
) re documenting what the tidy
etc methods returned. But probably best to implement something and then see how that looks/works.
from broom.
I'd rather all tidiers live either in broom or in the package alongside the objects its tidying. So I'd be happy for tidy.gam to be placed in mgcv, but don't think it's worth spinning off to "mgcvbroom".
tidy.gam
is already written so if you write tidy_mgcv_gam
(and augment etc as necessary) we'll be set!
from broom.
Cool; I'll start on that!
from broom.
👍
from broom.
@gavinsimpson Hey, has any work been done on this? If not, I'm willing to work on it.
from broom.
@lselzer I actually have most of this done! This is the push I needed to finish it up, thanks
from broom.
If this isn't fixed it would be really helpful to have the tidy.gam
fail gracefully when an mgcv::gam
is passed. I was really confused as to why my output was disappearing.
from broom.
Thanks for providing this! Would it be possible to also support the output of mgcv::bam()
? This doesn't seem to work for me:
> library(broom)
> library(mgcv)
> sessionInfo()
R version 3.2.4 Revised (2016-03-16 r70336)
Platform: x86_64-apple-darwin12.5.0 (64-bit)
Running under: OS X 10.8.5 (Mountain Lion)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] mgcv_1.8-14 nlme_3.1-125 broom_0.4.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.6 lattice_0.20-33 tidyr_0.6.0 psych_1.6.6
[5] dplyr_0.5.0 assertthat_0.1 grid_3.2.4 R6_2.1.3
[9] plyr_1.8.4 DBI_0.5 magrittr_1.5 stringi_1.1.1
[13] lazyeval_0.2.0 reshape2_1.4.1 Matrix_1.2-4 tools_3.2.4
[17] stringr_1.1.0 parallel_3.2.4 compiler_3.2.4 mnormt_1.5-4
[21] tibble_1.2
> data(mtcars)
# This works
> fit <- gam(mpg ~ cyl + s(hp), data=mtcars)
> tidy(fit)
term edf ref.df statistic p.value
1 s(hp) 5.506492 6.601482 2.257316 0.06910746
> glance(fit)
df logLik AIC BIC deviance df.residual
1 7.506492 -72.95905 162.9311 175.3994 179.0741 24.49351
# But this doesn't
> fit <- bam(mpg ~ cyl + s(hp), data=mtcars)
> tidy(fit)
data frame with 0 columns and 0 rows
> glance(fit)
Error in `$<-.data.frame`(`*tmp*`, "logLik", value = -77.1853352336568) :
replacement has 1 row, data has 0
According to ?bam
the value is a gam
object so I'm guessing it shouldn't be to difficult to add this.
Thanks!
from broom.
Is there any plan to make tidy compatible with gamm() from mgcv?
from broom.
It seems that the method doesn't work for gam
models with family = ziplss()
. Here is an example
data(Owls, package="glmmTMB")
Owls = plyr::rename(Owls, c(SiblingNegotiation="NCalls"))
Owls = transform(Owls, ArrivalTime=scale(ArrivalTime, center=TRUE, scale=FALSE))
m1.gam = gam(list(NCalls ~ (FoodTreatment + ArrivalTime) * SexParent + offset(logBroodSize) + s(Nest, bs = "re"),
~ 1), data = Owls, family = ziplss(), method = "REML")
tidy(m1.gam)
from broom.
Was this ever built in to either broom
or mgcv
/gamm4
? If so, how do I call it?
from broom.
@angoodkind This was merged a couple of years ago, although as Mollie mentions above, this may not work for all of mgcv::gam models and related functions.
You ought to be able to just use tidy
, glance
etc as for any other model supported by broom.
from broom.
@angoodkind it wasn't clear to me that by "this" you meant bam()
. No; as far as I can tell there is no support yet for bam()
or for some of the newer families and features of mgcv. I'm happy to implement this stuff, but, as mentioned in #239, this would probably be more efficient if the code were ins a separate broom support package rather than the main package.
from broom.
@gavinsimpson. Thanks. I might take a crack at that, as well.
from broom.
3 years later... has there been tidy()
support developed for bam()
? outside or inside broom?
from broom.
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.
from broom.
Related Issues (20)
- tidy.varest contains wrong (repeated) coefficients? HOT 4
- transition to cli errors
- add / polish alt text
- Regression Model Accuracy Metrics for Objects of class oohbchoice HOT 2
- No tidy method for objects of class npregression HOT 2
- Issues regarding CI computing for lm.beta models HOT 2
- augment error with `na.action = na.exclude` in `lm` HOT 1
- add conf.int and exponentiate arguments to `tidy.cch()`
- Error: No tidy method for objects of class npregression HOT 2
- Possible bug with `tidy() ` function on `lm.beta` object HOT 3
- augment() fails HOT 3
- address GHA failures re: minimum R version HOT 1
- Bug in `tidy.survfit()` coming in the next release of the {survival} pkg HOT 5
- Create tidy method HOT 5
- Support for glmtoolbox (GEE) HOT 2
- Allow choosing the type of residuals in `tidy.betareg()` HOT 3
- GHA failure re: archived package HOT 1
- dependency install errors on GHA HOT 3
- Release broom 1.0.6 HOT 1
- Glance.lm gives does not give fstatistic/ f stat based values when used on a 0 intercept model.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from broom.