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)

Arguments

f

A p-, d-, or q-function to diagnose. Usually the output of one of as_p(), as_d(), or as_q() default methods.

ref_f

A "true" distribution function of the same class as f. Usually the input to the aforementioned as_*() function.

...

Other arguments to ref_f. If they were supplied to as_*() function, then the exact same values must be supplied here.

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.

Value

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.

Details

Errors are computed as difference between "true" value (output of ref_f) and output of pdqr-function f. They are computed at "granulated" gran times grid (which is an "x" column of "x_tbl" in case f is p- or d-function and "cumprob" column if q-function). 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 pdqr-distribution 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)).

See also

enpoint() for representing pdqr-function as a set of points with desirable number of rows.

Examples

d_norm <- as_d(dnorm) error_norm <- pdqr_approx_error(d_norm, dnorm) summary(error_norm)
#> grid error abserror #> Min. :-4.753 Min. :-7.979e-07 Min. :9.900e-12 #> 1st Qu.:-2.377 1st Qu.:-4.000e-07 1st Qu.:1.975e-09 #> Median : 0.000 Median :-5.552e-08 Median :5.552e-08 #> Mean : 0.000 Mean :-2.104e-07 Mean :2.104e-07 #> 3rd Qu.: 2.377 3rd Qu.:-1.975e-09 3rd Qu.:4.000e-07 #> Max. : 4.753 Max. :-9.900e-12 Max. :7.979e-07
# 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