---
title: "Non-parametric Two-sample test"
author: "Giovanni Saraceno"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Non-parametric Two-sample test}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---

### Non-parametric two-sample test
```{r srr-tags, eval = FALSE, echo = FALSE}
#' srr tags
#' 
#' 
#' @srrstats {G1.5} two-sample test example in the associated paper
```
The two-sample test can be additionally performed by providing the two sample to be compared as ``x`` and ``y``. We generate the sample $y = (y_1, \ldots,y_n)$ from a skew-normal distribution $SN_d(0,I_d, \lambda)$, where $d=4$, $n=200$ and $\lambda= (0.5,\ldots,0.5)$.  

```{r message=FALSE}
library(sn)
library(mvtnorm)
library(QuadratiK)
n <- 200
d <- 4
skewness_y <- 0.5
set.seed(2468)
x_2 <- rmvnorm(n, mean = rep(0,d))
y_2 <- rmsn(n=n, xi=0, Omega = diag(d), alpha=rep(skewness_y,d))
```

```{r}
h <- 2
set.seed(2468)
two_test <- kb.test(x=x_2, y=y_2, h=h)
```

For the two-sample case, the ``summary`` function provides the results from the test and the descriptive statistics per variable and per group, as similarly described for the $k$-sample test. Additionally, it generates the qq-plots comparing the quantiles of the two groups for each variable. 
```{r fig.width=6, fig.height=8}
summary_two <- summary(two_test)
```

```{r}
summary_two$summary_tables
```

The figure automatically generated by the ``summary`` function on the result of the two-sample test displays the qq-plots between the two samples with a table of the standard descriptive statistics for each variable, computed per group and overall.

#### Select h

If a value of $h$ is not provided, the function automatically perform the function ``select_h``.
```{r}
# two_test_h <- kb.test(x=x_2, y=y_2)
```

For a more accurate search of the tuning parameter, the function ``select_h`` can be used. This function needs the input ``x`` and ``y`` as the function ``kb.test`` for the two-sample problem. 
```{r eval=FALSE, fig.width=6, fig.height=4}
set.seed(2468)
h_test2 <- select_h(x=x_2, y=y_2, alternative="skewness")
```

```{r eval=FALSE}
h_test2$h_sel
```

The figure generated by the ``select_h`` function on the result of the selection of $h$ algorithm on the two-sample data set displays the obtained power versus the considered $h$, for the alternatives $\delta$.

