Gamma and Inverse Gaussian models don't replicate Stata results exactly
Opened this issue · 0 comments
nathanielolin commented
Working on #28. They're close, but not exact.
> data(margex)
> margex$ycn[margex$ycn == 0] <- 1
> mod <- glm(ycn ~ treatment + age + distance, data = margex, family = inverse.gaussian)
>
> z1 <- marg(mod, var_interest = 'age', at_var_interest = seq(20, 60, 5),
+ type = 'levels')[[1]]
>
> z2 <- marg(mod, var_interest = 'treatment', type = 'effects')[[1]]
>
> stata <- aiEstimation::mod_marg(
+ 'glm ycn i.treatment c.age c.distance, family("igaussian")',
+ margs = list(age = sprintf("margins, at(age = (%s))",
+ paste(seq(20, 60, 5), collapse = ", ")),
+ treat = sprintf("margins, dydx(treat)")),
+ df = margex
+ )
>
> z1[, c("Label", "Margin", "Standard.Error", "P.Value")]
Label Margin Standard.Error P.Value
1 age = 20 73.68419 0.8351090 0
2 age = 25 73.86944 0.6894061 0
3 age = 30 74.05614 0.5564396 0
4 age = 35 74.24433 0.4508355 0
5 age = 40 74.43401 0.3988748 0
6 age = 45 74.62522 0.4245450 0
7 age = 50 74.81797 0.5194893 0
8 age = 55 75.01229 0.6567655 0
9 age = 60 75.20819 0.8174053 0
> stata$margins$age
variable margins_b margins_se p
1 1._at 73.68441 0.8330135 0
2 2._at 73.86966 0.6876766 0
3 3._at 74.05638 0.5550439 0
4 4._at 74.24458 0.4497050 0
5 5._at 74.43428 0.3978749 0
6 6._at 74.62550 0.4234810 0
7 7._at 74.81827 0.5181878 0
8 8._at 75.01260 0.6551204 0
9 9._at 75.20852 0.8153583 0
>
> z2[, c("Label", "Margin", "Standard.Error", "P.Value")]
Label Margin Standard.Error P.Value
1 treatment = 0 0.00000 0.0000000 NaN
2 treatment = 1 15.42396 0.8370207 7.946186e-76
> stata$margins$treat
variable margins_b margins_se p
1 0b.treatment 0.00000 NA NA
2 1.treatment 15.42372 0.8349224 3.39e-76
Similar issue with Gamma models