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

feature request: supporting fixtest objects #785

Closed
IndrajeetPatil opened this issue Nov 19, 2019 · 4 comments · Fixed by #793
Closed

feature request: supporting fixtest objects #785

IndrajeetPatil opened this issue Nov 19, 2019 · 4 comments · Fixed by #793

Comments

@IndrajeetPatil
Copy link
Contributor

IndrajeetPatil commented Nov 19, 2019

library(fixest)

gravity_results <- feglm(Euros ~ log(dist_km) | Origin + Destination + Product + Year, trade)

gravity_results_ols <- feols(log(Euros) ~ log(dist_km) | Origin + Destination + Product + Year, trade)

gravity_results_negbin <- fenegbin(Euros ~ log(dist_km) | Origin + Destination + Product + Year, trade)

class(gravity_results)
#> [1] "fixest"

class(gravity_results_ols)
#> [1] "fixest"

class(gravity_results_negbin)
#> [1] "fixest"

summary(gravity_results)
#> GLM estimation, family = poisson, Dep. Var.: Euros
#> Observations: 38,325 
#> Fixed-effects: Origin: 15,  Destination: 15,  Product: 20,  Year: 10
#> Standard-errors: Clustered (Origin) 
#>              Estimate Std. Error z value  Pr(>|z|)    
#> log(dist_km)  -1.5279   0.115699 -13.206 < 2.2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Log-likelihood: -7.025e+11   Adj. Pseudo-R2: 0.76403 
#>            BIC:  1.405e+12     Squared Cor.: 0.61202

summary(gravity_results_ols)
#> OLS estimation, Dep. Var.: log(Euros)
#> Observations: 38,325 
#> Fixed-effects: Origin: 15,  Destination: 15,  Product: 20,  Year: 10
#> Standard-errors: Clustered (Origin) 
#>              Estimate Std. Error z value  Pr(>|z|)    
#> log(dist_km)  -2.1699   0.154312 -14.062 < 2.2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Log-likelihood: -75,682.54   Adj. R2: 0.70514 
#>                            R2-Within: 0.21932

summary(gravity_results_negbin)
#> Negative Binomial ML estimation, Dep. Var.: Euros
#> Observations: 38,325 
#> Fixed-effects: Origin: 15,  Destination: 15,  Product: 20,  Year: 10
#> Standard-errors: Clustered (Origin) 
#>              Estimate Std. Error z value  Pr(>|z|)    
#> log(dist_km)  -1.7108   0.166378 -10.283 < 2.2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Over-dispersion parameter: theta = 0.5487735  
#> Log-likelihood:  -646,586.98   Adj. Pseudo-R2: 0.03464 
#>            BIC: 1,294,419.32     Squared Cor.: 0.4376

Created on 2019-11-19 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.6.1 (2019-07-05)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  ctype    English_United States.1252  
#>  tz       Europe/Berlin               
#>  date     2019-11-19                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version    date       lib source                        
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                
#>  backports     1.1.5      2019-10-02 [1] CRAN (R 3.6.1)                
#>  callr         3.3.2      2019-09-22 [1] CRAN (R 3.6.1)                
#>  cli           1.1.0      2019-03-19 [1] CRAN (R 3.6.0)                
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.5.1)                
#>  desc          1.2.0      2019-11-11 [1] Github (r-lib/desc@61205f6)   
#>  devtools      2.2.1      2019-09-24 [1] CRAN (R 3.6.1)                
#>  digest        0.6.22     2019-10-21 [1] CRAN (R 3.6.1)                
#>  ellipsis      0.3.0      2019-09-20 [1] CRAN (R 3.6.1)                
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 3.6.0)                
#>  fixest      * 0.2.0      2019-11-19 [1] CRAN (R 3.6.1)                
#>  Formula       1.2-3      2018-05-03 [1] CRAN (R 3.5.0)                
#>  fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.0)                
#>  glue          1.3.1      2019-03-12 [1] CRAN (R 3.6.0)                
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.6.0)                
#>  htmltools     0.4.0      2019-10-04 [1] CRAN (R 3.6.1)                
#>  knitr         1.26       2019-11-12 [1] CRAN (R 3.6.1)                
#>  lattice       0.20-38    2018-11-04 [2] CRAN (R 3.6.1)                
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.5.1)                
#>  MASS          7.3-51.4   2019-03-31 [1] CRAN (R 3.6.0)                
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.6.0)                
#>  nlme          3.1-140    2019-05-12 [2] CRAN (R 3.6.1)                
#>  numDeriv      2016.8-1.1 2019-06-06 [1] CRAN (R 3.6.0)                
#>  pkgbuild      1.0.6      2019-10-09 [1] CRAN (R 3.6.1)                
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.0)                
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.5.1)                
#>  processx      3.4.1      2019-07-18 [1] CRAN (R 3.6.1)                
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.0)                
#>  R6            2.4.1      2019-11-12 [1] CRAN (R 3.6.1)                
#>  Rcpp          1.0.3      2019-11-08 [1] CRAN (R 3.6.1)                
#>  remotes       2.1.0      2019-06-24 [1] CRAN (R 3.6.0)                
#>  rlang         0.4.1      2019-10-24 [1] Github (r-lib/rlang@30feeac)  
#>  rmarkdown     1.17       2019-11-13 [1] CRAN (R 3.6.1)                
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.5.1)                
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                
#>  stringi       1.4.3      2019-03-12 [1] CRAN (R 3.6.0)                
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.0)                
#>  testthat      2.3.0      2019-11-05 [1] CRAN (R 3.6.1)                
#>  usethis       1.5.1.9000 2019-11-13 [1] Github (r-lib/usethis@c5f1e7f)
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.5.1)                
#>  xfun          0.11       2019-11-12 [1] CRAN (R 3.6.1)                
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.5.1)                
#> 
#> [1] C:/Users/inp099/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-3.6.1/library
@karldw
Copy link
Contributor

