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

Fixest multi #734

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Fixest multi #734

wants to merge 8 commits into from

Conversation

strengejacke
Copy link
Member

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 2023

Codecov Report

Merging #734 (6c90722) into main (842c6e2) will decrease coverage by 2.88%.
The diff coverage is 75.00%.

❗ Current head 6c90722 differs from pull request most recent head 303a121. Consider uploading reports for the commit 303a121 to get more accurate results

@@            Coverage Diff             @@
##             main     #734      +/-   ##
==========================================
- Coverage   54.46%   51.58%   -2.88%     
==========================================
  Files         124      125       +1     
  Lines       15244    15044     -200     
==========================================
- Hits         8302     7761     -541     
- Misses       6942     7283     +341     
Files Changed Coverage Δ
R/get_df.R 67.25% <0.00%> (+2.84%) ⬆️
R/get_df_residual.r 21.79% <0.00%> (ø)
R/get_predicted_fixedeffects.R 76.47% <0.00%> (-4.78%) ⬇️
R/link_function.R 41.17% <0.00%> (-1.97%) ⬇️
R/link_inverse.R 44.96% <0.00%> (-1.09%) ⬇️
R/find_offset.R 95.00% <50.00%> (-5.00%) ⬇️
R/find_formula.R 63.44% <100.00%> (-2.15%) ⬇️
R/find_parameters.R 29.80% <100.00%> (-2.17%) ⬇️
R/find_predictors.R 79.52% <100.00%> (+0.16%) ⬆️
R/find_response.R 36.11% <100.00%> (-10.05%) ⬇️
... and 10 more

... and 43 files with indirect coverage changes

@etiennebacher
Copy link
Member

Thanks for opening the PR. As you can see there are a few things related to get_data() that need to be fixed for fixest_multi.

But even for simple fixest models I have a warning "Can't recover data from environment":

library(fixest)
library(insight)

data(iris)

mod <- feols(Petal.Width ~ Sepal.Width + Petal.Length | Species, iris)

head(get_data(mod))
#> Warning: Could not recover model data from environment. Please make sure your
#>   data is available in your workspace.
#>   Trying to retrieve data from the model frame now.
#>   Petal.Width Sepal.Width Petal.Length Species
#> 1         0.2         3.5          1.4  setosa
#> 2         0.2         3.0          1.4  setosa
#> 3         0.2         3.2          1.3  setosa
#> 4         0.2         3.1          1.5  setosa
#> 5         0.2         3.6          1.4  setosa
#> 6         0.4         3.9          1.7  setosa

Do you know why? And actually why do you try first to get data from environment and then fall back to extract data from model frame? Shouldn't it be the opposite since data in the environment can be overwritten by the user?

@vincentarelbundock
Copy link
Contributor

And actually why do you try first to get data from environment and then fall back to extract data from model frame? Shouldn't it be the opposite since data in the environment can be overwritten by the user?

We need the original dataset used to fit the model, and not the model frame, since the latter often includes transformations. For example, if you want to do predict(model, newdata = get_data(model)), you might end up transforming a predictor twice if the transformation is in the formula.

@vincentarelbundock
Copy link
Contributor

Adding to my previous comment: The old way was to take the model frame and to do clever back transformation, but this wasn't a great general solution because there were a ton of corner cases, and because some functions are not one-to-one.

@strengejacke
Copy link
Member Author

strengejacke commented Mar 17, 2023

Usually, for tests this turns out to be a scoping issue that is not often faced by users who work interactively (i.e. the warning appears less often than it might seem). In tests, you could do something like

d <<- iris
mod <- feols(Petal.Width ~ Sepal.Width + Petal.Length | Species, d)

this often helps.

@etiennebacher
Copy link
Member

etiennebacher commented Mar 17, 2023

We need the original dataset used to fit the model, and not the model frame, since the latter often includes transformations. For example, if you want to do predict(model, newdata = get_data(model)), you might end up transforming a predictor twice if the transformation is in the formula.

Got it, thanks for the explanation.

Usually, for tests this turns out to be a scoping issue that is not often faced by users who work interactively

Yes but the thing is that I also have the warning with the reprex above, even running it outside of reprex() like a normal user. Also, iris is my globenv so it seems like a bug?


Unrelated but just tagging easystats/performance#554 to easily link PRs about fixest_multi between them


Edit: ups @strengejacke I deleted a comment that I thought was duplicated

@easystats easystats deleted a comment from strengejacke Mar 17, 2023
@vincentarelbundock
Copy link
Contributor

