PTMLocScaleDataGen#
- class liesel_ptm.PTMLocScaleDataGen(shape, loc_fn=None, scale_fn=None, ncov=0, zmin=-2.5, zmax=2.5, use_norm_at_zero=True)[source]#
Bases:
DataGenerator
Draws random samples from a location-scale transformation model.
- Parameters:
shape (
Any
) – A vector of shape parameters \(\boldsymbol{\delta}\) used to define the transformation function.loc_fn (
Optional
[Callable
[[Any
],Any
]]) – A function taking in a 2d array of covariates, returning a 1d array of locations. (default:None
)scale_fn (
Optional
[Callable
[[Any
],Any
]]) – A function taking in a 2d array of covariates, returning a 1d array of scales. (default:None
)ncov (
int
) – An integer, giving the number of covariates to generate. (default:0
)zmin (
float
) – Lower and upper boundary knot locations, respectively. (default:-2.5
)zmax (
float
) – Lower and upper boundary knot locations, respectively. (default:2.5
)use_norm_at_zero (
bool
) – IfTrue
, the transformation function is shifted such that \(h(0)=0\) before inversion. Should be kept this way, this option exists mainly for testing purposes. (default:True
)
Examples
Example without covariates:
>>> import liesel_ptm as ptm >>> import jax
>>> key1 = jax.random.PRNGKey(21) >>> key2 = jax.random.PRNGKey(42) >>> shape = ptm.sample_shape(key1, nshape=10, scale=0.5).sample
>>> dg = ptm.PTMLocScaleDataGen(shape=shape) >>> sample = dg.sample(key2, nobs=10) >>> sample_df = dg.to_df(sample) >>> sample_df[["y", "pdf"]].head() y pdf 0 -2.283257 0.087928 1 0.430342 0.645286 2 0.091028 0.449210 3 0.552843 0.651007 4 0.443428 0.648257
Example with one covariate, using the same shape:
>>> dg = ptm.PTMLocScaleDataGen(shape=shape, loc_fn=lambda x: 1.5*x, ncov=1) >>> sample = dg.sample(key2, nobs=10) >>> sample_df = dg.to_df(sample) >>> sample_df[["y", "pdf"]].head()
Methods
Evaluates a number of quantities given fitting arrays of
z
andx
.Location function.
Normalization function \(h(\varepsilon)\).
Inverse of the normalization function.
Draws random samples from the transformation model implied by
shape
,loc()
, andscale()
.Scale function.
Takes a data dictionary as returned by
sample()
and turns it into apandas.DataFrame
.Full transformation function, including the scale and location parts.
Derivative of the full transformation function, including the scale and location parts.
Inverse of the full transformation function, including the scale and location parts.
Attributes