ggpredict produces single predicted value for continuous variable

49 Views Asked by At

I am trying to get the predicted probabilities from a rare-events logit.

When I try ggpredict, I get a single data-point, instead of the representative values I would expect (see: https://github.com/strengejacke/ggeffects/issues/220)

I have tried updating all the packages from their github sources.

Dataset can be found here: https://ucdp.uu.se/downloads/nsos/ucdp-onesided-231-csv.zip

rm(list = ls())
library(foreign)
library(ggeffects)
library(logistf) 

df = read.csv("~/ucdp-onesided-211.csv")
df$best_fatality_estimate = log(df$best_fatality_estimate + 1)

#Making some of the values 0, to reproduce the error
index = sample(1:nrow(df), 100, replace=FALSE) 
df$best_fatality_estimate[index] = 0 

#Making up some independent and dependent variables 
df$dv = rbinom(nrow(df), 1, 0.1)
df$iv = runif(nrow(df), min=0, max=100)
df$iv2 = rnorm(nrow(df), 100, sd=20)

reg <- logistf(dv~best_fatality_estimate+year  + iv + iv2, data = df)

ggeffects::ggpredict(reg, terms="best_fatality_estimate")

enter image description here

ggeffects::ggpredict(reg, terms="best_fatality_estimate [all]")

enter image description here

Interestingly, ggeffects works:

ggeffects::ggeffect(reg, terms="best_fatality_estimate")

enter image description here

0

There are 0 best solutions below