I think this PR will solve the warning. find_offset() returned an empty list for this fixest model, and in turns this broke the .recover_data_from_environment()

@vincentarelbundock
Copy link
Contributor

#736

@strengejacke
Copy link
Member Author

strengejacke commented Mar 18, 2023

In general, it would be nice if fixest_multi would behave like other models with multiple responses, i.e. lists are rbind to a data frame including a reponse-column. Here's an example for lm(), and how I implemented fixest_multi in parameters.

library(fixest)
library(parameters)
#> 
#> Attaching package: 'parameters'
#> The following objects are masked from 'package:fixest':
#> 
#>     demean, dof
data(trade)
m2 <- lm(cbind(mpg, wt) ~ gear + cyl, data = mtcars)
insight::get_parameters(m2)
#>     Parameter   Estimate Response
#> 1 (Intercept) 34.6594974      mpg
#> 2        gear  0.6519391      mpg
#> 3         cyl -2.7430946      mpg
#> 4 (Intercept)  2.2779127       wt
#> 5        gear -0.3463366       wt
#> 6         cyl  0.3582147       wt

ci(m2)
#>     Parameter   CI     CI_low     CI_high Response
#> 1 (Intercept) 0.95 24.5623530 44.75664181      mpg
#> 2        gear 0.95 -1.1971186  2.50099672      mpg
#> 3         cyl 0.95 -3.5069815 -1.97920762      mpg
#> 4 (Intercept) 0.95  0.4457076  4.11011793       wt
#> 5        gear 0.95 -0.6818624 -0.01081071       wt
#> 6         cyl 0.95  0.2196015  0.49682790       wt

standard_error(m2)
#>     Parameter         SE Response
#> 1 (Intercept) 4.93692453      mpg
#> 2        gear 0.90408315      mpg
#> 3         cyl 0.37349691      mpg
#> 4 (Intercept) 0.89584326       wt
#> 5        gear 0.16405290       wt
#> 6         cyl 0.06777391       wt

p_value(m2)
#>     Parameter            p Response
#> 1 (Intercept) 1.013557e-07      mpg
#> 2        gear 4.766184e-01      mpg
#> 3         cyl 4.324142e-08      mpg
#> 4 (Intercept) 1.659504e-02       wt
#> 5        gear 4.349999e-02       wt
#> 6         cyl 1.147460e-05       wt

model_parameters(m2)
#> # mpg response
#> 
#> Parameter   | Coefficient |   SE |         95% CI | t(29) |      p
#> ------------------------------------------------------------------
#> (Intercept) |       34.66 | 4.94 | [24.56, 44.76] |  7.02 | < .001
#> gear        |        0.65 | 0.90 | [-1.20,  2.50] |  0.72 | 0.477 
#> cyl         |       -2.74 | 0.37 | [-3.51, -1.98] | -7.34 | < .001
#> 
#> # wt response
#> 
#> Parameter   | Coefficient |   SE |         95% CI | t(29) |      p
#> ------------------------------------------------------------------
#> (Intercept) |        2.28 | 0.90 | [ 0.45,  4.11] |  2.54 | 0.017 
#> gear        |       -0.35 | 0.16 | [-0.68, -0.01] | -2.11 | 0.043 
#> cyl         |        0.36 | 0.07 | [ 0.22,  0.50] |  5.29 | < .001
#> 
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#>   using a Wald t-distribution approximation.



m1 <- femlm(c(dist_km, Euros) ~ log(dist_km) + Origin + Year | Destination + Product, data = trade)
ci(m1)
#>       Parameter   CI        CI_low       CI_high Response
#> 1  log(dist_km) 0.95  1.000000e+00  1.000000e+00  dist_km
#> 2      OriginBE 0.95  9.727951e-10  8.143362e-09  dist_km
#> 3      OriginDE 0.95  3.083668e-09  1.716274e-08  dist_km
#> 4      OriginDK 0.95  2.271560e-09  1.168992e-08  dist_km
#> 5      OriginES 0.95  4.697153e-09  2.103707e-08  dist_km
#> 6      OriginFI 0.95 -3.225852e-08 -7.465491e-09  dist_km
#> 7      OriginFR 0.95  3.797618e-09  1.958950e-08  dist_km
#> 8      OriginGB 0.95  3.650321e-10  2.878821e-09  dist_km
#> 9      OriginGR 0.95 -2.359901e-08 -4.169361e-09  dist_km
#> 10     OriginIE 0.95 -2.412297e-08 -5.151406e-09  dist_km
#> 11     OriginIT 0.95  4.451757e-09  1.889752e-08  dist_km
#> 12     OriginLU 0.95 -5.538803e-08 -1.115783e-08  dist_km
#> 13     OriginNL 0.95  2.037227e-09  1.305061e-08  dist_km
#> 14     OriginPT 0.95 -1.959574e-09  4.093182e-09  dist_km
#> 15     OriginSE 0.95 -9.699107e-09 -1.998330e-09  dist_km
#> 16         Year 0.95  4.486226e-11  2.148093e-10  dist_km
#> 17 log(dist_km) 0.95 -1.742715e+00 -1.313021e+00    Euros
#> 18     OriginBE 0.95  3.318728e-01  1.773425e+00    Euros
#> 19     OriginDE 0.95  1.676209e+00  2.723105e+00    Euros
#> 20     OriginDK 0.95  3.332296e-01  1.532583e+00    Euros
#> 21     OriginES 0.95  2.016852e+00  2.900868e+00    Euros
#> 22     OriginFI 0.95 -1.356722e+00 -3.669280e-01    Euros
#> 23     OriginFR 0.95  1.506505e+00  2.828352e+00    Euros
#> 24     OriginGB 0.95  4.058747e-01  2.079479e+00    Euros
#> 25     OriginGR 0.95  1.588754e-01  9.870459e-01    Euros
#> 26     OriginIE 0.95  8.155916e-02  1.292333e+00    Euros
#> 27     OriginIT 0.95  1.368731e+00  2.271995e+00    Euros
#> 28     OriginLU 0.95 -2.594945e+00 -1.960661e+00    Euros
#> 29     OriginNL 0.95  1.407565e+00  2.445573e+00    Euros
#> 30     OriginPT 0.95 -6.210283e-01  4.944586e-01    Euros
#> 31     OriginSE 0.95 -1.440671e-01  1.630997e+00    Euros
#> 32         Year 0.95  3.009689e-02  4.210343e-02    Euros

standard_error(m1)
#>       Parameter           SE Response
#> 1  log(dist_km) 2.451896e-09  dist_km
#> 2      OriginBE 1.671627e-09  dist_km
#> 3      OriginDE 3.282161e-09  dist_km
#> 4      OriginDK 2.195641e-09  dist_km
#> 5      OriginES 3.809218e-09  dist_km
#> 6      OriginFI 5.779835e-09  dist_km
#> 7      OriginFR 3.681458e-09  dist_km
#> 8      OriginGB 5.860230e-10  dist_km
#> 9      OriginGR 4.529506e-09  dist_km
#> 10     OriginIE 4.422715e-09  dist_km
#> 11     OriginIT 3.367645e-09  dist_km
#> 12     OriginLU 1.031110e-08  dist_km
#> 13     OriginNL 2.567477e-09  dist_km
#> 14     OriginPT 1.411039e-09  dist_km
#> 15     OriginSE 1.795231e-09  dist_km
#> 16         Year 3.961864e-11  dist_km
#> 17 log(dist_km) 1.001717e-01    Euros
#> 18     OriginBE 3.360595e-01    Euros
#> 19     OriginDE 2.440560e-01    Euros
#> 20     OriginDK 2.795973e-01    Euros
#> 21     OriginES 2.060847e-01    Euros
#> 22     OriginFI 2.307441e-01    Euros
#> 23     OriginFR 3.081537e-01    Euros
#> 24     OriginGB 3.901563e-01    Euros
#> 25     OriginGR 1.930659e-01    Euros
#> 26     OriginIE 2.822597e-01    Euros
#> 27     OriginIT 2.105721e-01    Euros
#> 28     OriginLU 1.478663e-01    Euros
#> 29     OriginNL 2.419841e-01    Euros
#> 30     OriginPT 2.600461e-01    Euros
#> 31     OriginSE 4.138090e-01    Euros
#> 32         Year 2.799005e-03    Euros

p_value(m1)
#>       Parameter             p Response
#> 1  log(dist_km) 6.266878e-114  dist_km
#> 2      OriginBE  1.637590e-02  dist_km
#> 3      OriginDE  8.080290e-03  dist_km
#> 4      OriginDK  6.689497e-03  dist_km
#> 5      OriginES  4.506839e-03  dist_km
#> 6      OriginFI  4.011436e-03  dist_km
#> 7      OriginFR  6.729851e-03  dist_km
#> 8      OriginGB  1.511084e-02  dist_km
#> 9      OriginGR  8.391490e-03  dist_km
#> 10     OriginIE  5.163262e-03  dist_km
#> 11     OriginIT  3.777075e-03  dist_km
#> 12     OriginLU  6.085983e-03  dist_km
#> 13     OriginNL  1.079375e-02  dist_km
#> 14     OriginPT  4.621571e-01  dist_km
#> 15     OriginSE  5.721845e-03  dist_km
#> 16         Year  5.507173e-03  dist_km
#> 17 log(dist_km)  4.080089e-10    Euros
#> 18     OriginBE  7.345135e-03    Euros
#> 19     OriginDE  3.330237e-07    Euros
#> 20     OriginDK  4.892628e-03    Euros
#> 21     OriginES  1.006827e-08    Euros
#> 22     OriginFI  2.218309e-03    Euros
#> 23     OriginFR  5.924893e-06    Euros
#> 24     OriginGB  6.613974e-03    Euros
#> 25     OriginGR  1.018285e-02    Euros
#> 26     OriginIE  2.893447e-02    Euros
#> 27     OriginIT  5.492131e-07    Euros
#> 28     OriginLU  3.577348e-10    Euros
#> 29     OriginNL  1.448381e-06    Euros
#> 30     OriginPT  8.112561e-01    Euros
#> 31     OriginSE  9.399477e-02    Euros
#> 32         Year  3.686171e-09    Euros

model_parameters(m1)
#> # dist_km response
#> 
#> Parameter     |  Log-Mean |       SE |         95% CI |        z | df |      p
#> ------------------------------------------------------------------------------
#> dist km [log] |      1.00 | 2.45e-09 | [ 1.00,  1.00] | 4.08e+08 | 14 | < .001
#> Origin [BE]   |  4.56e-09 | 1.67e-09 | [ 0.00,  0.00] |     2.73 | 14 | 0.016 
#> Origin [DE]   |  1.01e-08 | 3.28e-09 | [ 0.00,  0.00] |     3.08 | 14 | 0.008 
#> Origin [DK]   |  6.98e-09 | 2.20e-09 | [ 0.00,  0.00] |     3.18 | 14 | 0.007 
#> Origin [ES]   |  1.29e-08 | 3.81e-09 | [ 0.00,  0.00] |     3.38 | 14 | 0.005 
#> Origin [FI]   | -1.99e-08 | 5.78e-09 | [ 0.00,  0.00] |    -3.44 | 14 | 0.004 
#> Origin [FR]   |  1.17e-08 | 3.68e-09 | [ 0.00,  0.00] |     3.18 | 14 | 0.007 
#> Origin [GB]   |  1.62e-09 | 5.86e-10 | [ 0.00,  0.00] |     2.77 | 14 | 0.015 
#> Origin [GR]   | -1.39e-08 | 4.53e-09 | [ 0.00,  0.00] |    -3.07 | 14 | 0.008 
#> Origin [IE]   | -1.46e-08 | 4.42e-09 | [ 0.00,  0.00] |    -3.31 | 14 | 0.005 
#> Origin [IT]   |  1.17e-08 | 3.37e-09 | [ 0.00,  0.00] |     3.47 | 14 | 0.004 
#> Origin [LU]   | -3.33e-08 | 1.03e-08 | [ 0.00,  0.00] |    -3.23 | 14 | 0.006 
#> Origin [NL]   |  7.54e-09 | 2.57e-09 | [ 0.00,  0.00] |     2.94 | 14 | 0.011 
#> Origin [PT]   |  1.07e-09 | 1.41e-09 | [ 0.00,  0.00] |     0.76 | 14 | 0.462 
#> Origin [SE]   | -5.85e-09 | 1.80e-09 | [ 0.00,  0.00] |    -3.26 | 14 | 0.006 
#> Year          |  1.30e-10 | 3.96e-11 | [ 0.00,  0.00] |     3.28 | 14 | 0.006 
#> 
#> # Euros response
#> 
#> Parameter     | Log-Mean |       SE |         95% CI |      z | df |      p
#> ---------------------------------------------------------------------------
#> dist km [log] |    -1.53 |     0.10 | [-1.74, -1.31] | -15.25 | 14 | < .001
#> Origin [BE]   |     1.05 |     0.34 | [ 0.33,  1.77] |   3.13 | 14 | 0.007 
#> Origin [DE]   |     2.20 |     0.24 | [ 1.68,  2.72] |   9.01 | 14 | < .001
#> Origin [DK]   |     0.93 |     0.28 | [ 0.33,  1.53] |   3.34 | 14 | 0.005 
#> Origin [ES]   |     2.46 |     0.21 | [ 2.02,  2.90] |  11.93 | 14 | < .001
#> Origin [FI]   |    -0.86 |     0.23 | [-1.36, -0.37] |  -3.73 | 14 | 0.002 
#> Origin [FR]   |     2.17 |     0.31 | [ 1.51,  2.83] |   7.03 | 14 | < .001
#> Origin [GB]   |     1.24 |     0.39 | [ 0.41,  2.08] |   3.19 | 14 | 0.007 
#> Origin [GR]   |     0.57 |     0.19 | [ 0.16,  0.99] |   2.97 | 14 | 0.010 
#> Origin [IE]   |     0.69 |     0.28 | [ 0.08,  1.29] |   2.43 | 14 | 0.029 
#> Origin [IT]   |     1.82 |     0.21 | [ 1.37,  2.27] |   8.64 | 14 | < .001
#> Origin [LU]   |    -2.28 |     0.15 | [-2.59, -1.96] | -15.40 | 14 | < .001
#> Origin [NL]   |     1.93 |     0.24 | [ 1.41,  2.45] |   7.96 | 14 | < .001
#> Origin [PT]   |    -0.06 |     0.26 | [-0.62,  0.49] |  -0.24 | 14 | 0.811 
#> Origin [SE]   |     0.74 |     0.41 | [-0.14,  1.63] |   1.80 | 14 | 0.094 
#> Year          |     0.04 | 2.80e-03 | [ 0.03,  0.04] |  12.90 | 14 | < .001
#> 
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#>   using a Wald z-distribution approximation.
#> 
#> The model has a log- or logit-link. Consider using `exponentiate =
#>   TRUE` to interpret coefficients as ratios.

