Search code examples
rmodelsummary

Rescale regression coefficients in modelsummary by arbitraty number (e.g, 100 to have percentage points)


I have a linear model with a binary dependent variable. I want to rescale the OLS coefficients by factor 100 to make them interpretable as percentage point changes.

In Stata's estout, this could simply be done by adding "transform(@*100 100)" how can this be done with modelsummary.

Bonus: Also transform the mean dependent variable to %.

library(modelsummary)
set.seed(1)
y <- rbinom(100,1,0.5)
x <- rbinom(100,1,0.5)
modelsummary(lm(y ~ x))

This gives me

                  (1)
(Intercept)     0.500
               (0.074)
x               −0.037
               (0.101)

What I need is

                  (1)
(Intercept)     50.0
                (7.4)
x               −3.7
               (10.1)
-------------------------
Mean y          48.2 %

Solution

  • As @Friede wrote in comments, the best solution is almost certainly to scale the data before fitting your model. That said, if you insist on scaling the final results, you could define a custom function as described here:

    https://modelsummary.com/vignettes/modelsummary_extension.html#modifying-information-tidy_custom-and-glance_custom

    library(modelsummary)
    set.seed(1)
    y <- rbinom(100,1,0.5)
    x <- rbinom(100,1,0.5)
    mod <- lm(y ~ x)
    tidy_custom.lm <- function(x, ...) {
        out <- broom::tidy(x)
        out$estimate <- out$estimate * 100
        return(out)
    }
    modelsummary(mod, "markdown")
    
    +-------------+---------+
    |             | (1)     |
    +=============+=========+
    | (Intercept) | 50.000  |
    +-------------+---------+
    |             | (0.074) |
    +-------------+---------+
    | x           | -3.704  |
    +-------------+---------+
    |             | (0.101) |
    +-------------+---------+
    | Num.Obs.    | 100     |
    +-------------+---------+
    | R2          | 0.001   |
    +-------------+---------+
    | R2 Adj.     | -0.009  |
    +-------------+---------+
    | AIC         | 150.9   |
    +-------------+---------+
    | BIC         | 158.7   |
    +-------------+---------+
    | Log.Lik.    | -72.431 |
    +-------------+---------+
    | F           | 0.134   |
    +-------------+---------+
    | RMSE        | 0.50    |
    +-------------+---------+