Creates a 2x2 contingency table from the data frame or matrix for the qualitative performance and reader precision of downstream analysis.

## Usage

```
diagTab(
formula = ~.,
data,
bysort = NULL,
dimname = NULL,
levels = NULL,
rep = FALSE,
across = NULL
)
```

## Arguments

- formula
(

`numeric`

)

a formula object with the cross-classifying variables (separated by`+`

) on the right hand side. If data is wide structure, the row name of contingency is represented by the variable to the left of the`+`

sign, and the col name is the right. If data is long structure, the classified variable is put on the left of the formula, and the value variable is put on the right.- data
(

`data.frame`

or`matrix`

)

a data frame or matrix.- bysort
(

`string`

)

a sorted variable from the col names of`data`

, and a grouped variable for reproducibility analysis.- dimname
(

`vector`

)

a character vector define the row name of contingency table in first variable, and col name in second variable.- levels
(

`vector`

)

a vector of known levels for measurements.- rep
(

`logical`

)

whether to implement the reproducibility like reader precision or not.- across
(

`string`

)

the across variable to split original data set to subsets. The between-reader and within-reader precision's across variable is`site`

commonly.

## Note

To be attention that if you would like to generate the 2x2 contingency table for reproducibility analysis, the original data should be long structure and using the corresponding formula.

## See also

`Summary()`

for object to calculate diagnostic accuracy criteria.

## Examples

```
# For qualitative performance with wide data structure
data("qualData")
qualData %>% diagTab(formula = ~ CandidateN + ComparativeN)
#> Contingency Table:
#>
#> levels: 0 1
#> ComparativeN
#> CandidateN 0 1
#> 0 54 16
#> 1 8 122
qualData %>%
diagTab(
formula = ~ CandidateN + ComparativeN,
levels = c(1, 0)
)
#> Contingency Table:
#>
#> levels: 1 0
#> ComparativeN
#> CandidateN 1 0
#> 1 122 8
#> 0 16 54
# For qualitative performance with long data structure
dummy <- data.frame(
id = c("1001", "1001", "1002", "1002", "1003", "1003"),
value = c(1, 0, 0, 0, 1, 1),
type = c("Test", "Ref", "Test", "Ref", "Test", "Ref")
)
dummy %>%
diagTab(
formula = type ~ value,
bysort = "id",
dimname = c("Test", "Ref"),
levels = c(1, 0)
)
#> Contingency Table:
#>
#> levels: 1 0
#> Ref
#> Test 1 0
#> 1 1 1
#> 0 0 1
# For Between-Reader precision performance
data("PDL1RP")
reader <- PDL1RP$btw_reader
reader %>%
diagTab(
formula = Reader ~ Value,
bysort = "Sample",
levels = c("Positive", "Negative"),
rep = TRUE,
across = "Site"
)
#> Contingency Table:
#>
#> levels: Positive Negative
#> Pairwise2
#> Pairwise1 Positive Negative
#> Positive 200 7
#> Negative 15 228
```