Created on 2023-03-18 with reprex v2.0.2

@strengejacke
Copy link
Member Author

@etiennebacher Would you like to have this feature in the next CRAN release (i.e. do you also have time to work on this PR the next days), or can it wait until the release after the submission that is planned the next days?

@etiennebacher
Copy link
Member

No it's not needed for the next release, it can wait for a future one, I'm not sure exactly when I'll rework on this

@etiennebacher etiennebacher marked this pull request as draft March 18, 2023 11:35
@etiennebacher
Copy link
Member

etiennebacher commented Mar 20, 2023

Actually it's not that easy because fixest_multi models can have several responses (as in the example above) but also a lot of different predictors. For example, fixest provides the utility function csw0() (for cumulative stepwise) that takes several variables and estimates several models with all combinations of predictors (adding one at a time):

library(fixest)

mod <- feols(Petal.Width ~ Sepal.Width + csw0(Petal.Length, Sepal.Length) | Species, iris)

class(mod)
#> [1] "fixest_multi"

mod
#> Standard-errors: Clustered (Species) 
#> Expl. vars.: Sepal.Width
#>             Estimate Std. Error t value Pr(>|t|) 
#> Sepal.Width 0.283481   0.137218 2.06592  0.17482 
#> ---
#> Expl. vars.: Sepal.Width + Petal.Length
#>              Estimate Std. Error t value Pr(>|t|) 
#> Sepal.Width  0.202033   0.120657 1.67444  0.23602 
#> Petal.Length 0.170121   0.078076 2.17890  0.16119 
#> ---
#> Expl. vars.: Sepal.Width + Petal.Length + Sepal.Length
#>               Estimate Std. Error  t value Pr(>|t|)    
#> Sepal.Width   0.242200   0.118923  2.03661 0.178611    
#> Petal.Length  0.242203   0.051994  4.65827 0.043125 *  
#> Sepal.Length -0.092934   0.026870 -3.45861 0.074390 .

So it's probably possible to create an id column for this but we can't rely on the different values in Response.

@strengejacke
Copy link
Member Author

And even more complicated:

library(fixest)

