pdqr_approx_error()
computes errors that are results of 'pdqr'
approximation, which occurs because of possible tail trimming and assuming
piecewise linearity of density function in case of "continuous" type. For an
easy view summary, use summary().
pdqr_approx_error(f, ref_f, ..., gran = 10, remove_infinity = TRUE)
f  A p, d, or qfunction to diagnose. Usually the output of one of


ref_f  A "true" distribution function of the same class
as 
...  Other arguments to 
gran  Degree of grid "granularity" in case of "continuous" type: number of subintervals to be produced inside every interval of density linearity. Should be not less than 1 (indicator that original column from "x_tbl" will be used, see details). 
remove_infinity  Whether to remove rows corresponding to infinite error. 
A data frame with the following columns:
grid <dbl>
: A grid at which errors are computed.
error <dbl>
: Errors which are computed as ref_f(grid, ...)  f(grid)
.
abserror <dbl>
: Absolute value of "error" column.
Errors are computed as difference between "true" value (output of
ref_f
) and output of pdqrfunction f
. They are computed at "granulated"
gran
times grid (which is an "x" column of "x_tbl" in case f
is p or
dfunction and "cumprob" column if qfunction). They are usually negative
because of possible tail trimming of reference distribution.
Notes:
gran
argument for "discrete" type is always 1.
Quantile pdqr approximation of "discrete" distribution with infinite
tale(s) can result into "all one" summary of error. This is expected output
and is because test grid is chosen to be quantiles of pdqrdistribution which
due to renormalization can differ by one from reference ones. For example:
summary(pdqr_approx_error(as_p(ppois, lambda = 10), ppois, lambda = 10))
.
enpoint()
for representing pdqrfunction as a set of points with
desirable number of rows.
#> grid error abserror
#> Min. :4.753 Min. :7.979e07 Min. :9.900e12
#> 1st Qu.:2.377 1st Qu.:4.000e07 1st Qu.:1.975e09
#> Median : 0.000 Median :5.552e08 Median :5.552e08
#> Mean : 0.000 Mean :2.104e07 Mean :2.104e07
#> 3rd Qu.: 2.377 3rd Qu.:1.975e09 3rd Qu.:4.000e07
#> Max. : 4.753 Max. :9.900e12 Max. :7.979e07
# Setting `gran` results into different number of rows in output
error_norm_2 < pdqr_approx_error(d_norm, dnorm, gran = 1)
nrow(meta_x_tbl(d_norm)) == nrow(error_norm_2)#> [1] TRUE
# By default infinity errors are removed
d_beta < as_d(dbeta, shape1 = 0.3, shape2 = 0.7)
error_beta_1 < pdqr_approx_error(d_beta, dbeta, shape1 = 0.3, shape2 = 0.7)
summary(error_beta_1)#> grid error abserror
#> Min. :0.00001 Min. :13.9547 Min. : 0.0167
#> 1st Qu.:0.25000 1st Qu.: 0.0278 1st Qu.: 0.0174
#> Median :0.50000 Median : 0.0199 Median : 0.0199
#> Mean :0.50000 Mean : 0.0215 Mean : 0.0470
#> 3rd Qu.:0.74999 3rd Qu.: 0.0174 3rd Qu.: 0.0278
#> Max. :0.99999 Max. :587.9396 Max. :587.9396
# To not remove them, set `remove_infinity` to `FALSE`
error_beta_2 < pdqr_approx_error(
d_beta, dbeta, shape1 = 0.3, shape2 = 0.7, remove_infinity = FALSE
)
summary(error_beta_2)#> grid error abserror
#> Min. :0.00 Min. :13.95467 Min. :0.01671
#> 1st Qu.:0.25 1st Qu.: 0.02783 1st Qu.:0.01736
#> Median :0.50 Median : 0.01987 Median :0.01987
#> Mean :0.50 Mean : Inf Mean : Inf
#> 3rd Qu.:0.75 3rd Qu.: 0.01736 3rd Qu.:0.02784
#> Max. :1.00 Max. : Inf Max. : Inf