including a label for omitted coefficients in texreg - r

I want to replicate in texreg the functionality contained in stargazer via the arguments omit and omit.labels (see here). Unfortunately, I cannot use the stargazer package as it does not support the model I am using and is not extensible. Since texreg is easily extensible I can get it to work with my models. I can also easily omit some output from texreg with the omit.coef argument. What I can't seem to figure out is how to insert labels for the omitted coefficients. Does this exist in texreg? Does anyone have experience trying to write this functionality into an extract function? Alternatively, has anyone figured out how to extend stargazer to work with a custom model?
Context: I am writing a presentation in knitr and need to convert the output of some estimators into latex which will then get converted to pdf for my beamer presentation. The output has a bunch of covariates and thus is too long to display nicely in beamer. I want to truncate the output by omitting some covariates and inserting in their place a line indicating whether these covariates have been included in the model or not, e.g. collapse the variables "County Population", "County Income", etc. into a line that reads "County controls" and then have "Yes" or "No" to indicate whether these controls were included in the estimate or not. Ideally, someone could help me figure out a way to do this in texreg. If not, I would be open to other packages/approaches, e.g. xtable.

A possible option is the github version of huxtable. (I am the author.) This has a huxreg function which creates a table from a bunch of regressions, much like texreg: it'll work for anything that has a broom::tidy method defined for it. You can then edit the table much like a normal data frame, just rbind in the rows you want.
You'll need to install using devtools::install_github, if you want to try this route.

Related

Scale Regression Summary in Beamer Presentation

In order to create a presentation, I use R Markdown. I'd like to print a linear regression (lm) or mixed-effects model (lmer) summary on a slide. However, it does not fit neatly on the slide and I searched the web for a method that allows me to scale the summary, but I couldn't find anything useful. Of course, I could delve deeply into the LaTeX configuration of my Markdown document. However, I was wondering whether there is a quick solution e.g., using a certain package, function or set up the relevant chunk differently?
I use stargazer to create the regresssion tables, there you can change the font size with font.size, the column spacing withcolumn.sep.width and/or print the regressions on one row with single.row = TRUE.

R: [Indicspecies package] multipatt function: extract values from summary.multipatt

I am working with the 'indicspecies' package - multipatt function and am unable to extract summary values of the package. Unfortunately I can't print all the summary and am left with impartial information for my model. The reason is the huge amount of data that needs to be printed from the summary (300.000 different species, 3 groups, 6 comparable combinations).
This is what happens with summary being saved (pre-code incl.):
x <- multipatt(data, ...)
sumx <-summary(x)
sumx
NULL
str(sumx)
NULL
So, the summary does not work exactly like a generic summary. It seems that the function is based around the older indval function from the 'labdsv' package (which is mentioned in the documentation). I found an archived thread where a similar problem is discussed: http://r.789695.n4.nabble.com/extract-values-from-summary-of-function-indval-of-the-package-labdsv-td4637466.html
but it seems not resolved (and is not exactly about the same function, rather the base function indval).
I was wondering if anyone has experience with the indicspecies package and knows a way to either extract the info from the summary.
It is possible to extract significance and other information from the other saved data from the model, but it might be nice to just get a quick complete overview from the data.
ps. I tried
options(max.print=1000000)
but this didn't solve it for me.
I use to capture the summary output for a multipatt object, but don't any more because the p-values reported are not corrected for multiple testing. To answer the OP's question you can capture the summary output using capture.output
ex.
dat.multipatt.summary<-capture.output(summary(dat.multipatt, indvalcomp=TRUE))
Again, I do not recommend this. It is very important to correct the p-values for multiple testing, so the summary output actually isn't helpful. To be clear ?multipatt states:
"sign Data table with results of the best matching pattern, the association value and the degree of statistical significance of the association (i.e. p-values from permutation test). Note that p-values are not corrected for multiple testing."
I just posted an answer for how to correct the p-values here https://stats.stackexchange.com/questions/370724/indiscpecies-multipatt-and-overcoming-multi-comparrisons/401277#401277
I don't have any experience with this package and since you haven't provided the data, it's difficult to reproduce. But since summary is returning NULL, are you sure your x is computed properly? Check the object.size or class or something else of x to see if it indeed has any content.
Also instead of accessing all the contents of summary(x) together, you can use # to access slots of it (similar to $ in dataframe).
If you need further assistance, it'd be better t provide atleast a small subset or some other sample data so that the community can work with it.

saving tables (e.g. latex) from Bayesian estimation functions in R

I would like to save the results of a Bayesian estimation function (e.g. brm) to file (e.g. in Latex format), for sharing results and preparing publications. It appears that existing packages (e.g. xtable, stargazer) are designed with non-Bayesian statistics in mind and cannot handle these model objects. Are there any existing packages or available code to handle this task (before I begin to recreate the wheel)? I have found tools for making tables from models estimated using JAGS/BUGS here but brm uses stan to estimate models.
If you call launch_shinystan on the object and go to the Estimate tab, there is a link to Generate LaTeX table that gives you a bunch of options to check on the left and it outputs the syntax on the right.
For posterity's sake, for basic tables one may also access specific parts of the model by for example:
summary(model)$fixed
where model is a stanfit object, and pass that to xtable or another function to output latex tables.

PLM object to LaTeX table

How can I make LaTeX tables with plm objects?
I have been using apsrtable to make LaTeX tables for output summaries for lm objects, but can't seem to find an easy way to do the same with plm. I am calculating panel corrected standard errors using plm and VcovBK(), but then have to go into latex and change the standard errors by hand.
As of version 2.0, the stargazer package supports PLM objects. It also makes some very nice tables, so it is worth a look.
A general approach which shouod work is to put your results in a data.frame and use xtable to create a LaTex table. This might take a bit more work than using premade templates, but it is very flexible.

Suggestion for R/LaTeX table creation package

I've been using xtable package for a long time, and looking forward to writting my first package in R... so I reckon that if I have some "cool" idea that's worth carying out, there's a great chance that somebody got there before me... =)
I'm interested in functions/packages specialized for LaTeX table creation (through R, of course). I bumped on quantreg package which has latex.table function. Any suggestion for similar function(s)/package(s)?
P.S.
I'm thinking about building a webapp in which users can define their own presets/templates of tables, choose style, statistics, etc. It's an early thought, though... =)
I sometimes divide the task of creating LaTeX tables into two parts:
I'll write the table environment, caption, and tabular environment commands directly in my LaTeX document.
I'll export just the body of the table from R using a custom function.
The R export part involves several steps:
Starting with a matrix of the whole table including any headings:
Add any LaTeX specific formatting to the table. E.g., enclose digits in dollar symbols to ensure that negative numbers display correctly.
Collapse rows into a single character value by replacing separate columns with the ampersand (&) and adding ends-of-row symbols "\\"
Add any horizontal lines to be displayed in the table. I use the booktabs LaTeX package.
Export the resulting character vector using the write function
The exported text file is then imported using the input command in LaTeX. I ensure that the file name corresponds to the table label.
I have used this approach in the context of writing journal articles.
In these cases, there are a lot of different types of tables (e.g., multi-page tables, landscape tables, tables requiring extended margins, tables requiring particular alignment, tables where I want to change the wording of the table title). In this setting, I've mostly found it easier to just export the data from R. In this way, the result is reproducible research, but it is easier to tweak aspects of table design in the LaTeX document. And in the context of journal articles, there are usually not too many tables and rather specific formatting requirements.
However, I imagine if I were producing large numbers of batch reports, I'd consider exporting more aspects directly from R.
Beyond xtable and Hmisc as listed by Rob, there are also at least
apsrtable which formats latex tables from one or more model objects
p2lh which exports R to LaTeX and HTML
RcmdrPlugin.Export which graphically exports output to LaTeX or HTML
reporttools which generates LaTeX tables of descriptive statistics
This was just based on a quick search. So there may be more for you to look at before you try to hook it into a webapp. Good luck.
In addition to the packages mentioned above, there is the stargazer package. It works well with objects from many commonly used functions and packages (lm, glm, svyglm, plm, survival, AER, pscl, and others), as well as with zelig objects.
Apart from xtable, there's the latex function in the Hmisc package.

Resources