twopiece is an R package for the family of two-piece distributions, a
flexible class of unimodal distributions constructed by joining two rescaled
half-densities of a symmetric baseline distribution at the mode. This simple
construction introduces asymmetry while preserving the tail behaviour and shape
of the chosen baseline, making two-piece distributions a tractable and
interpretable alternative to standard symmetric models.
Given a unimodal symmetric (about 0) probability density function
where
# install.packages("devtools")
devtools::install_github("FJRubio67/twopiece")
library(twopiece)The package provides density (d), distribution (p), quantile (q), and
random sampling (r) functions for two-piece distributions with three or four
parameters:
| Function | Description |
|---|---|
dtp3 / ptp3 / qtp3 / rtp3
|
Two-piece distributions with 3 parameters ( |
dtp4 / ptp4 / qtp4 / rtp4
|
Two-piece distributions with 4 parameters ( |
The baseline distribution is passed as a function argument (e.g. FUN = dnorm,
FUN = dt), making the package compatible with any symmetric unimodal baseline
available in R.
Three parameterisations of asymmetry are supported via the param argument:
param |
Parameterisation |
|---|---|
"tp" |
Two-piece: separate scale parameters |
"eps" |
Epsilon-skew: single scale |
"isf" |
Inverse scale factors: single scale |
For full documentation: ?dtp3, ?dtp4
library(twopiece)
# Two-piece normal: asymmetric with heavier right tail
x <- seq(-5, 10, length.out = 500)
plot(x, dtp3(x, mu = 0, par1 = 1, par2 = 3, FUN = dnorm, param = "tp"),
type = "l", ylab = "Density", main = "Two-piece Normal")
# Random sampling
sim <- rtp3(1000, mu = 0, par1 = 1, par2 = 3, FUN = rnorm, param = "tp")- The family of two-piece distributions — mathematical background and examples
- twopiece R package — package walkthrough
- DTP — Double two-piece distributions (R)
- TPSAS — Two-piece sinh-arcsinh distributions (R)
- FlexBinReg — Binary regression with two-piece link functions
This package is licensed under the MIT License.