Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Behavior with vcov #356

Closed
mgoplerud opened this issue Sep 18, 2022 · 1 comment
Closed

Unexpected Behavior with vcov #356

mgoplerud opened this issue Sep 18, 2022 · 1 comment

Comments

@mgoplerud
Copy link

Hello,

I noticed some unexpected behavior with vcov. If you adjust any of the arguments, the other settings specified during the initial estimation are not inherited correctly. It seems to not be a problem with summary in the example I show below.

library(fixest)

res_pois <- fepois(round(Petal.Length) ~ Petal.Width + Sepal.Length | Species, iris, se = 'iid', ssc = ssc(adj = FALSE))
res_glm <- glm(round(Petal.Length) ~ Petal.Width + Sepal.Length + Species, iris, family = poisson())

# Target covariance
vcov(res_glm)[2:3,2:3,drop=F]
#>               Petal.Width Sepal.Length
#> Petal.Width   0.038988314 -0.005434063
#> Sepal.Length -0.005434063  0.006418182
# Uses correct pre-specified settings (agrees with GLM)
vcov(res_pois)
#>               Petal.Width Sepal.Length
#> Petal.Width   0.038988314 -0.005434063
#> Sepal.Length -0.005434063  0.006418182
# Overrides pre-specified arguments for ssc
vcov(res_pois, se = 'iid')
#>               Petal.Width Sepal.Length
#> Petal.Width   0.040063854 -0.005583968
#> Sepal.Length -0.005583968  0.006595235
# Overrides default setting for se/vcov: "se" is set to "cluster"
vcov(res_pois, ssc = res_pois$summary_flags$ssc) 
#>               Petal.Width Sepal.Length
#> Petal.Width  0.0037281535 3.720606e-04
#> Sepal.Length 0.0003720606 6.963743e-05
# If both are manually specified, agrees with provided settings
vcov(res_pois, se = 'iid', ssc = res_pois$summary_flags$ssc) 
#>               Petal.Width Sepal.Length
#> Petal.Width   0.038988314 -0.005434063
#> Sepal.Length -0.005434063  0.006418182

# Point estimates agree as expected
coef(res_pois)
#>  Petal.Width Sepal.Length 
#>   0.08475446   0.14744109
coef(res_glm)[2:3]
#>  Petal.Width Sepal.Length 
#>   0.08475446   0.14744109

# Not a problem with summary?
summary(res_pois)
#> Poisson estimation, Dep. Var.: round(Petal.Length)
#> Observations: 150 
#> Fixed-effects: Species: 3
#> Standard-errors: IID 
#>              Estimate Std. Error  t value Pr(>|t|)    
#> Petal.Width  0.084754   0.197455 0.429235 0.667752    
#> Sepal.Length 0.147441   0.080114 1.840401 0.065709 .  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Log-Likelihood: -235.1   Adj. Pseudo R2: 0.20737 
#>            BIC:  496.1     Squared Cor.: 0.941817
summary(res_pois, se = 'iid')
#> Poisson estimation, Dep. Var.: round(Petal.Length)
#> Observations: 150 
#> Fixed-effects: Species: 3
#> Standard-errors: IID 
#>              Estimate Std. Error  t value Pr(>|t|)    
#> Petal.Width  0.084754   0.197455 0.429235 0.667752    
#> Sepal.Length 0.147441   0.080114 1.840401 0.065709 .  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Log-Likelihood: -235.1   Adj. Pseudo R2: 0.20737 
#>            BIC:  496.1     Squared Cor.: 0.941817
summary(res_pois, ssc = ssc(adj = F))
#> Poisson estimation, Dep. Var.: round(Petal.Length)
#> Observations: 150 
#> Fixed-effects: Species: 3
#> Standard-errors: IID 
#>              Estimate Std. Error  t value Pr(>|t|)    
#> Petal.Width  0.084754   0.197455 0.429235 0.667752    
#> Sepal.Length 0.147441   0.080114 1.840401 0.065709 .  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Log-Likelihood: -235.1   Adj. Pseudo R2: 0.20737 
#>            BIC:  496.1     Squared Cor.: 0.941817

Created on 2022-09-18 by the reprex package (v2.0.1)

@lrberge
Copy link
Owner

lrberge commented Feb 14, 2024

Hi, sorry for the delay. I agree the behavior was against what one expected. Now fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants