Comments (8)
More straightforward comparisons:
library(nestedLogit)
library(ggeffects)
library(effects)
ggpredict(m, c("hincome", "children")) |> plot() # OK
ggeffect(m, "hincome") |> plot() # bugged!
Effect("hincome", m) |> plot() # OK
Also tried a multinomial model; that seems OK
from ggeffects.
I must confess that the two functions "ggeffect()" and "ggemmeans()" should deserve a little more love. I started working on this package when I was rather new to R and had no idea of method dispatch. Actually, like John pointed out, I should refactor large parts of the package and make the functions generics, so the code will become a bit clearer and easier to maintain.
But that's a long-term goal, I think related to this issue, I'll indeed "special-casing" nestedLogit.
from ggeffects.
btw, is this in the CRAN or GitHub version of nestedLogit?
from ggeffects.
Ok, got it, the CRAN version was just updated. Btw, can you explain the large differences between what predict()
and Effect()
return?
library(nestedLogit)
data("Womenlf", package = "carData")
m <- nestedLogit(partic ~ hincome + children,
logits(
work = dichotomy("not.work", c("parttime", "fulltime")),
full = dichotomy("parttime", "fulltime")
),
data = Womenlf
)
effects::Effect("hincome", m, xlevels = list(hincome = seq(10, 40, 10)))
#>
#> hincome effect (probability) for not.work
#> hincome
#> 10 20 30 40
#> 0.5472608 0.6485550 0.7380345 0.8113586
#>
#> hincome effect (probability) for parttime
#> hincome
#> 10 20 30 40
#> 0.1656323 0.2206211 0.2177867 0.1764002
#>
#> hincome effect (probability) for fulltime
#> hincome
#> 10 20 30 40
#> 0.28710686 0.13082390 0.04417872 0.01224116
predict(m, newdata = ggeffects::new_data(m, terms = c("hincome[10:40, by=10]")))
#>
#> predicted response-category probabilties
#> not.work parttime fulltime
#> 1 0.2864384 0.05907221 0.6544894
#> 2 0.3799734 0.12943673 0.4905899
#> 3 0.4833619 0.22495878 0.2916793
#> 4 0.5881947 0.28527228 0.1265330
#>
#> predicted response-category logits
#> not.work parttime fulltime
#> 1 -0.91274548 -2.7681058 0.63883223
#> 2 -0.48966118 -1.9059482 -0.03764493
#> 3 -0.06657687 -1.2369990 -0.88724209
#> 4 0.35650744 -0.9184576 -1.93196717
#>
#> standard errors of predicted probabilities
#> not.work parttime fulltime
#> 1 0.05355137 0.02685851 0.05580606
#> 2 0.06155651 0.04714845 0.06655909
#> 3 0.09546538 0.09563873 0.10160578
#> 4 0.13317026 0.12816405 0.09792827
#>
#> standard errors of predicted logits
#> not.work parttime fulltime
#> 1 0.2620040 0.4832173 0.2467842
#> 2 0.2612826 0.4184172 0.2663307
#> 3 0.3822848 0.5485371 0.4917936
#> 4 0.5497867 0.6285879 0.8860491
Created on 2023-06-23 with reprex v2.0.2
from ggeffects.
I think John will have to look at your example where you use:
predict(m, newdata = ggeffects::new_data(m, terms = c("hincome[10:40, by=10]")))
predict
simply calculates the predicted probababilities, SEs etc evaluated at the values given by newdata
. (It can also do this for the individual nested dichotomies, but that's not the issue here.)
Effect
, when not all predictors are specified, calculates the predicted probs. at the margins/average of the omitted variables.
from ggeffects.
As I understand it, and without checking in detail, predict()
sets children
to "absent"
(its first level) while Effect()
computes effects marginalized over the two levels of children
. Labour-force participation is higher when children are absent.
BTW, to see confidence limits computed by Effect()
for comparison, use summary()
.
from ggeffects.
With respect to making the functions in ggeffects generic: I'm not familiar enough with your package to be confident in offering advice, but from what I've seen, the main functions, like ggeffect()
, could be simple S3 generics and the current versions of the functions, or something very close to them, could just become the default methods. That way, what works now should continue to work, and it would be possible to introduce specific methods for cases, like "nestedLogit"
objects that currently don't work.
from ggeffects.
Thanks for following up!
from ggeffects.
Related Issues (20)
- Errors with new ggeffects version & zero-inflated negative binomial model (glmmTMB) HOT 4
- `data_tabulate()` for crosstables prints NA-proportions when no values are available
- zi_prob-type predictions with new predict_response function HOT 7
- how does test_predictions deal with categorical non-focal terms? HOT 7
- ggeffects capabilities with spatail regression model objects HOT 2
- Error when specifying focal terms in ggeffect() HOT 2
- Wrong labels for `test_prediction()` with `margin`. HOT 1
- Fix printing issue with cleaning values
- r ggeffect random sample linear spline HOT 1
- Bug in order of comparisons / labels when character vector is used in model
- Plotting ordinal logistic predicted effects on latent scale of ordinal outcome? HOT 3
- test_predictions not working with gamm4 model output HOT 4
- predict_response removes unobserved dv levels from clmm? HOT 3
- earth (MARS) support HOT 1
- reference issue in "Introduction_randomeffects.Rmd"
- plot add data=TRUE not making sense HOT 6
- Error: Objects of class `ggeffects` are not yet supported. HOT 5
- "Could not find model object to extract residuals." fails with a pipe HOT 4
- Curvilinear interaction is significant, then how do I get the significances of the linear term and quadratic term of the focal variable at the +1SD, mean, -SD points of moderator? HOT 7
- Problems with predictions from "robustbase" package ("hypothesis_test") HOT 1
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 ggeffects.