mod <- feols(c(Petal.Width, Sepal.Width) ~ csw0(Petal.Length, Sepal.Length) | Species, iris)
mod
#> Standard-errors: Clustered (Species) 
#> 
#> ### Dep. var.: Petal.Width
#> 
#> Expl. vars.: 1
#> No variable (only the fixed-effects).
#> ---
#> Expl. vars.: Petal.Length
#>              Estimate Std. Error t value Pr(>|t|)    
#> Petal.Length 0.230389   0.068201 3.37812  0.07757 .  
#> ---
#> Expl. vars.: Petal.Length + Sepal.Length
#>               Estimate Std. Error   t value Pr(>|t|) 
#> Petal.Length  0.231921   0.086269  2.688346  0.11499 
#> Sepal.Length -0.001693   0.035875 -0.047202  0.96664 
#> 
#> ### Dep. var.: Sepal.Width
#> 
#> Expl. vars.: 1
#> No variable (only the fixed-effects).
#> ---
#> Expl. vars.: Petal.Length
#>              Estimate Std. Error t value Pr(>|t|)    
#> Petal.Length 0.298311   0.057189 5.21623 0.034843 *  
#> ---
#> Expl. vars.: Petal.Length + Sepal.Length
#>               Estimate Std. Error   t value Pr(>|t|) 
#> Petal.Length -0.042451   0.200105 -0.212144  0.85165 
#> Sepal.Length  0.376714   0.209702  1.796425  0.21426
class(mod)
#> [1] "fixest_multi"
s <- summary(mod)
names(s)
#> [1] "lhs: Petal.Width; rhs: 1"                          
#> [2] "lhs: Petal.Width; rhs: Petal.Length"               
#> [3] "lhs: Petal.Width; rhs: Petal.Length + Sepal.Length"
#> [4] "lhs: Sepal.Width; rhs: 1"                          
#> [5] "lhs: Sepal.Width; rhs: Petal.Length"               
#> [6] "lhs: Sepal.Width; rhs: Petal.Length + Sepal.Length"

Created on 2023-03-20 with reprex v2.0.2

@strengejacke
Copy link
Member Author

In that case, we should use the Group column, at least in model_parameters():

library(fixest)
iris$x <- rnorm(150)
mod <- feols(c(Petal.Width, Sepal.Width) ~ x + csw0(Petal.Length, Sepal.Length) | Species, iris)
summary(mod)
#> Standard-errors: Clustered (Species) 
#> 
#> ### Dep. var.: Petal.Width
#> 
#> Expl. vars.: x
#>   Estimate Std. Error t value Pr(>|t|) 
#> x 0.004595   0.004216 1.08973  0.38963 
#> ---
#> Expl. vars.: x + Petal.Length
#>              Estimate Std. Error t value Pr(>|t|)    
#> x            0.007443   0.001604 4.64013 0.043441 *  
#> Petal.Length 0.230825   0.068203 3.38438 0.077316 .  
#> ---
#> Expl. vars.: x + Petal.Length + Sepal.Length
#>              Estimate Std. Error  t value Pr(>|t|)    
#> x            0.007480   0.002088 3.583172 0.069827 .  
#> Petal.Length 0.230063   0.086565 2.657705 0.117202    
#> Sepal.Length 0.000844   0.036356 0.023225 0.983579    
#> 
#> ### Dep. var.: Sepal.Width
#> 
#> Expl. vars.: x
#>    Estimate Std. Error   t value Pr(>|t|) 
#> x -0.016767   0.049178 -0.340946  0.76563 
#> ---
#> Expl. vars.: x + Petal.Length
#>               Estimate Std. Error   t value Pr(>|t|)    
#> x            -0.013095   0.046168 -0.283637 0.803354    
#> Petal.Length  0.297545   0.060385  4.927434 0.038805 *  
#> ---
#> Expl. vars.: x + Petal.Length + Sepal.Length
#>               Estimate Std. Error   t value Pr(>|t|) 
#> x             0.003500   0.040789  0.085808  0.93944 
#> Petal.Length -0.043320   0.195610 -0.221464  0.84529 
#> Sepal.Length  0.377901   0.209543  1.803455  0.21309
out <- parameters::model_parameters(mod)
out$Group <- c(1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 6)
out
#> # Petal.Width.1
#> 
#> Parameter | Coefficient |       SE |        95% CI | t(2) |     p
#> -----------------------------------------------------------------
#> x         |    4.59e-03 | 4.22e-03 | [-0.01, 0.02] | 1.09 | 0.390
#> 
#> # Petal.Width.2
#> 
#> Parameter    | Coefficient |       SE |        95% CI | t(2) |     p
#> --------------------------------------------------------------------
#> x            |    7.44e-03 | 1.60e-03 | [ 0.00, 0.01] | 4.64 | 0.043
#> Petal.Length |        0.23 |     0.07 | [-0.06, 0.52] | 3.38 | 0.077
#> 
#> # Petal.Width.3
#> 
#> Parameter    | Coefficient |       SE |        95% CI | t(2) |     p
#> --------------------------------------------------------------------
#> x            |    7.48e-03 | 2.09e-03 | [ 0.00, 0.02] | 3.58 | 0.070
#> Petal.Length |        0.23 |     0.09 | [-0.14, 0.60] | 2.66 | 0.117
#> Sepal.Length |    8.44e-04 |     0.04 | [-0.16, 0.16] | 0.02 | 0.984
#> 
#> # Sepal.Width.4
#> 
#> Parameter | Coefficient |   SE |        95% CI |  t(2) |     p
#> --------------------------------------------------------------
#> x         |       -0.02 | 0.05 | [-0.23, 0.19] | -0.34 | 0.766
#> 
#> # Sepal.Width.5
#> 
#> Parameter    | Coefficient |   SE |        95% CI |  t(2) |     p
#> -----------------------------------------------------------------
#> x            |       -0.01 | 0.05 | [-0.21, 0.19] | -0.28 | 0.803
#> Petal.Length |        0.30 | 0.06 | [ 0.04, 0.56] |  4.93 | 0.039
#> 
#> # Sepal.Width.6
#> 
#> Parameter    | Coefficient |   SE |        95% CI |  t(2) |     p
#> -----------------------------------------------------------------
#> x            |    3.50e-03 | 0.04 | [-0.17, 0.18] |  0.09 | 0.939
#> Petal.Length |       -0.04 | 0.20 | [-0.88, 0.80] | -0.22 | 0.845
#> Sepal.Length |        0.38 | 0.21 | [-0.52, 1.28] |  1.80 | 0.213
#> 
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#>   using a Wald t-distribution approximation.

