6.3.14. statsmodels.sandbox.distributions.transformed

A class for the distribution of a non-linear monotonic transformation of a continuous random variable

simplest usage: example: create log-gamma distribution, i.e. y = log(x),

where x is gamma distributed (also available in scipy.stats)

loggammaexpg = Transf_gen(stats.gamma, np.log, np.exp)

example: what is the distribution of the discount factor y=1/(1+x)
where interest rate x is normally distributed with N(mux,stdx**2)’)? (just to come up with a story that implies a nice transformation)

invnormalg = Transf_gen(stats.norm, inversew, inversew_inv, decr=True, a=-np.inf)

This class does not work well for distributions with difficult shapes,
e.g. 1/x where x is standard normal, because of the singularity and jump at zero.
Note: I’m working from my version of scipy.stats.distribution.
But this script runs under scipy 0.6.0 (checked with numpy: 1.2.0rc2 and python 2.4)

This is not yet thoroughly tested, polished or optimized

TODO:
  • numargs handling is not yet working properly, numargs needs to be specified (default = 0 or 1)
  • feeding args and kwargs to underlying distribution is untested and incomplete
  • distinguish args and kwargs for the transformed and the underlying distribution - currently all args and no kwargs are transmitted to underlying distribution - loc and scale only work for transformed, but not for underlying distribution - possible to separate args for transformation and underlying distribution parameters
  • add _rvs as method, will be faster in many cases

Created on Tuesday, October 28, 2008, 12:40:37 PM Author: josef-pktd License: BSD

6.3.14.1. Functions

absfunc(x)
derivminus(x)
derivplus(x)
examples_transf()
get_u_argskwargs(**kwargs)
identit(x)
inverse(x)
inverseminus(x)
inverseplus(x)
inversew(x)
inversew_inv(x)
iteritems(obj, **kwargs) replacement for six’s iteritems for Python2/3 compat
negsquarefunc(x)

6.3.14.2. Classes

ExpTransf_gen(kls, *args, **kwargs) Distribution based on log/exp transformation
LogTransf_gen(kls, *args, **kwargs) Distribution based on log/exp transformation
SquareFunc class to hold quadratic function with inverse function and derivative
TransfTwo_gen(kls, func, funcinvplus, ...) Distribution based on a non-monotonic (u- or hump-shaped transformation)
Transf_gen(kls, func, funcinv, *args, **kwargs) a class for non-linear monotonic transformation of a continuous random variable