Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201941

Fixed effects with ggeffect() in R

$
0
0

I'm wondering if anyone has any experience using ggeffect() with lots of fixed effects. Although my independent variable is strongly related to my dependent variable, I get these massive confidence intervals when I add in state fixed effects.

A toy example:

set.seed(200)

indvar <- runif(500, min = 0, max = .5)
state <- as.factor(rep(c(1:50), 10))
statev <- as.integer(state) * runif(500, 0, 0.02)
depvar <- round(indvar + statev)

data <- data.frame(indvar, state, depvar)

m1 <- glm(depvar ~ indvar, data = data, family = "binomial")

margin <- ggeffect(m1, "indvar")

plot(margin)

Plot with expected confidence intervals

This gives me nice clean confidence intervals around the independent variable. However, as soon as I add in the state fixed effects, the confidence interval stretches essentially from 0 to 1, even though there remains a super strong relationship.

m2 <- glm(depvar ~ indvar + state, data = data, family = "binomial")

margin <- ggeffect(m2, "indvar")

plot(margin)

Plot with super wide confidence intervals

Thoughts much appreciated!


Viewing all articles
Browse latest Browse all 201941

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>