---
title: "Nonparametric Tests"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Nonparametric Tests}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

## Empirical Likelihood Tests

Empirical likelihood is a nonparametric method of inference based on a data driven likelihood ratio function. Like the bootstrap and jackknife, empirical likelihood inference does not require us to specify a family of distributions for the data. Like parametric likelihood methods, empirical likelihood makes an automatic determination of the shape of confidence regions [...] and has very favorable asymptotic power properties. It can be thought of as a bootstrap that does not resample and as a likelihood without parametric assumptions. (Owen 2001)

## Tests For Mu

One sample and one-way tests are implemented. Note the distribution does not need to be symmetrical and less data is needed. 

```{r part1}
library(LRTesteR)
library(statmod)

set.seed(1)
x <- rinvgauss(n = 30, mean = 2.25, dispersion = 2)
empirical_mu_one_sample(x = x, mu = 1, alternative = "two.sided")
```
The one way test does not require nuisance parameters or sample size to be equal.

```{r part2}
set.seed(1)
x <- c(
  rinvgauss(n = 35, mean = 1, dispersion = 1),
  rinvgauss(n = 40, mean = 2, dispersion = 3),
  rinvgauss(n = 45, mean = 3, dispersion = 5)
)
fctr <- c(rep(1, 35), rep(2, 40), rep(3, 45))
fctr <- factor(fctr, levels = c("1", "2", "3"))
empirical_mu_one_way(x = x, fctr = fctr, conf.level = .95)
```

## Tests For A Quantile

Any quantile can be tested. In this example, the null hypothesis is the median (Q equal to .50) is 0 (value argument).

```{r part3}
set.seed(2)
x <- rnorm(n = 30, mean = 0, sd = 1)
empirical_quantile_one_sample(x = x, Q = .50, value = 0, alternative = "two.sided")
```
Other quantiles can be tested as well. 

```{r part4}
# Q1
empirical_quantile_one_sample(x = x, Q = .25, value = 0, alternative = "two.sided")
```

```{r part5}
# Q3
empirical_quantile_one_sample(x = x, Q = .75, value = 0, alternative = "two.sided")
```


In one-way analysis, equality of a quantile is tested. Here, a common median (Q equal to .50) is tested.

```{r part6}
set.seed(1)
x <- c(
  rnorm(n = 35, mean = 1, sd = 1),
  rnorm(n = 40, mean = 2, sd = 1.25),
  rnorm(n = 45, mean = 3, sd = 1.5)
)
fctr <- c(rep(1, 35), rep(2, 40), rep(3, 45))
fctr <- factor(fctr, levels = c("1", "2", "3"))
empirical_quantile_one_way(x = x, Q = .50, fctr = fctr)
```
