Skip to content

Commit

Permalink
vignette updated
Browse files Browse the repository at this point in the history
  • Loading branch information
markean committed Feb 17, 2024
1 parent 8fccd14 commit 509c184
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 48 deletions.
28 changes: 15 additions & 13 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ Authors@R: c(
person("Pierre", "Chausse", role = "rev"),
person("Alex", "Stringer", role = "rev")
)
Description: Performs multiple empirical likelihood tests. It offers an
easy-to-use interface and flexibility in specifying hypotheses and
calibration methods, extending the framework to simultaneous inferences.
The core computational routines are implemented using the 'Eigen' 'C++'
library and 'RcppEigen' interface, with 'OpenMP' for parallel computation.
Details of the testing procedures are provided in Kim, MacEachern, and
Peruggia (2023) <doi:10.1080/10485252.2023.2206919>. A companion paper by
Kim, MacEachern, and Peruggia (2024) <doi:10.18637/jss.v108.i05> is
available for further information. This work was supported by the U.S.
National Science Foundation under Grants No. SES-1921523 and DMS-2015552.
Description: Performs multiple empirical likelihood tests. It offers an
easy-to-use interface and flexibility in specifying hypotheses and
calibration methods, extending the framework to simultaneous
inferences. The core computational routines are implemented using the
'Eigen' 'C++' library and 'RcppEigen' interface, with 'OpenMP' for
parallel computation. Details of the testing procedures are provided
in Kim, MacEachern, and Peruggia (2023)
<doi:10.1080/10485252.2023.2206919>. A companion paper by Kim,
MacEachern, and Peruggia (2024) <doi:10.18637/jss.v108.i05> is
available for further information. This work was supported by the U.S.
National Science Foundation under Grants No. SES-1921523 and
DMS-2015552.
License: GPL (>= 2)
URL: https://docs.ropensci.org/melt/, https://github.com/ropensci/melt
BugReports: https://github.com/ropensci/melt/issues
Expand All @@ -32,10 +34,11 @@ Imports:
utils
Suggests:
covr,
dplyr,
ggplot2,
knitr,
MASS,
microbenchmark,
R.rsp,
rmarkdown,
spelling,
testthat (>= 3.0.0),
Expand All @@ -46,8 +49,7 @@ LinkingTo:
Rcpp,
RcppEigen
VignetteBuilder:
knitr,
R.rsp
knitr
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
Expand Down
1 change: 0 additions & 1 deletion melt.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ BuildType: Package
PackageUseDevtools: Yes
PackageCleanBeforeInstall: No
PackageInstallArgs: --no-multiarch --with-keep.source
PackageBuildArgs: --compact-vignettes=both --no-build-vignettes
PackageCheckArgs: --as-cran --ignore-vignettes --no-tests
PackageRoxygenize: rd,collate,namespace,vignette
Binary file removed vignettes/article.pdf
Binary file not shown.
2 changes: 0 additions & 2 deletions vignettes/article.pdf.asis

This file was deleted.

50 changes: 32 additions & 18 deletions vignettes/model.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,67 @@ vignette: >
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
```{r, include=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
dpi = 300
)
```
```{r setup, echo=FALSE}
```{r, echo=FALSE}
library(melt, warn.conflicts = FALSE)
```

## Fitting an `EL` object
The melt package provides several functions to construct an `EL` object or an object that inherits from `EL`:
The melt package provides several functions to construct an `EL` object or an
object that inherits from `EL`:

* `el_mean()` for the mean.
* `el_sd()` for the standard deviation.
* `el_lm()` for linear models.
* `el_glm()` for generalized linear models.

We illustrate the usage of `el_mean()` with the `faithful` data set.
```{r, eval = TRUE}

```{r, eval=TRUE}
data("faithful")
str(faithful)
summary(faithful)
```
Suppose we are interested in evaluating empirical likelihood at (3.5, 70).

Suppose we are interested in evaluating empirical likelihood at `c(3.5, 70)`.

```{r}
fit <- el_mean(faithful, par = c(3.5, 70))
class(fit)
showClass("EL")
```
The `faithful` data frame is coerced to a numeric matrix. Simple print method shows essential information on `fit`.

The `faithful` data frame is coerced to a numeric matrix. Simple print method
shows essential information on `fit`.

```{r}
fit
```
Note that the maximum empirical likelihood estimates are the same as the sample average.
The chi-square value shown corresponds to the minus twice the empirical log-likelihood ratio.
It has an asymptotic chi-square distribution of 2 degrees of freedom under the null hypothesis.
Hence the $p$-value here is not exact.
The convergence status at the bottom can be used to check the convex hull constraint.

Weighted data can be handled by supplying the `weights` argument.
For non-`NULL` `weights`, weighted empirical likelihood is computed.
Any valid `weights` is re-scaled for internal computation to add up to the total number of observations.
For simplicity, we use `faithful$waiting` as our weight vector.

Note that the maximum empirical likelihood estimates are the same as the sample
average. The chi-square value shown corresponds to the minus twice the empirical
log-likelihood ratio. It has an asymptotic chi-square distribution of 2 degrees
of freedom under the null hypothesis. Hence the $p$-value here is not exact. The
convergence status at the bottom can be used to check the convex hull
constraint.

Weighted data can be handled by supplying the `weights` argument. For non-`NULL`
`weights`, weighted empirical likelihood is computed. Any valid `weights` is
re-scaled for internal computation to add up to the total number of
observations. For simplicity, we use `faithful$waiting` as our weight vector.

```{r}
w <- faithful$waiting
(wfit <- el_mean(faithful, par = c(3.5, 70), weights = w))
```
We get different results, where the estimates are now the weighted sample average.
The chi-square value and the associated $p$-value are based on the same limit theorem, but care must be taken when interpreting the results since they are largely affected by the limiting behavior of the weights.

We get different results, where the estimates are now the weighted sample
average. The chi-square value and the associated $p$-value are based on the same
limit theorem, but care must be taken when interpreting the results since they
are largely affected by the limiting behavior of the weights.
44 changes: 30 additions & 14 deletions vignettes/performance.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ vignette: >
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
```{r, include=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
Expand All @@ -18,21 +18,31 @@ knitr::opts_chunk$set(
out.width = "100%"
)
```
All the tests were done on an Arch Linux x86_64 machine with an Intel(R) Core(TM) i7 CPU (1.90GHz).
We first load the necessary packages.
```{r setup}
library(melt)
library(microbenchmark)
library(ggplot2)
```{r, echo=FALSE}
library(melt, warn.conflicts = FALSE)
```

All the tests were done on an Arch Linux x86_64 machine with an Intel(R)
Core(TM) i7 CPU (1.90GHz).


## Empirical likelihood computation
We show the performance of computing empirical likelihood with `el_mean()`.
We test the computation speed with simulated data sets in two different settings: 1) the number of observations increases with the number of parameters fixed, and 2) the number of parameters increases with the number of observations fixed.

### Increasing the number of observations
We fix the number of parameters at $p = 10$, and simulate the parameter value and $n \times p$ matrices using `rnorm()`. In order to ensure convergence with a large $n$, we set a large threshold value using `el_control()`.
We show the performance of computing empirical likelihood with `el_mean()`. We
test the computation speed with simulated data sets in two different settings:
1) the number of observations increases with the number of parameters fixed,
and 2) the number of parameters increases with the number of observations fixed.


## Increasing the number of observations

We fix the number of parameters at \(p = 10\), and simulate the parameter value
and \(n \times p\) matrices using `rnorm()`. In order to ensure convergence with
a large \(n\), we set a large threshold value using `el_control()`.

```{r}
library(ggplot2)
library(microbenchmark)
set.seed(3175775)
p <- 10
par <- rnorm(p, sd = 0.1)
Expand All @@ -46,13 +56,17 @@ result <- microbenchmark(
```

Below are the results:

```{r message=FALSE}
result
autoplot(result)
```

### Increasing the number of parameters
This time we fix the number of observations at $n = 1000$, and evaluate empirical likelihood at zero vectors of different sizes.

## Increasing the number of parameters\

This time we fix the number of observations at \(n = 1000\), and evaluate
empirical likelihood at zero vectors of different sizes.
```{r}
n <- 1000
result2 <- microbenchmark(
Expand All @@ -79,5 +93,7 @@ result2 <- microbenchmark(
result2
autoplot(result2)
```
On average, evaluating empirical likelihood with a 100000×10 or 1000×400 matrix at a parameter value satisfying the convex hull constraint takes less than a second.

On average, evaluating empirical likelihood with a 100000×10 or 1000×400 matrix
at a parameter value satisfying the convex hull constraint takes less than a
second.
31 changes: 31 additions & 0 deletions vignettes/references.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@article{kim2024melt,
title = {{melt}: Multiple Empirical Likelihood Tests in {R}},
author = {Eunseop Kim and Steven N. MacEachern and Mario Peruggia},
journal = {Journal of Statistical Software},
year = {2024},
volume = {108},
number = {5},
pages = {1--33},
doi = {10.18637/jss.v108.i05}
}

@article{kim2023empirical,
title = {Empirical Likelihood for the Analysis of Experimental Designs},
author = {Eunseop Kim and Steven N. MacEachern and Mario Peruggia},
journal = {Journal of Nonparametric Statistics},
volume = {35},
number = {4},
pages = {709--732},
year = {2023},
publisher = {Taylor & Francis},
doi = {10.1080/10485252.2023.2206919}
}

@manual{melt,
title = {\pkg{melt}: Multiple Empirical Likelihood Tests},
author = {Eunseop Kim},
year = {2023},
note = {\proglang{R} package version 1.10.0},
url = {https://CRAN.R-project.org/package=melt}
}

Loading

0 comments on commit 509c184

Please sign in to comment.