compareR
compareR.Rd
Calculates descriptive statistics and performs statistical inference on two binary diagnostic tests in a single function call. Handles multiple comparisons using methods in `p.adjust()`.
Usage
compareR(
df,
alpha = 0.05,
margins = FALSE,
multi_corr = "holm",
cc = TRUE,
dp = 1,
sesp = TRUE,
ppvnpv = TRUE,
plrnlr = TRUE,
test.names = c("Test 1", "Test 2"),
...
)
Arguments
- df
A data frame or matrix with 3 columns (test1, test2, gold). Flexible coding of positive and negative results permitted.
- alpha
An alpha value. Defaults to 0.05.
- margins
A Boolean value indicating whether the contingency tables should have margins containing summed totals of rows and columns.
- multi_corr
Method for multiple comparisons. Uses `p.adjust.methods`.
- cc
A Boolean value indicating whether McNemar's test should be applied with continuity correction.
- dp
Number of decimal places of output in summary tables. Defaults to 1.
- sesp
A Boolean value indicating whether output should include sensitivity and specificity.
- ppvnpv
A Boolean value indicating whether output should include positive and negative predictive values.
- plrnlr
A Boolean value indicating whether output should include positive and negative likelihood ratios.
- test.names
A vector of length two giving the names of the two different binary diagnostic tests. This argument is not relevant when testing a single binary diagnostic test.
- ...
Rarely needs to be used. Allows additional arguments to be passed to internal functions.
Details
Confidence intervals for prevalence, diagnostic accuracies and predictive values are calculated using the interval for binomial proportions described by Yu et al. (2014). Confidence intervals for likelihood ratios are calculated using the methods recommended by Martín-Andrés and Álvarez-Hernández (2014). Hypothesis testing for diagnostic accuracies uses different methods depending on disease prevalence and number of participants or samples as described by Roldán-Nofuentes and Sidaty-Regad (2019). Global hypothesis testing for predictive values uses a method described by Roldán-Nofuentes et al. (2012), with subsequent individual tests (where indicated) performed using methods described by Kosinksi (2012). The methods for hypothesis testing- for likelihood ratios are taken from Roldán-Nofuentes & Luna del Castillo (2007).
An excellent summary of these methods is provided by Roldán-Nofuentes (2020) along with an open-source program (compbdt) licensed under GPL-2. This R package can be considered an extension of this work and is therefore distributed under the same license. Please consider citing Roldán-Nofuentes (2020) when you are citing this package.
References
Yu, Guo & Xu (2014) JSCS. 2014; 84:5,1022-1038 doi:10.1080/00949655.2012.738211
Martín Andrés & Álvarez Hernández (2014) Stat Comput. 2014; 24,65–75 doi:10.1007/s11222-012-9353-5
Roldán-Nofuentes & Sidaty-Regad (2019) JSCS. 2019; 89:14,2621-2644 doi:10.1080/00949655.2019.1628234
Roldán-Nofuentes, Luna del Castillo & Montero-Alonso (2012) Comput Stat Data Anal. 2012; 6,1161–1173. doi:10.1016/j.csda.2011.06.003
Kosinski (2012) Stat Med. 2012; 32,964-977 doi:10.1002/sim.5587
Roldán-Nofuentes, Luna del Castillo (2007) Stat Med. 2007; 26:4179–201. doi:10.1002/sim.2850
Roldán-Nofuentes (2020) BMC Med Res Methodol. 2020; 20,143 doi:10.1186/s12874-020-00988-y
Examples
# load data
df <- cfpr
# run compareR function
compareR(df,
margins = TRUE, multi_corr = "bonf",
test.names = c("pulm.exac", "pseudomonas")
)
#> $cont
#> $cont$`True Status: POS`
#> Test 2
#> Test 1 Positive Negative Sum
#> Positive 185 3445 3630
#> Negative 0 1424 1424
#> Sum 185 4869 5054
#>
#> $cont$`True Status: NEG`
#> Test 2
#> Test 1 Positive Negative Sum
#> Positive 123 1219 1342
#> Negative 0 5564 5564
#> Sum 123 6783 6906
#>
#>
#> $prev
#> Estimate SE Lower CI Upper CI
#> Prevalence 42.3 0.5 41.4 43.1
#>
#> $acc
#> $acc$accuracies
#> $acc$accuracies$pulm.exac
#> Estimate SE Lower CI Upper CI
#> Sensitivity 71.8 0.6 70.6 73.0
#> Specificity 80.6 0.5 79.6 81.5
#>
#> $acc$accuracies$pseudomonas
#> Estimate SE Lower CI Upper CI
#> Sensitivity 3.7 0.3 3.2 4.2
#> Specificity 98.2 0.2 97.9 98.5
#>
#>
#> $acc$glob.test.stat
#> [1] 12301.32
#>
#> $acc$glob.p.value
#> [1] 0
#>
#> $acc$glob.p.adj
#> [1] 0
#>
#> $acc$sens.test.stat
#> [1] 10821.03
#>
#> $acc$sens.p.value
#> [1] 0
#>
#> $acc$sens.p.adj
#> [1] 0
#>
#> $acc$spec.test.stat
#> [1] 1480.291
#>
#> $acc$spec.p.value
#> [1] 0
#>
#> $acc$spec.p.adj
#> [1] 0
#>
#>
#> $pv
#> $pv$predictive.values
#> $pv$predictive.values$pulm.exac
#> Estimate SE Lower CI Upper CI
#> PPV 73.0 0.6 71.8 74.2
#> NPV 79.6 0.5 78.7 80.6
#>
#> $pv$predictive.values$pseudomonas
#> Estimate SE Lower CI Upper CI
#> PPV 60.1 2.8 54.5 65.4
#> NPV 58.2 0.5 57.3 59.1
#>
#>
#> $pv$glob.test.stat
#> [1] 2830.026
#>
#> $pv$glob.p.value
#> [1] 0
#>
#> $pv$glob.p.adj
#> [1] 0
#>
#> $pv$ppv.test.stat
#> [1] 28.45746
#>
#> $pv$ppv.p.value
#> [1] 9.578013e-08
#>
#> $pv$ppv.p.adj
#> [1] 7.66241e-07
#>
#> $pv$npv.test.stat
#> [1] 2261.186
#>
#> $pv$npv.p.value
#> [1] 0
#>
#> $pv$npv.p.adj
#> [1] 0
#>
#>
#> $lr
#> $lr$likelihood.ratios
#> $lr$likelihood.ratios$pulm.exac
#> Estimate SE Lower CI Upper CI
#> PLR 3.7 0.1 3.5 3.9
#> NLR 0.3 0.0 0.3 0.4
#>
#> $lr$likelihood.ratios$pseudomonas
#> Estimate SE Lower CI Upper CI
#> PLR 2.1 0.2 1.6 2.6
#> NLR 1.0 0.0 1.0 1.0
#>
#>
#> $lr$glob.test.stat
#> [1] 2010.219
#>
#> $lr$glob.p.value
#> [1] 0
#>
#> $lr$glob.p.adj
#> [1] 0
#>
#> $lr$plr.test.stat
#> [1] 5.246279
#>
#> $lr$plr.p.value
#> [1] 1.552014e-07
#>
#> $lr$plr.p.adj
#> [1] 1.241611e-06
#>
#> $lr$nlr.test.stat
#> [1] 44.83283
#>
#> $lr$nlr.p.value
#> [1] 0
#>
#> $lr$nlr.p.adj
#> [1] 0
#>
#>
#> $other
#> $other$alpha
#> [1] 0.05
#>
#> $other$equal
#> [1] FALSE
#>
#> $other$zeros
#> [1] 2
#>
#> $other$Youden1
#> [1] 0.5239192
#>
#> $other$Youden2
#> [1] 0.01879407
#>
#> $other$test.names
#> [1] "pulm.exac" "pseudomonas"
#>
#>
#> attr(,"class")
#> [1] "compareR"