Skip to content

FAQ-D/SUMM transformation functions current code and location #7244

Open

Description

@josef-pkt

We have collections of non-linear functions and links, partially spread out over different parts of statsmodels

main

  • genmod Links, monotonic
  • genmod varfuncs
  • robust norms, used as objective functions, mostly symmetric u or v shaped, with redescending tails, not really "transform" classes
  • base.transform contains Box-Cox including estimation code
  • copulas: Archimedean generator transforms, Pickand dependence function for EV (same pattern but not really a transform)

other (not in official use)

  • statsmodels.sandbox.distributions.transform_functions : old code mostly for u-shaped transformation of variables for distributions, transformed module also contains simple examples like log transform

linear/affine

  • linalg transformation to impose constraints base._constraints.TransformRestriction linear multivariate transformation
  • linalg statsmodels.tools.transform_model only contains StandardizeTransform, with estimation mean, scale, linear transformation
    I guess not in use yet.

we also have other linalg functions that are projections and similar, all linalg versions are linear or affine transformations

multivariate transforms

  • mnlogit, links for GEE
  • compositional data transform: Simplex^{k} -> R^{k-1} where are those?
  • ?

Other in use

  • penalization functions, similar to robust norms, are u- or v-shaped
  • We also have hardcoded, specific use case transformations, e.g. for hypothesis test of correlation, proportion and similar variables on limited domains or Logit transform in discrete Logit, Exp transform in count models

design issues

I think I start tools.transforms in parallel to genmod links for new distribution classes #7241, now in PR #7246
A collection of functions and derivatives, no data involved. i.e. different from Box-Cox in base.transform
(transforms is plural noun as in links)

Another possibility:
Add an Inverted class, that just flips transform with inverted transform. With that we can use generic code that uses transforms in both directions, i.e. Link = Inverted(Transform)
e.g. log = Inverted(Exp) where Exp is a class name and log is an instance of a transform class

many related issues and many different internal use cases


list of transformations

that follow links, transforms pattern (with derivatives)

links

  • Log/Exp
  • logit, not a subclass of CDFLink, CDFLink is subclass of Logit
  • CLogLog, subclass of logit, What's the equivalence as CDFLink? (extreme value distribution ?)
  • power
  • NegativeBinomial link, (I never looked closely at that)
  • CDFLinks
    • probit, normal, gaussian,
    • cauchy
    • student-t
    • ..

transforms

  • SinhArcsinh
  • Sinh, Johnson-SU
  • BirnbaumSaunders
  • TMI, R to R+, name TMI = "t minus inverse t" = t - 1/t. rename?
  • RtoInterval
  • RplustoInterval. odds/logit transformation (logit without exp)
  • Johnson-SB transformation ? same as logit transformation, log-odds ?
  • TMI with other powers? generalized BS- or TMI-transformation
  • [ ]

some are combination transformation e.g. johnson-SB is log plus odds/logit transformation
Log-BirnBaumSaunders is a Sinh, BirnbaumSaunders has a square-root compared to TMI

terminology

Logit uses log/exp, i.e. combines Logistic/Odds + Log ? mapping R -> R+
continued in next comment

Activity

  1. josef-pkt commented on Jan 7, 2021

    @josef-pkt
    MemberAuthor

    move question from first comment and continue here

    Is Logit the cdf of log-logistic distribution?
    check

    We need "logistic" (?) transformation R+ -> (0, 1) separately. That's a basic/canonical transformation in Jones 2007

    also check;
    Logit as CDFLink versus log-logistic CDFLink versus Johnson-SB distribution
    all 3 combine log/exp with the logit/odds transformation x / (1 - x)
    My current guess:
    links.logit = CDF_log-logistic and
    log-logistic defines the same transformation as johnson-sb from normality

    update

    I got this reversed
    logistic distribution has cdf 1 / (1 + exp(-y)) y = x / b
    log-logistic distribution has cdf 1 / (1 + z)**b

    so logistic has the exp to define domain in R
    and log-logistic has no exp and requires domain R+

    https://en.wikipedia.org/wiki/Logistic_distribution
    https://en.wikipedia.org/wiki/Log-logistic_distribution

    "If X has a log-logistic distribution with scale parameter alpha and shape parameter beta then Y = log(X) has a logistic distribution with location parameter log(alpha) and scale parameter 1/beta ."

  2. josef-pkt commented on Jan 7, 2021

    @josef-pkt
    MemberAuthor

    still need beta family and beta composed flexible distributions, but those might not be transformation of variables.

    one relate to odds transformation

    If X ~ Beta(a, b). then X / (1-X} ~ BetaPrime(a, b)
    https://en.wikipedia.org/wiki/Beta_prime_distribution

    Beta domain (0, 1) or [0, 1]
    BetaPrime domain R+ closed at zero (not R++), i.e. [0, inf), also called Beta of second kind

    also section 4.1 in Jones 2007, which also include distribution on domain R
    Beta of the third kind, based on TMI transform AFAICS

    Another relationship

    inverted Pit makes every cdf into a transformation from (0, 1) to a new domain, i.e. CdfLink is transform from original domain to uniform distribution on (0, 1)

    and we can apply transformation IntervaltoR directly on the uniform, i.e. cdf is then equal to inverse transform of RtoInterval

    I haven't looked at details for Beta generated flexible distributions and how they fit in.

    some of this might mainly be of theoretical interest and to write unit tests that exploit various relationships
    e.g. I can test BirnbaumSounders transformation by applying it to normal distribution and comparing with the corresponding distribution in scipy.stats.

  3. josef-pkt commented on Jan 10, 2021

    @josef-pkt
    MemberAuthor

    funny,
    I had defined copulas also mostly through transformations with methods evaluate, inverse and deriv, deriv2, but no deriv_inverse. deriv_inverse have been added for archimedean transforms (at least up to 4th derivative of inverse function)

    looks like univariate, bivariate and multivariate transformations mixed together.

  4. josef-pkt commented on Feb 3, 2023

    @josef-pkt
    MemberAuthor

    doc problem: __call__ method in links is not clickable in class docstring, i.e. we cannot see its docstring
    e.g. https://www.statsmodels.org/dev/generated/statsmodels.genmod.families.links.Log.html

    possible solution: define evaluate method and make __call__ an alias of evaluate
    most of transforms that I implemented have evaluate method but often no __call__ method

  5. changed the title [-]FAQ-D/SUM transformation functions current code and location[/-] [+]FAQ-D/SUMM transformation functions current code and location[/+] on Nov 1, 2023
  6. josef-pkt commented on Nov 1, 2023

    @josef-pkt
    MemberAuthor

    The above all seem to ignore parameterized transforms, i.e. with need classes for transforms that use auxiliary parameters as args or kwargs in methods.
    Current parameterized function fix the parameter in __init__ which makes it difficult to include it in a model that estimates those auxiliary parameters.
    e.g.
    parameterized varfuncs for #9050
    and parameterized link functions #5409 #624

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions