form_retype {pdqr}R Documentation

Change type of pdqr-function

Description

Modify type of pdqr-function using method of choice.

Usage

form_retype(f, type = NULL, method = "value")

Arguments

f

A pdqr-function.

type

A desired type of output. Should be one of "discrete" or "continuous". If NULL (default), it is chosen as an opposite of f's type.

method

Retyping method. Should be one of "value", "piecelin", "dirac".

Details

If type of f is equal to input type then f is returned.

Method "value" uses renormalized columns of f's "x_tbl" metadata as values for output's "x_tbl" metadata. In other words, it preserves ratios between values of d-function at certain "x" points. Its main advantages are that this method can work well with any pdqr type and that two consecutive conversions return the same function. Conversion algorithm is as follows:

Method "piecelin" should be used mostly for converting from "continuous" to "discrete" type. It uses the fact that 'pdqr' densities are piecewise-linear (linear in intervals between values of "x" column of "x_tbl" metadata) on their support:

Method "dirac" is used mostly for converting from "discrete" to "continuous" type (for example, in form_mix() in case different types of input pdqr-functions). It works in the following way:

Value

A pdqr-function with type equal to input type.

See Also

form_regrid() for changing grid (rows of "x_tbl" metadata) of pdqr-function.

form_resupport() for changing support of pdqr-function.

Other form functions: form_estimate(), form_mix(), form_regrid(), form_resupport(), form_smooth(), form_tails(), form_trans()

Examples

my_con <- new_d(data.frame(x = 1:5, y = c(1, 2, 3, 2, 1) / 9), "continuous")
meta_x_tbl(my_con)

# By default, conversion is done to the opposite type
my_dis <- form_retype(my_con)
meta_x_tbl(my_dis)

# Default retyping (with method "value") is accurate when doing consecutive
# retyping
my_con_2 <- form_retype(my_dis, "continuous")
meta_x_tbl(my_con_2)

# Method "dirac"
my_dirac <- form_retype(my_dis, "continuous", method = "dirac")
meta_x_tbl(my_dirac)

# Method "piecelin"
## From "continuous" to "discrete" (preferred direction)
my_dis_piece <- form_retype(my_con, "discrete", method = "piecelin")
meta_x_tbl(my_dis_piece)
## Conversion from "discrete" to "continuous" is very approximate
my_con_piece <- form_retype(my_dis_piece, "continuous", method = "piecelin")
meta_x_tbl(my_con_piece)

plot(my_con, main = 'Approximate nature of method "piecelin"')
lines(my_con_piece, col = "blue")

[Package pdqr version 0.3.1 Index]