In tbl_summary’s reference page, it states:
“Additionally, {p##} is available for percentiles, where ## is an integer from 0 to 100. For example, p25: quantile(probs=0.25, type=2).”
Does this mean that the type 2 algorithm is used in calculating percentiles using the quantile function? The documentation for stats::quantile reports that type = 7 is the default algorithm, and in my experience it seems that tbl_summary is using type = 7 not type = 2.
Is this accurate?
As a follow-up question, is it possible to change the algorithm “type” argument within the stats::quantile function implemented within tbl_summary’s percentiles calculations?
Here is a representative example of the discrepancy between type 7 (quantile default) versus type 2 (tbl_summary reference page)
data <- data.table::data.table(values = c(120, 120, 140, 210))
tbl_summary(
data,
type = list(values ~ 'continuous'),
statistic = list(values ~ "{p75}"),
digits = everything() ~ 1
)
Quantile defaults to using type = 7
stats::quantile(data$values, probs = 0.75)
75%
157.5
In tbl_summary reference, the “example” describing percentiles calculation uses type = 2 for quantile function
stats::quantile(data$values, probs = 0.75, type = 2)
75%
175
It would be helpful to control the algorithm “type” that quantile uses within tbl_summary. This would be particularly useful for how the IQRs are reported – especially for small N.