Created on 2023-03-20 with reprex v2.0.2

@strengejacke
Copy link
Member Author

Printing of headers can be improved...

library(fixest)
library(parameters)
#> 
#> Attaching package: 'parameters'
#> The following objects are masked from 'package:fixest':
#> 
#>     demean, dof
iris$x <- rnorm(150)
mod <- feols(c(Petal.Width, Sepal.Width) ~ x + csw0(Petal.Length, Sepal.Length) | Species, iris)
ci(mod)
#>       Parameter   CI      CI_low    CI_high    Response
#> 1             x 0.95 -0.02993508 0.02649643 Petal.Width
#> 2             x 0.95 -0.01873451 0.01609273 Petal.Width
#> 3  Petal.Length 0.95 -0.06502876 0.52578512 Petal.Width
#> 4             x 0.95 -0.01905216 0.01642175 Petal.Width
#> 5  Petal.Length 0.95 -0.14072260 0.60447689 Petal.Width
#> 6  Sepal.Length 0.95 -0.15660915 0.15329504 Petal.Width
#> 7             x 0.95 -0.09814132 0.13322628 Sepal.Width
#> 8             x 0.95 -0.14664376 0.18276112 Sepal.Width
#> 9  Petal.Length 0.95  0.06755155 0.52937863 Sepal.Width
#> 10            x 0.95 -0.17810517 0.21164253 Sepal.Width
#> 11 Petal.Length 0.95 -0.90431469 0.82053641 Sepal.Width
#> 12 Sepal.Length 0.95 -0.53085663 1.28335837 Sepal.Width
#>                              Group
#> 1                                x
#> 2                 x + Petal.Length
#> 3                 x + Petal.Length
#> 4  x + Petal.Length + Sepal.Length
#> 5  x + Petal.Length + Sepal.Length
#> 6  x + Petal.Length + Sepal.Length
#> 7                                x
#> 8                 x + Petal.Length
#> 9                 x + Petal.Length
#> 10 x + Petal.Length + Sepal.Length
#> 11 x + Petal.Length + Sepal.Length
#> 12 x + Petal.Length + Sepal.Length

