[R-sig-Geo] Using Stargazer to output spautolm models in Latex

Roger Bivand Roger.Bivand at nhh.no
Sat Nov 26 10:36:12 CET 2016


The spdep sarlm stargazer support was seriously broken when introduced, 
and the package author was only interested in advertising the package, and 
unresponsive with regard to necessary fixes.

Writing functions to extract what is needed from the summary objects could 
be done, but is hard to do right. For example, a sarlm object fitted using 
lagsarlm or sacsarlm should never have its covariate coefficients 
displayed, only the three-column impacts from the impacts() method (the 
coefficients are not equal to of a unit increment on a covariate in these 
cases unless \rho_{Lag} = 0 as they would be where the spatial process is 
uncorrelated with the covariates).

By the way (checking now), the R code in stargazer is (still) in two 
files, and is very difficult to read (badly constructed, one file is 6500 
lines long). For spdep fitted objects, it does not use their declared 
class, and continues to ignore the need to report the spatial 
coefficients. Of course, impacts are ignored. As previously reported, 
stargazer should never be used with spdep objects, it is seriously 
misleading.

It is possible that pander will work better, but it doesn't do model 
comparison tables out of the box as far as I can see - you'd need to take 
the relevant parts from the summary object for your fitted model. This 
however is something that can be done readily, as can be done for xtable. 
I usually create a formatted character matrix and output through xtable if 
I need a model comparison table. Look at:

example(NY_data)
esar1f <- spautolm(Z ~ PEXPOSURE + PCTAGE65P + PCTOWNHOME,
  data=nydata, listw=listw_NY, family="SAR", method="eigen")
res <- summary(esar1f)
str(res)

to see what is where, and at the code in spdep:::print.summary.spautolm to 
see how its print method extracts the relevant pieces.

For example:

c(c(res$Coef[,1:2]), unname(res$lambda), res$lambda.se, res$fit$s2, 
res$LL)

gives you four interleaved coefficients and their standard errors, 
\rho_{Err} and its standard error, the model sigma^2 and the model log 
likelihood. The issue in table construction is then slotting the right 
(column) vector elements into the right table rows, because covariates may 
be omitted in some models. Row and column names also need care (a trick 
for the coefficient standard errors is to use increasing numbers of 
spaces). Using a character matrix lets you vary the formatting by row 
(different numbers of digits for model sigma^2 and log likelihood).

The stargazer package tried to be clever and make things easy, which might 
be OK if it did things right, but it doesn't (for spdep objects and by 
extension for others its author doesn't understand), so it should be 
avoided. I tried to get its author to fix it, but because of the way the 
code is written (one large operative file), suggesting patches without 
seeing the workflow clearly remains impossible.

So, work from the summary objects of your fitted models and build a 
matrix for, for example, pander or xtable.

Hope this clarifies,

Roger

On Fri, 25 Nov 2016, Melanie Bacou wrote:

> You could also check into the `pander` package (documented at
> http://rapporter.github.io/pander/#helper-functions).>
> AFAIK there's no helper function to output SAR/CAR or GWR objects
> directly, but you might be able to work with `pander.lm`.
>
> Else maybe submit a request on GitHub
> https://github.com/Rapporter/pander/issues.
>
> --Mel.
>
>
> On 11/25/2016 04:17 PM, Samar Deen wrote:
>> Hi Everyone,
>>
>> I am running some CAR regressions using spautolm. I wanted to generate some
>> summary tables of the regressions using stargazer to output in Latex.
>> While stargazer supports some spdep classes, unfortunately, stargazer does
>> not support  spautolm. Has anyone tried to output CAR model regression
>> results in Latex? Please do let me know if you have come across a
>> supporting package.
>>
>> One alternative will be to convert the spautolm class to a supported
>> class in stargazer. But I haven't had much luck.
>>
>> Any tips will be most helpful.
>>
>> Thank you.
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
http://depsy.org/person/434412



More information about the R-sig-Geo mailing list