Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: add the standard error below the coefficent. #145

Open
JiaxiangBU opened this issue Feb 2, 2021 · 6 comments
Open

Feature Request: add the standard error below the coefficent. #145

JiaxiangBU opened this issue Feb 2, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@JiaxiangBU
Copy link

JiaxiangBU commented Feb 2, 2021

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)?

@datalorax
Copy link
Owner

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)

@JaySumners
Copy link
Collaborator

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.

@JiaxiangBU
Copy link
Author

JiaxiangBU commented Feb 3, 2021

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.

@datalorax
Copy link
Owner

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!

@ACC1100
Copy link

ACC1100 commented Apr 11, 2021

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.

@datalorax datalorax reopened this Apr 12, 2021
@datalorax
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants