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

**This package aims on Clinical and Laboratory Standards Institute (CLSI) EP15-A3 Calculations**

CLSI EP15-A3 provides guidance on the user verification of precision and the estimation of bias for laboratory test methods. It outlines the steps and procedures that clinical laboratories should follow to evaluate the performance of a test method they intend to implement. 

This package is a R implementation of the calculations used in the document

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

# Install

```{r eval=FALSE, include=FALSE}
devtools::install_github('clauciorank/CLSIEP15')
```

# Load
```{r setup}
library(CLSIEP15)
```

# Usage

**Create a table in the specified format**

**Wider Format**
```{r echo=FALSE}
knitr::kable(ferritin_wider)
```

**Long Format**

```{r echo=FALSE}
knitr::kable(head(ferritin_long, 12))
```

`ferritin_long` and `ferritin_wider` are provided as data in the package and can be used as example

**For Long Format**

```{r}
data <- create_table_ep_15(ferritin_long, data_type = 'long')
```

**For Wide Format**
```{r}
data <- create_table_ep_15(ferritin_wider)
```

# Precision

***Calculate Anova parameters and Imprecision Estimates***

```{r}
aov_t <- calculate_aov_infos(data)
aov_t
```

If user repetibility(SR or CVR) < repetibility claim and Within-lab(SWL or CVWL) < Within-lab claim the 
user has verified manufacture's precision claims if not the upper verification limit (UVL) should be checked

```{r}
uvl_info <- calculate_uvl_info(aov_return = aov_t, cvr_or_sr = .43, cvwl_or_swl = .7)
uvl_info
```

Where arguments are the follow:

- aov_return:	Return of calculate_aov_info()

- nsamp: number of samples in the experiment. Default is 1

- cvr_or_sr: Desirable CV or S repetability

- cvwl_or_swl: Desirable CV or S within-lab

Recheck If user repetability(SR or CVR) < UVL repetability claim and Within-lab(SWL or CVWL) < UVL Within-lab claim

# Bias

For calculating a range for acceptable bias different scenarios and subscenarios are provided by the document

`calculate_bias_interval` is the function used:

```{r eval=FALSE}
calculate_bias_interval(
  scenario,
  nrun,
  nrep,
  SWL,
  SR,
  nsamples,
  expected_mean,
  user_mean,
  ...
)
```

These are the mandatory parameters:

- scenario: Choosed scenario from section 3.3 of EP15-A3

- nrun: Number of runs

- nrep: number of repetitions per run (n0)

- SWL: S within laboratory (obtained from anova)

- SR: S repetability (obtained from anova)

- nsamples: total number of samples tested usual 1

- expected_mean: Expected mean or TV

- user_mean: Mean of all samples (obtained from anova)

- ... : additional parameters necessary for processing the choosed scenario

**Scenario A**

Bona fide reference materials, can vary depending on the information provided by the manufacturer. 
- Sub scenario "u":
    -  manufacturer supplies a "standard error," "standard uncertainty" (u), or "combined standard uncertainty" (often denoted as uC ) for the TV
- Sub scenario "Uk":
    - manufacturer provides an "expanded uncertainty" (U) for the TV and a "coverage factor" (k)
- Sub scenario "Ucoverage":
    - manufacturer provides an "expanded uncertainty" (U) for the TV and a "coverage percentage"
- Sub scenario "lowerupper":
    - manufacturer provides an lower and upper limits and a "coverage percentage" (CI)
    
**Example**

```{r eval=FALSE}
calculate_bias_interval('A', 
                        subscenario = 'Uk', 
                        nrun = 7, 
                        nrep = 5, 
                        SWL = .042, 
                        SR = .032, 
                        nsamples = 2, 
                        exppected_mean = 1, 
                        user_mean = .94
                        )
```

Will return

`Error in calculate_se_rm(scenario, additional_args) : For the choosed scenario U and k must be supplied`

So we need to pass the requested parameters:

```{r}
calculate_bias_interval('A', 
                        subscenario = 'Uk', 
                        nrun = 7, 
                        nrep = 5, 
                        SWL = .042, 
                        SR = .032, 
                        nsamples = 2, 
                        expected_mean = 1, 
                        user_mean = .94, 
                        U = 140, 
                        k = 1.96
                        )
```


**Scenario B and C**

When a reference material's total uncertainty (TV) is determined based on Proficiency Testing (PT) (B) or  peer group results from an interlaboratory QC program (C)

Additional parameters necessary are sd_rm and nlab

**Example**
```{r}
calculate_bias_interval('C',  nrun = 7, 
                        nrep = 5, 
                        SWL = .042, 
                        SR = .032, 
                        nsamples = 2, 
                        expected_mean = 1, 
                        user_mean = .94,
                        sd_rm = .05,
                        nlab = 43)
```

**Scenario D and E**

If the TV represents a conventional quantity value (D) or When working with a commercial QC material supplied
with a TV for which the standard error cannot be estimated (E)

```{r}
calculate_bias_interval('E', 
                        nrun = 7, 
                        nrep = 5, 
                        SWL = .042, 
                        SR = .032, 
                        nsamples = 2, 
                        expected_mean = 1, 
                        user_mean = .94
                        )
```

**Bias conclusion**

If the mean is inside `interval` object returned in `calculate_bias_interval()` the result is not significant and the observed bias is inside the manufacture claims

-------------------------------------------------------
Package repository: https://github.com/clauciorank/CLSIEP15