karldw commented Nov 21, 2019

@IndrajeetPatil, thanks for requesting this!
For others who see this issue, the fixest author prefers that these methods are in broom, rather than fixest. (lrberge/fixest#2)

@IndrajeetPatil
Copy link
Contributor Author

IndrajeetPatil commented Nov 21, 2019

@karldw Please feel free to make a PR here if you wish. This will be a good addition to the current collection of broom tidiers.

@grantmcdermott
Copy link
Contributor

grantmcdermott commented Nov 26, 2019

@IndrajeetPatil @karldw

Just to let you know I've started working on this here: https://github.com/grantmcdermott/broom/tree/fixest-tidiers

I've added a tidy.fixest method, but still need to do the glance and augmentequivalents, say nothing of adding tests, etc. So if anyone feels like pitching in...

FWIW, since fixest follows a particular protocol for recovering different SE estimates — which further implies, for example, that summary.fixest() simply yields another fixest object — I've decided to allow users two ways of adjusting the SEs with tidy():

  1. Either through the fixest object that is fed to tidy()
  2. Or, specify it directly in the tidy() call with the analogous "se" and "cluster" arguments.

Example:

> library(fixest)
> gravity <- feols(log(Euros) ~ log(dist_km) | Origin + Destination + Product + Year, trade)
> 
> tidy(gravity, conf.int = T)
# A tibble: 1 x 7
  term         estimate std.error statistic p.value conf.low conf.high
  <chr>           <dbl>     <dbl>     <dbl>   <dbl>    <dbl>     <dbl>
1 log(dist_km)    -2.17    0.0209     -104.       0    -2.21     -2.13
>  
> ## To get robust or clustered SEs, users can either:
>
> ## 1) Feed tidy() a summary.fixest object that has accepted these arguments
> gravity_summ <- summary(gravity, cluster = c("Product", "Year"))
> tidy(gravity_summ, conf.int = T)
# A tibble: 1 x 7
  term         estimate std.error statistic   p.value conf.low conf.high
  <chr>           <dbl>     <dbl>     <dbl>     <dbl>    <dbl>     <dbl>
1 log(dist_km)    -2.17    0.0743     -29.2 3.02e-187    -2.32     -2.02
>
> ## 2) Or, specify the arguments directly in the tidy() call
> tidy(gravity, conf.int = T, cluster = c("Product", "Year"))
# A tibble: 1 x 7
  term         estimate std.error statistic   p.value conf.low conf.high
  <chr>           <dbl>     <dbl>     <dbl>     <dbl>    <dbl>     <dbl>
1 log(dist_km)    -2.17    0.0743     -29.2 3.02e-187    -2.32     -2.02

@github-actions
Copy link

github-actions bot commented Mar 8, 2021

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants