-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from JavierMtzRdz/develop
Update notes
- Loading branch information
Showing
9 changed files
with
235 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
^README\.Rmd$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
.Rproj.user | ||
.Rproj | ||
inst/ | ||
misc/ | ||
^tidydelta\.Rproj$ | ||
^\.Rproj\.user$ | ||
^LICENSE\.md$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
Package: tidydelta | ||
Title: Estimation of standard errors using Delta Method. | ||
Title: Estimation of standard errors using Delta Method | ||
Version: 0.0.0.9000 | ||
Authors@R: | ||
person("First", "Last", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "YOUR-ORCID-ID")) | ||
person("Javier", "Martinez-Rodriguez", , "[email protected]", | ||
role = c("aut", "cre")) | ||
Description: What the package does (one paragraph). | ||
License: MIT + file LICENSE | ||
Imports: | ||
|
@@ -12,6 +12,8 @@ Imports: | |
purrr, | ||
rlang, | ||
tibble | ||
Suggests: | ||
tidyverse | ||
Encoding: UTF-8 | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.2.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
output: github_document | ||
--- | ||
|
||
<!-- README.md is generated from README.Rmd. Please edit that file --> | ||
|
||
```{r, include = FALSE} | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>", | ||
fig.path = "man/figures/README-", | ||
out.width = "100%" | ||
) | ||
``` | ||
|
||
# tidydelta | ||
|
||
<!-- badges: start --> | ||
<!-- badges: end --> | ||
|
||
Delta Method implementation to estimate standard errors in a {tidyverse} workflow. | ||
|
||
## Installation | ||
|
||
You can install the development version of tidydelta from [GitHub](https://github.com/JavierMtzRdz/tidydelta) with: | ||
|
||
``` r | ||
remotes::install_github("JavierMtzRdz/tidydelta") | ||
# Or | ||
devtools::install_github("JavierMtzRdz/tidydelta") | ||
``` | ||
|
||
## Example | ||
|
||
Using tidydelta_m(), the following commands are equivalent: | ||
|
||
```{r example} | ||
# Load packages | ||
library(tidydelta) | ||
library(tidyverse) | ||
# Simulate samples | ||
set.seed(547) | ||
x = rnorm(10000, mean = 5, sd = 2) | ||
y = rnorm(10000, mean = 15, sd = 3) | ||
bd <- tibble(x, y) | ||
# Equivalent uses of tidydelta_m() | ||
tidydelta_m(~ y/x, | ||
conf_lev = .95) | ||
tidydelta_m(~ bd$y/bd$x, | ||
conf_lev = .95) | ||
bd %>% | ||
summarise(tidydelta_m(~ y/x, | ||
conf_lev = .95)) | ||
``` | ||
|
||
Now, the data frame is divided into samples to compare the transformation of the sample with the estimation of `tidydelta()`. In the real world, you would not need to compute the Delta Method if you have many samples, but it shows how it can be incorporated in a workflow with tidyverse. | ||
|
||
```{r message=FALSE, warning=FALSE, fig.height=3.5, dpi=300} | ||
(result <- bd %>% | ||
summarise(tidydelta_m(~ x/y, | ||
conf_lev = .95))) | ||
ggplot() + | ||
geom_histogram(data = bd %>% | ||
mutate(t = x/y), | ||
aes(x = t)) + | ||
geom_vline(aes(xintercept = result$T_n, | ||
color = "T_n")) + | ||
geom_vline(aes(xintercept = c(result$lower_ci, | ||
result$upper_ci), | ||
color = "CI"), | ||
linetype = "dashed") + | ||
labs(color = element_blank()) + | ||
theme_minimal() + | ||
theme(text = element_text(family = "Times New Roman")) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,104 @@ | ||
# stat547c_topics-in-probability | ||
|
||
<!-- README.md is generated from README.Rmd. Please edit that file --> | ||
|
||
# tidydelta | ||
|
||
<!-- badges: start --> | ||
<!-- badges: end --> | ||
|
||
Delta Method implementation to estimate standard errors in a {tidyverse} | ||
workflow. | ||
|
||
## Installation | ||
|
||
You can install the development version of tidydelta from | ||
[GitHub](https://github.com/JavierMtzRdz/tidydelta) with: | ||
|
||
``` r | ||
remotes::install_github("JavierMtzRdz/tidydelta") | ||
# Or | ||
devtools::install_github("JavierMtzRdz/tidydelta") | ||
``` | ||
|
||
## Example | ||
|
||
Using tidydelta_m(), the following commands are equivalent: | ||
|
||
``` r | ||
# Load packages | ||
library(tidydelta) | ||
library(tidyverse) | ||
#> Warning: package 'dplyr' was built under R version 4.3.1 | ||
#> Warning: package 'stringr' was built under R version 4.3.1 | ||
#> ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ── | ||
#> ✔ dplyr 1.1.4 ✔ readr 2.1.4 | ||
#> ✔ forcats 1.0.0 ✔ stringr 1.5.1 | ||
#> ✔ ggplot2 3.4.3 ✔ tibble 3.2.1 | ||
#> ✔ lubridate 1.9.2 ✔ tidyr 1.3.0 | ||
#> ✔ purrr 1.0.2 | ||
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ── | ||
#> ✖ dplyr::filter() masks stats::filter() | ||
#> ✖ dplyr::lag() masks stats::lag() | ||
#> ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors | ||
|
||
# Simulate samples | ||
set.seed(547) | ||
x = rnorm(10000, mean = 5, sd = 2) | ||
y = rnorm(10000, mean = 15, sd = 3) | ||
|
||
bd <- tibble(x, y) | ||
|
||
# Equivalent uses of tidydelta_m() | ||
tidydelta_m(~ y/x, | ||
conf_lev = .95) | ||
#> # A tibble: 1 × 6 | ||
#> y x T_n se lower_ci upper_ci | ||
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> | ||
#> 1 15.0 5.02 2.99 1.33 0.378 5.61 | ||
|
||
tidydelta_m(~ bd$y/bd$x, | ||
conf_lev = .95) | ||
#> # A tibble: 1 × 6 | ||
#> y x T_n se lower_ci upper_ci | ||
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> | ||
#> 1 15.0 5.02 2.99 1.33 0.378 5.61 | ||
bd %>% | ||
summarise(tidydelta_m(~ y/x, | ||
conf_lev = .95)) | ||
#> # A tibble: 1 × 6 | ||
#> y x T_n se lower_ci upper_ci | ||
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> | ||
#> 1 15.0 5.02 2.99 1.33 0.378 5.61 | ||
``` | ||
|
||
Now, the data frame is divided into samples to compare the | ||
transformation of the sample with the estimation of `tidydelta()`. In | ||
the real world, you would not need to compute the Delta Method if you | ||
have many samples, but it shows how it can be incorporated in a workflow | ||
with tidyverse. | ||
|
||
``` r | ||
(result <- bd %>% | ||
summarise(tidydelta_m(~ x/y, | ||
conf_lev = .95))) | ||
#> # A tibble: 1 × 6 | ||
#> x y T_n se lower_ci upper_ci | ||
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> | ||
#> 1 5.02 15.0 0.334 0.149 0.0422 0.626 | ||
|
||
ggplot() + | ||
geom_histogram(data = bd %>% | ||
mutate(t = x/y), | ||
aes(x = t)) + | ||
geom_vline(aes(xintercept = result$T_n, | ||
color = "T_n")) + | ||
geom_vline(aes(xintercept = c(result$lower_ci, | ||
result$upper_ci), | ||
color = "CI"), | ||
linetype = "dashed") + | ||
labs(color = element_blank()) + | ||
theme_minimal() + | ||
theme(text = element_text(family = "Times New Roman")) | ||
``` | ||
|
||
<img src="man/figures/README-unnamed-chunk-2-1.png" width="100%" /> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.