model_parameters(mod)
#> # Petal.Width.x
#> 
#> Parameter | Coefficient |       SE |        95% CI |  t(2) |     p
#> ------------------------------------------------------------------
#> x         |   -1.72e-03 | 6.56e-03 | [-0.03, 0.03] | -0.26 | 0.818
#> 
#> # Sepal.Width.x
#> 
#> Parameter | Coefficient |   SE |        95% CI | t(2) |     p
#> -------------------------------------------------------------
#> x         |        0.02 | 0.03 | [-0.10, 0.13] | 0.65 | 0.581
#> 
#> # Petal.Width.x + Petal.Length
#> 
#> Parameter    | Coefficient |       SE |        95% CI |  t(2) |     p
#> ---------------------------------------------------------------------
#> x            |   -1.32e-03 | 4.05e-03 | [-0.02, 0.02] | -0.33 | 0.775
#> Petal.Length |        0.23 |     0.07 | [-0.07, 0.53] |  3.36 | 0.078
#> 
#> # Sepal.Width.x + Petal.Length
#> 
#> Parameter    | Coefficient |   SE |        95% CI | t(2) |     p
#> ----------------------------------------------------------------
#> x            |        0.02 | 0.04 | [-0.15, 0.18] | 0.47 | 0.684
#> Petal.Length |        0.30 | 0.05 | [ 0.07, 0.53] | 5.56 | 0.031
#> 
#> # Petal.Width.x + Petal.Length + Sepal.Length
#> 
#> Parameter    | Coefficient |       SE |        95% CI |  t(2) |     p
#> ---------------------------------------------------------------------
#> x            |   -1.32e-03 | 4.12e-03 | [-0.02, 0.02] | -0.32 | 0.780
#> Petal.Length |        0.23 |     0.09 | [-0.14, 0.60] |  2.68 | 0.116
#> Sepal.Length |   -1.66e-03 |     0.04 | [-0.16, 0.15] | -0.05 | 0.967
#> 
#> # Sepal.Width.x + Petal.Length + Sepal.Length
#> 
#> Parameter    | Coefficient |   SE |        95% CI |  t(2) |     p
#> -----------------------------------------------------------------
#> x            |        0.02 | 0.05 | [-0.18, 0.21] |  0.37 | 0.747
#> Petal.Length |       -0.04 | 0.20 | [-0.90, 0.82] | -0.21 | 0.854
#> Sepal.Length |        0.38 | 0.21 | [-0.53, 1.28] |  1.78 | 0.216
#> 
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#>   using a Wald t-distribution approximation.


mod <- feols(c(Petal.Width, Sepal.Width) ~ x + Petal.Length | Species, iris)
model_parameters(mod)
#> # Petal.Width response
#> 
#> Parameter    | Coefficient |       SE |        95% CI |  t(2) |     p
#> ---------------------------------------------------------------------
#> x            |   -1.32e-03 | 4.05e-03 | [-0.02, 0.02] | -0.33 | 0.775
#> Petal Length |        0.23 |     0.07 | [-0.07, 0.53] |  3.36 | 0.078
#> 
#> # Sepal.Width response
#> 
#> Parameter    | Coefficient |   SE |        95% CI | t(2) |     p
#> ----------------------------------------------------------------
#> x            |        0.02 | 0.04 | [-0.15, 0.18] | 0.47 | 0.684
#> Petal Length |        0.30 | 0.05 | [ 0.07, 0.53] | 5.56 | 0.031
#> 
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#>   using a Wald t-distribution approximation.

mod <- feols(Petal.Width ~ x + csw0(Petal.Length, Sepal.Length) | Species, iris)
model_parameters(mod)
#> # x
#> 
#> Parameter | Coefficient |       SE |        95% CI |  t(2) |     p
#> ------------------------------------------------------------------
#> x         |   -1.72e-03 | 6.56e-03 | [-0.03, 0.03] | -0.26 | 0.818
#> 
#> # x + Petal.Length
#> 
#> Parameter    | Coefficient |       SE |        95% CI |  t(2) |     p
#> ---------------------------------------------------------------------
#> x            |   -1.32e-03 | 4.05e-03 | [-0.02, 0.02] | -0.33 | 0.775
#> Petal.Length |        0.23 |     0.07 | [-0.07, 0.53] |  3.36 | 0.078
#> 
#> # x + Petal.Length + Sepal.Length
#> 
#> Parameter    | Coefficient |       SE |        95% CI |  t(2) |     p
#> ---------------------------------------------------------------------
#> x            |   -1.32e-03 | 4.12e-03 | [-0.02, 0.02] | -0.32 | 0.780
#> Petal.Length |        0.23 |     0.09 | [-0.14, 0.60] |  2.68 | 0.116
#> Sepal.Length |   -1.66e-03 |     0.04 | [-0.16, 0.15] | -0.05 | 0.967
#> 
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#>   using a Wald t-distribution approximation.

Created on 2023-03-20 with reprex v2.0.2

etiennebacher and others added 2 commits March 21, 2023 19:42
Merge branch 'main' into fixest-multi

# Conflicts:
#	README.md
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

Successfully merging this pull request may close these issues.

4 participants