equatiomatic icon indicating copy to clipboard operation
equatiomatic copied to clipboard

Feature Request: add the standard error below the coefficent.

Open JiaxiangBU opened this issue 4 years ago • 6 comments

I know this package from https://bookdown.org/yihui/rmarkdown-cookbook/equatiomatic.html. Like the actual coefficent output,

#> $$
#> \operatorname{\widehat{mpg}} = 34.66 - 1.59(\operatorname{cyl}) - 0.02(\operatorname{disp})
#> $$

Does this package support the standard error below the coefficient (moreover, with R square)?

JiaxiangBU avatar Feb 02 '21 06:02 JiaxiangBU

It does not, but I'm happy to consider something like that. I'm not exactly sure how to incorporate that into the equation though. Do you have ideas on what it should look like?

Using your example, we get

library(equatiomatic)
library(lme4)
#> Loading required package: Matrix

m <- lm(mpg ~ cyl + disp, mtcars)
extract_eq(m, use_coef = TRUE)

The coefficients from this model are:

broom::tidy(m)
#> # A tibble: 3 x 5
#>   term        estimate std.error statistic  p.value
#>   <chr>          <dbl>     <dbl>     <dbl>    <dbl>
#> 1 (Intercept)  34.7       2.55       13.6  4.02e-14
#> 2 cyl          -1.59      0.712      -2.23 3.37e- 2
#> 3 disp         -0.0206    0.0103     -2.01 5.42e- 2

So would you want something like

$$ \operatorname{\widehat{mpg}} = 34.66{2.55]} - 1.59{0.71]}(\operatorname{cyl}) - 0.02{[0.01]}(\operatorname{disp}) $$

which would render as

Screen Shot 2021-02-02 at 5 52 51 AM

That seems a little unconventional and a bit confusing to me because it almost looks like the coefficient estimates should be be multiplied by their standard errors.

We could try putting them as subscripts:

Screen Shot 2021-02-02 at 5 54 44 AM

Or as subscripts with annotations:

Screen Shot 2021-02-02 at 5 57 07 AM

But I still don't love the way those look. I am not at all sure how we could include r squared.

Created on 2021-02-02 by the reprex package (v0.3.0)

datalorax avatar Feb 02 '21 13:02 datalorax

I've never seen the standard error included except as a +/-. Like the other notation though, it won't be standard mathematical notation and may be confusing.

JaySumners avatar Feb 03 '21 02:02 JaySumners

image

@datalorax Thanks for your reply, I think the stderr is below the coefficient. Here is an example from Wooldridge (2018,382).

I use the mathpix to capture the latex script, but the alignment should be fixed farther.

$$
\begin{aligned}
\hat{\Delta \log \left(\text { hrwage }_{t}\right)}=&-.0036+.809 \Delta \log (\text { outphr }) \\
&(.0042)(.173) \\
n=& 40, R^{2}=.364, \bar{R}^{2}=.348
\end{aligned}
$$

It is usual to report the fitted regression output with standard error and R square in econometrics textbook at the intro level.

Wooldridge, Jeffrey M. 2018. Introductory Econometrics: A Modern Approach. 7th ed. Cengage Learning, Inc.

JiaxiangBU avatar Feb 03 '21 07:02 JiaxiangBU

Ah... I see. Yeah that might be possible, although it would probably get pretty confusing for anything other than simple models. We could maybe give it a try though. Thanks for the suggestion!

datalorax avatar Feb 03 '21 17:02 datalorax

How's the progress on this feature? I just stumbled on this package and was also looking for this feature until I saw this issue.

I've personally been using \underset{bottom}{top} which appears follow the same example as the Wooldridge one the OP showed. Example below.

equation

And the code used to produce it: \widehat{work_i} = \underset{(`r lpm$std.error[1]`)}{`r lpm$coefficients[1]`} + \underset{(`r lpm$std.error[2]`)}{`r lpm$coefficients[2]`}educ_i + \underset{(`r lpm$std.error[3]`)}{`r lpm$coefficients[3]`}male_i + \underset{(`r lpm$std.error[4]`)}{`r lpm$coefficients[4]`}age_i

Ignore the messiness, the general usage would just be \underset{`r [std_error]`}{`r [coefficient]`} which shouldn't be too difficult to implement. I can create a pull request with the changes if this isn't already in the works/has been done.

ACC1100 avatar Apr 11 '21 07:04 ACC1100

HI! The progress on this has been... none! I haven't worked on it at all, to be honest. But I just re-opened the issue and will keep it open as something to implement. I don't think it should be too terribly difficult. I just need to get the time and, unfortunately, this spring term is a bit overwhelming to me as is. But hopefully I can find some time here in the next few weeks to dedicate a day to some of these sorts of issues.

datalorax avatar Apr 12 '21 03:04 datalorax