Comments (5)
Do you have a reproducible example?
from insight.
I will try to get one. I am using a custom function to fit and save models in parallel and then load and name the resulting models so I would have to simplify certain things from the pipeline to get it to reproduce without publishing a bunch of tangentially related code.
from insight.
So I had to revisit the issue in a new project and I went ahead and isolated the issue:
ibrary(tidyverse)
library(lme4)
library(performance)
data(troutegg,package="faraway")
#This does not work
fit_mod <- function(formula,weights,data,family,subset){
mod <-glmer(as.formula(formula),weight=eval(parse(text=weights)),
data=data,family= eval(parse(text = family)),subset=eval(parse(text=subset)))
return(mod)
}
mod <- fit_mod(formula = "survive/total~period+(1|location)",
weights = "total",
data=troutegg,
family="binomial('logit')",
subset = "total>0")
performance::binned_residuals(mod)
#This works
mod2 <-glmer(as.formula("survive/total~period+(1|location)"),weight=eval(parse(text="total")),
data=troutegg,nAGQ=0,family= eval(parse(text = "binomial('logit')")))
performance::binned_residuals(mod2)
#Digging deeper, problem comes from
insight::get_data(mod)
#This does not work too...
fit_mod_alt <- function(formula,data,weights,troutegg,family,subset){
mod <-glmer(as.formula(formula),weight=eval(parse(text=weights)),
data=get(data,envir = .GlobalEnv),family= eval(parse(text = family)),subset=eval(parse(text=subset)))
return(mod)
}
mod3 <- fit_mod_alt(formula = "survive/total~period+(1|location)",
weights = "total",
data="troutegg",
family="binomial('logit')",
subset = "total>0")
performance::binned_residuals(mod3)
If I understand correctly, the data for the model shows up as data internally when fitted with the fit_mod function (as opposed to troutegg), which causes issues with the get_data function from insight that is used internally within some performance library functions such as binned_residuals
from insight.
I also tried assigning troutegg to data to see if that helps, it also did not
#This also does not work
data <- troutegg
fit_mod_alt <- function(formula,data,weights,troutegg,family,subset){
mod <-glmer(as.formula(formula),weight=eval(parse(text=weights)),
data=data,family= eval(parse(text = family)),subset=eval(parse(text=subset)))
return(mod)
}
mod3 <- fit_mod_alt(formula = "survive/total~period+(1|location)",
weights = "total",
data=data,
family="binomial('logit')",
subset = "total>0")
performance::binned_residuals(mod3)
from insight.
So I finally figured out the root of the issue:
The get_data function does not work intended when I used the subset argument. It works OK when I subset within the as an input (example with tidyverse filter) as opposed to the subset argument. It is likely a none-issue for 99% of the cases.
#Works!
mod4 <- fit_mod_alt(formula = "survive/total~period+(1|location)",
weights = "total",
data= troutegg,
family="binomial('logit')")
insight::get_data(mod4)
#Alternative to subset with tidyverse
mod5 <- fit_mod_alt(formula = "survive/total~period+(1|location)",
weights = "total",
data= troutegg %>% filter(eval(parse(text="location !=5"))),
family="binomial('logit')")
insight::get_data(mod5)
from insight.
Related Issues (20)
- test code needs glmmTMB HOT 3
- Test for `find_weights()` failing on CRAN HOT 1
- `find_transformation` incorrectly detects power transformations HOT 2
- `find_predictors()` with multiple `strata()` variables in `clogit()` HOT 1
- Issues with CRAN version HOT 1
- is_singular with lme models uses a lot of memory HOT 1
- glm model misreported as bernoulli HOT 2
- `brms::gr()` is not supported HOT 1
- AIC varies with order of factors in binomial? HOT 8
- `get_variance()` and `null_model()` functions not working depending on the way you call the objects of your model HOT 1
- Add family == "gaulss" to `find_formula` and `find_variables` for `mgcv::gam` HOT 2
- ICC for brms Beta model: returning NA HOT 11
- Detect the package that is needed to create or predict a model object HOT 8
- `find_predictors()`: false positives with some user inputs in GAM splines HOT 2
- rename marginaleffects' `s.value` column name
- Fix `apply_table_theme()`
- `insight::find_variables()`: error with `brms` and `mm()` HOT 8
- Tests failing on CRAN HOT 1
- Add support for package "did" HOT 2
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 insight.