15.5 Poisson regression with an extra binary predictor
Simulate \(y\) data for a Poisson regression with one continuous predictor \(x_1\) and one a binary predicor \(x_2\). This is Poisson regression with a varying intercept.
Code
dg$y =rpois(n = n, lambda =exp(0+0.5*x1 +1*x2))g =ggplot(dg, aes(x = x1, y = y, color =as.factor(x2), group = x2)) +geom_jitter(show.legend = F, alpha =0.1, width =0, height =0.3) +geom_smooth(linewidth =3)g %>%pub(xlim =c(0, 1 ), ylim =c(0, 14))