Huxtable stacking several regression models

Hi!

I am trying to explore the possibility of using huxtable as a replacement for stargazer and/or kable. In particular, I would like to know if huxtable allows me to stack up several lists of regressions into panelled table (similar to what starpolishr package tires to achieve). Here is an example of such table.

Any comments are appreciated!
Thank you!

Sure. Package author here. This is a toy example.

library(huxtable)
p1 <- sample(nrow(iris), nrow(iris)/2)
mod1 <- lm(Sepal.Width ~ Sepal.Length, iris[p1, ])
mod2 <- lm(Sepal.Width ~ Sepal.Length + Species, iris[p1, ])
mod3 <- lm(Sepal.Width ~ Sepal.Length, iris[-p1, ])
mod4 <- lm(Sepal.Width ~ Sepal.Length + Species, iris[-p1, ])

h1 <- huxreg(mod1, mod2, error_pos = "right", error_format = "{p.value}", note = NULL)
h2 <- huxreg(mod3, mod4, error_pos = "right", error_format = "{p.value}")
rbind(h1, h2)

which gives you something like

                      ─────────────────────────────────────────────────────────────────
                                                         (1)                   (2)     
                                          ─────────────────────────────────────────────
                        (Intercept)           3.280 ***   0.000     1.720 ***   0.000  
                        Sepal.Length         -0.044       0.436     0.327 ***   0.000  
                        Speciesversicolor                          -0.872 ***   0.000  
                        Speciesvirginica                           -0.953 ***   0.000  
                                          ─────────────────────────────────────────────
                        N                    75                    75                  
                        R2                    0.008                 0.519              
                        logLik              -39.822               -12.660              
                        AIC                  85.644                35.320              
                      ─────────────────────────────────────────────────────────────────
                                                         (1)                   (2)     
                                          ─────────────────────────────────────────────
                        (Intercept)           3.567 ***   0.000     1.622 ***   0.000  
                        Sepal.Length         -0.081       0.221     0.375 ***   0.000  
                        Speciesversicolor                          -1.094 ***   0.000  
                        Speciesvirginica                           -1.056 ***   0.000  
                                          ─────────────────────────────────────────────
                        N                    75                    75                  
                        R2                    0.020                 0.636              
                        logLik              -46.050                -8.896              
                        AIC                  98.099                27.793              
                      ─────────────────────────────────────────────────────────────────
                        *** p < 0.001; ** p < 0.01; * p < 0.05.                        

You can then edit the huxtable at will.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.