The goal of xmerit
is to facility teaching and researching on Econometrics.
Installation
You can install the development version of xmerit from GitHub with:
# install.packages("devtools")
devtools::install_github("huhuaping/xmerit")
Example
This is a basic example which shows you how to show math equation (LaTex
equation) easily in Rmarkdown Writing.
Dataset and model
library(xmerit)
data(mtcars)
## basic example code
df <- mtcars
mod <- mpg ~ cyl + disp + wt +gear
xvars <- all.vars(mod)[-1]
yvars <- all.vars(mod)[1]
lm.fit <- lm(formula = mod, data = df)
summary(lm.fit)
#>
#> Call:
#> lm(formula = mod, data = df)
#>
#> Residuals:
#> Min 1Q Median 3Q Max
#> -4.9159 -1.2484 -0.3566 1.4719 5.9253
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 43.539847 4.860059 8.959 1.42e-09 ***
#> cyl -1.784296 0.613889 -2.907 0.00722 **
#> disp 0.006944 0.012007 0.578 0.56782
#> wt -3.792867 1.081819 -3.506 0.00161 **
#> gear -0.490445 0.790285 -0.621 0.54007
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 2.624 on 27 degrees of freedom
#> Multiple R-squared: 0.835, Adjusted R-squared: 0.8105
#> F-statistic: 34.15 on 4 and 27 DF, p-value: 3.36e-10
xmerit::lx.psm
Here we will show the use of function xmerit::lx.psm()
.
R chunk
lx.out <- xmerit::lx.psm(
x = xvars, y = yvars,
begin = 0,
#greek.n = length(xvars)+1,
n.row = 3,
lm.label = "lx-psm",
lm.tag = "lx.psm",
no_dollar = FALSE)
xmerit::lx.est
Now let me show the use of function xmerit::lx.est()
.
R chunk
lx.out <- xmerit::lx.est(
lm.mod = mod, lm.dt = df,
lm.n = 3, lm.label = "lx-est",
lm.tag = "lx.est",
no_dollar = FALSE)
source style
$$\begin{equation}
999}
\begin{alignedat}{&\widehat{mpg}=&&+43.54&&-1.78cyl_i&&+0.01disp_i\\
&(s)&&(4.8601)&&(0.6139)&&(0.0120)\\
&(t)&&(+8.96)&&(-2.91)&&(+0.58)\\
&(cont.)&&-3.79wt_i&&-0.49gear_i &&\\
&(s)&&(1.0818)&&(0.7903) &&\\
&(t)&&(-3.51)&&(-0.62) &&
\end{alignedat}
\quad \text{(lx.est)}\quad#eq:lx-est)
(\$$
\end{equation}
-reference syntax of `see \@ref(eq:lx-est)` will be rendered as see \@ref(eq:lx-est). The cross
render effect
$$\begin{equation} \begin{alignedat}{999} &\widehat{mpg}=&&+43.54&&-1.78cyl_i&&+0.01disp_i\\ &(s)&&(4.8601)&&(0.6139)&&(0.0120)\\ &(t)&&(+8.96)&&(-2.91)&&(+0.58)\\ &(cont.)&&-3.79wt_i&&-0.49gear_i &&\\ &(s)&&(1.0818)&&(0.7903) &&\\ &(t)&&(-3.51)&&(-0.62) && \end{alignedat} \quad \text{(lx.est)}\quad (\#eq:lx-est) \end{equation}$$
The cross-reference syntax of see \@ref(eq:lx-est)
will be rendered as see @ref(eq:lx-est).