form_recenter: Change center and spread of distribution

View source: R/form-other.R

form_recenterR Documentation

Change center and spread of distribution

Description

These functions implement linear transformations, output distribution of which has desired center and spread. These functions are useful for creating distributions with some input center and spread value based on present distribution, which is a common task during hypothesis testing.

Usage

form_recenter(f, to, method = "mean")

form_respread(f, to, method = "sd", center_method = "mean")

Arguments

f

A pdqr-function.

to

A desired value of summary.

method

Method of computing center for form_recenter() and spread for form_respread(). Values should be one of possible method values from summ_center() and summ_spread() respectively.

center_method

Method of computing center for form_respread() in order to preserve it in output.

Details

form_recenter(f, to, method) is basically a f - summ_center(f, method) + to: it moves distribution without affecting its shape so that output distribution has center at to.

form_respread(f, to, method, center_method) is a following linear transformation: coef * (f - center) + center, where center is summ_center(f, center_method) and coef is computed so as to guarantee output distribution to have spread equal to to. In other words, this linear transformation stretches distribution around its center until the result has spread equal to to (center remains the same as in input f).

Value

A pdqr-function describing distribution with desired center or spread.

Examples

my_beta <- as_d(dbeta, shape1 = 1, shape2 = 3)

my_beta2 <- form_recenter(my_beta, to = 2)
summ_center(my_beta2)

my_beta3 <- form_respread(my_beta2, to = 10, method = "range")
summ_spread(my_beta3, method = "range")
## Center remains unchainged
summ_center(my_beta3)

pdqr documentation built on May 31, 2023, 8:48 p.m.