Page 1 of 1

Export model summary from Apollo objects to LaTeX

Posted: 19 Jan 2021, 08:28
by alvarogutyerrez
Dear Stephane and David,

[Disclaimer: this is not particularly a feature request because it is related to the Apollo objects' post-processing, but I couldn't find a better topic to post this question.]

First of all, thank you for this fantastic software. I have been using it a lot lately, and it's awesome. However, a significant drawback compared to other ''standard'' R canned packages is that it's rather tedious to export results to LaTeX or word. In particular, for complex models like a Latent Class with a large allocation model.

I am very much used to use `modelsummary` to create my tables on my documents easily from my R-script, but given that the object created by apollo is a MaxLik, it required a lot of work to generate a well-formatted table.

Do you generate your tables ''manually'' on your documents, or is there a feature that I am missing here to export results? So far, I am aware of the `apollo_modelOutput(model)` function, which works great for simpler models, but in complex specifications, gets a little bit messy.

Thank you for your time!
Best wishes,

Re: Export model summary from Apollo objects

Posted: 20 Jan 2021, 20:03
by dpalma
Hi Alvaro,

We are aware that exporting to latex is a useful feature currently missing in Apollo, and we are looking into adding it in the medium term. Thank you for pointing us towards “modelsummary”, it might come in handy in the future.

In the meantime, I would recommend you using the apollo_combineResults function. It can generate a single table (in csv format) presenting results from multiple models. Then, you can format the table in excel, and export it to latex using excel2latex (an excel extension). Or if you use LibreOffice, you can install the calc2latex extension.

Best wishes
David

Re: Export model summary from Apollo objects

Posted: 21 Jan 2021, 08:00
by alvarogutyerrez
Hi David, thanks for your answer!

I actually decided to create a workaround for this problem. I have created a minimalist example of how to work with `modelsummary` on `Apollo` objects on my GitHub. I think people that work with LaTeX could benefit from it.

Feel free to use it and modified further. I will probably add more examples on my way because I am quite tired of changing the library each time I fit a different model, so I will probably stick to Apollo from now on :D .

Here is the link: https://github.com/alvarogutyerrez/expo ... delsummary

Best regards!

Re: Export model summary from Apollo objects

Posted: 21 Jan 2021, 11:48
by dpalma
Thank you for your work, Alvaro! This looks very useful!

Re: Export model summary from Apollo objects to LaTeX

Posted: 09 Apr 2021, 04:22
by gregorymacfarlane
Yes, I agree this looks very good! Getting tidy, glance, and augment methods written for apollo objects will help users access tools like modelsummary (which is amazing, and should be the model summary package to end all model summary packages), coefplot, and lots of other great pieces of the R ecosystem.

I started working on the same thing this afternoon before I saw this post; I've got a fork of the broom repository with tidy and glance methods written already. I haven't confirmed if they work on the latent class object that you posted. The code is at https://github.com/gregmacfarlane/broom ... -tidiers.R.

Here's what I get when I run the methods I wrote on the example MNL data.

Code: Select all

>   apollo_mnl
Maximum Likelihood estimation
BFGS maximization, 78 iterations
Return code 0: successful convergence 
Log-Likelihood: -1025.756 (9 free parameter(s))
Estimate(s): 0 0.4746553 1.629093 0.9445357 -0.003646093 -0.008846134 -0.02068522 -0.01123936 -0.0114658 -0.03394737 
>   tidy.apollo(apollo_mnl) 
# A tibble: 9 x 5
  term      estimate std.error statistic    p.val
  <chr>        <dbl>     <dbl>     <dbl>    <dbl>
1 asc_bus    0.475     1.02        0.466 1.36e+ 0
2 asc_air    1.63      0.827       1.97  1.95e+ 0
3 asc_rail   0.945     0.804       1.18  1.76e+ 0
4 b_tt_car  -0.00365   0.00155    -2.35  1.90e- 2
5 b_tt_bus  -0.00885   0.00262    -3.37  7.49e- 4
6 b_tt_air  -0.0207    0.00660    -3.13  1.72e- 3
7 b_tt_rail -0.0112    0.00439    -2.56  1.04e- 2
8 b_access  -0.0115    0.00643    -1.78  7.46e- 2
9 b_cost    -0.0339    0.00329   -10.3   6.79e-25
>   tidy.apollo(apollo_mnl, se.type = "robust") 
# A tibble: 9 x 5
  term      estimate std.error statistic    p.val
  <chr>        <dbl>     <dbl>     <dbl>    <dbl>
1 asc_bus    0.475     0.991       0.479 1.37e+ 0
2 asc_air    1.63      0.818       1.99  1.95e+ 0
3 asc_rail   0.945     0.795       1.19  1.77e+ 0
4 b_tt_car  -0.00365   0.00157    -2.33  2.01e- 2
5 b_tt_bus  -0.00885   0.00262    -3.38  7.21e- 4
6 b_tt_air  -0.0207    0.00642    -3.22  1.28e- 3
7 b_tt_rail -0.0112    0.00447    -2.52  1.19e- 2
8 b_access  -0.0115    0.00630    -1.82  6.86e- 2
9 b_cost    -0.0339    0.00318   -10.7   1.32e-26
>   tidy.apollo(apollo_mnl, conf.int = TRUE) 
# A tibble: 9 x 7
  term      estimate std.error statistic    p.val conf.low conf.high
  <chr>        <dbl>     <dbl>     <dbl>    <dbl>    <dbl>     <dbl>
1 asc_bus    0.475     1.02        0.466 1.36e+ 0 -0.493     1.44   
2 asc_air    1.63      0.827       1.97  1.95e+ 0  0.843     2.42   
3 asc_rail   0.945     0.804       1.18  1.76e+ 0  0.181     1.71   
4 b_tt_car  -0.00365   0.00155    -2.35  1.90e- 2 -0.00512  -0.00217
5 b_tt_bus  -0.00885   0.00262    -3.37  7.49e- 4 -0.0113   -0.00635
6 b_tt_air  -0.0207    0.00660    -3.13  1.72e- 3 -0.0270   -0.0144 
7 b_tt_rail -0.0112    0.00439    -2.56  1.04e- 2 -0.0154   -0.00707
8 b_access  -0.0115    0.00643    -1.78  7.46e- 2 -0.0176   -0.00536
9 b_cost    -0.0339    0.00329   -10.3   6.79e-25 -0.0371   -0.0308 
> 
>   glance.apollo(apollo_mnl)
# A tibble: 1 x 4
  logLik rho20   AIC  nobs
   <dbl> <dbl> <dbl> <int>
1 -1026. 0.124 2070.  1000
I would add that a lot of this would be a bit easier to write and more robust if there was an apollo class and a summary method in the apollo package.

Re: Export model summary from Apollo objects to LaTeX

Posted: 14 Apr 2021, 16:23
by stephanehess
Hi

we will consider an apollo class in future, but it's somewhat down our list of priorities at the moment as there are many other pressing developments

Stephane