ngreifer / WeightIt

WeightIt: an R package for propensity score weighting
https://ngreifer.github.io/WeightIt/
102 stars 12 forks source link

Covergence problems with glm() #31

Closed hjuerges closed 2 years ago

hjuerges commented 2 years ago

Dear Noah, thanks for writing this great package. When estimating a model with 100 times more treated than controls, I get warnings:

Warning messages: 1: glm.fit: algorithm did not converge 2: glm.fit: fitted probabilities numerically 0 or 1 occurred 3: Some extreme weights were generated. Examine them with summary() and maybe trim them with trim().

I generally understand why that might happen. However, when I run the exact same model outside weightit just with glm, this does not happen. The self-contained code given below replicates my problem.

Kind regards Hendrik


library(tidyverse) library(WeightIt)

data("nsw_mixtape", package = "causaldata") data("cps_mixtape", package = "causaldata")

df <- nsw_mixtape |> filter(treat==1) |> bind_rows(cps_mixtape) |> mutate(delta_Y=re78-re75)

W = weightit(treat ~ age + educ + black + hisp + marr + nodegree + re74, data = df, estimand = "ATT", method = "ps", include.obj = TRUE)

summary(W$ps)

df$pscore <- predict( glm(treat ~ age + educ + black + hisp + marr + nodegree + re74, family=binomial(), data = df), type="response")

summary(df$pscore)

hjuerges commented 2 years ago

Actually it should read "100 times more controls than treated". Sorry.

ngreifer commented 2 years ago

I think this should be fixed now. The cause was that I supplied bad starting values to glm(). Thanks for letting me know.