Comments (3)
I think it's a similar issue like here: leeper/margins#92 and I guess Stata is getting the CI wrong here. It looks like predictions and SE are on the (transformed) response scale, and then est +/- 1.96 * SE
may lead to CI that are out of bound (e.g. above 1 or below 0 for predicted probabilities, or predicted IRR below 0 etc.).
See example:
newdata <- data.frame(
working = as.factor(c(0, 1, 0, 1, 0, 1)),
income = c(100, 100, 1000, 1000, 10000, 10000)
)
prdat <-
stats::predict(
logit,
newdata = newdata,
type = "response",
se.fit = TRUE
)
pr <- as.vector(prdat)
cbind(
est = pr,
lower = pr - qnorm(.975) * sqrt(attr(prdat, "var")),
upper = pr + qnorm(.975) * sqrt(attr(prdat, "var"))
)
# almost match STATA output, but computation is wrong
#> est lower upper
#> 1 0.4906395 0.2211180 0.7601610
#> 2 0.5794210 0.2486688 0.9101731
#> 3 0.4893027 0.2234625 0.7551430
#> 4 0.5773197 0.2507525 0.9038869
#> 5 0.4759466 0.2458485 0.7060447
#> 6 0.5561654 0.2710491 0.8412817
Here the "correct" approach:
prdat <-
stats::predict(
logit,
newdata = newdata,
type = "link",
se.fit = TRUE
)
linv <- sjstats::link_inverse(logit)
pr <- as.vector(prdat)
cbind(
est = linv(pr),
lower = linv(pr - qnorm(.975) * sqrt(attr(prdat, "var"))),
upper = linv(pr + qnorm(.975) * sqrt(attr(prdat, "var")))
)
# The output from ggpredict()
#> est lower upper
#> 1 0.4906395 0.2467707 0.7390463
#> 2 0.5794210 0.2617570 0.8425931
#> 3 0.4893027 0.2484972 0.7351775
#> 4 0.5773197 0.2637649 0.8388980
#> 5 0.4759466 0.2652582 0.6955592
#> 6 0.5561654 0.2830412 0.7990959
from ggeffects.
Okay, great. Thanks for your explanation and example.
from ggeffects.
FYI, I've added a vignette on this topic:
https://strengejacke.github.io/ggeffects/articles/stata.html
from ggeffects.
Related Issues (20)
- Averaged (marginal) predictions using {marginaleffects}
- missing errors when using fixest models HOT 4
- Colors not showing correctly when specifiying "show_data = T" in the plot method of ggpredict object HOT 1
- ggpredict produces single predicted value for continuous variable HOT 4
- Question about sources of uncertainty when estimatinc confidence intervals HOT 2
- Johnson-Neyman FDR Correction HOT 10
- Relicensing {ggeffects} HOT 5
- Error of ggpredict with glmmPQL HOT 3
- Population-level predictions for gam/comparable predictions for gam and glmer fits HOT 5
- plot a subset for 4-way-interactions HOT 3
- New incompatibilities with emmeans for quantile regression HOT 4
- ggpredict() does not recognise `` quoted response variable with a : symbol in mixed models HOT 1
- "Collapse_group" produces many data points HOT 4
- ggpredict doesn't work for vglm models where multiple.responses = TRUE HOT 1
- Problem with ggpredict when fixing a parameter value in glmmTMB HOT 2
- ggpredict() returns 90% CI when ppd = TRUE for rstanarm models, but labeled as 95% HOT 1
- Difference between insight::get_predicted and ggeffects::ggpredict when calculating PI
- ggpredict outputs only 6 values at the time HOT 1
- `tinytable` S4 refactor: output formats HOT 5
- Issue with plotting an interaction with a quadratic variable through plot_model from a multi-level and logistic model 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 ggeffects.