1.. _boxcox_transformation: 2 3Box Cox transformation 4====================== 5 6| We consider :math:`X: \Omega \times \cD \rightarrow \Rset^d` a 7 multivariate stochastic process of dimension :math:`d` where 8 :math:`\cD \in \Rset^n` and :math:`\omega \in \Omega` is an event. We 9 suppose that the process is :math:`\cL^2(\Omega)`. 10| We note :math:`X_{\vect{t}}: \Omega \rightarrow \Rset^d` the random 11 variable at the vertex :math:`\vect{t} \in \cD` defined by 12 :math:`X_{\vect{t}}(\omega)=X(\omega, \vect{t})`. 13| If the variance of :math:`X_{\vect{t}}` depends on the vertex 14 :math:`\vect{t}`, the Box Cox transformation maps the process 15 :math:`X` into the process :math:`Y` such that the variance of 16 :math:`Y_{\vect{t}}` is constant (at the first order at least) with 17 respect to :math:`\vect{t}`. 18| We present here: 19 20- the estimation of the Box Cox transformation from a given field of 21 the process :math:`X`, 22 23- the action of the Box Cox transformation on a field generated from 24 :math:`X`. 25 26| We note :math:`h: \Rset^d \rightarrow \Rset^d` the Box Cox 27 transformation which maps the process :math:`X` into the process 28 :math:`Y: \Omega \times \cD \rightarrow \Rset^d`, where 29 :math:`Y=h(X)`, such that :math:`\Var{Y_{\vect{t}}}` is independent of 30 :math:`\vect{t}` at the first order. 31| We suppose that :math:`X_{\vect{t}}` is a positive random variable for 32 any :math:`\vect{t}`. To verify that constraint, it may be needed to 33 consider the shifted process :math:`X+\vect{\alpha}`. 34| We illustrate some usual Box Cox transformations :math:`h` in the 35 scalar case (:math:`d`\ =1), using the Taylor development of 36 :math:`h: \Rset \rightarrow \Rset` at the mean point of 37 :math:`X_{\vect{t}}`. 38| In the multivariate case, we estimate the Box Cox transformation 39 component by component and we define the multivariate Box Cox 40 transformation as the aggregation of the marginal Box Cox 41 transformations. 42 43| **Marginal Box Cox transformation:** 44| The first order Taylor development of :math:`h` around 45 :math:`\Expect{Y_{\vect{t}}}` writes: 46 47 .. math:: 48 49 \forall \vect{t} \in \cD, h(X_{\vect{t}}) = h(\Expect{X_{\vect{t}}}) + (X_{\vect{t}} - \Expect{X_{\vect{t}}})h'(\Expect{X_{\vect{t}}}) 50 51which leads to: 52 53 .. math:: 54 55 \Expect{h(X_{\vect{t}})} = h(\Expect{X_{\vect{t}}}) 56 57and then: 58 59 .. math:: 60 61 \Var{h(X_{\vect{t}})} = h'(\Expect{X_{\vect{t}}})^2 \Var{X_{\vect{t}}} 62 63To have :math:`\Var{h(X_{\vect{t}})}` constant with respect to 64:math:`\vect{t}` at the first order, we need: 65 66.. math:: 67 :label: eqh 68 69 h'(\Expect{X_{\vect{t}}}) = k \left( \Var{X_{\vect{t}}} \right)^{-1/2} 70 71Now, we make some additional hypotheses on the relation between 72:math:`\Expect{X_{\vect{t}}}` and :math:`\Var{X_{\vect{t}}}`: 73 74- If we suppose that 75 :math:`\Var{X_{\vect{t}}} \propto \Expect{X_{\vect{t}}}`, then 76 :eq:`eqh` leads to the function :math:`h(y) \propto \sqrt{y}` and we 77 take :math:`h(y) = \sqrt{y}, y~>~0`; 78 79- If we suppose that 80 :math:`\Var{X_{\vect{t}}} \propto (\Expect{X_{\vect{t}}})^2` , then 81 :eq:`eqh` leads to the function :math:`h(y) \propto \log{y}` and we 82 take :math:`h(y) = \log{y}, y>0`; 83 84- More generally, if we suppose that 85 :math:`\Var{X_{\vect{t}}} \propto (\Expect{X_{\vect{t}}})^{\beta}`, 86 then :eq:`eqh` leads to the function :math:`h_\lambda` parametrized by 87 the scalar :math:`\lambda`: 88 89 .. math:: 90 :label: BoxCoxModel 91 92 h_\lambda(y) = 93 \left\{ 94 \begin{array}{ll} 95 \frac{y^\lambda-1}{\lambda} & \lambda \neq 0 \\ 96 \log(y) & \lambda = 0 97 \end{array} 98 \right. 99 100 101where :math:`\lambda = 1-\frac{\beta}{2}`. 102 103The inverse Box Cox transformation is defined by: 104 105.. math:: 106 :label: InverseBoxCoxModel 107 108 h^{-1}_\lambda(y) = 109 \left\{ 110 \begin{array}{ll} 111 \displaystyle (\lambda y + 1)^{\frac{1}{\lambda}} & \lambda \neq 0 \\ 112 \displaystyle \exp(y) & \lambda = 0 113 \end{array} 114 \right. 115 116| **Estimation of the Box Cox transformation:** 117| The parameter :math:`\lambda` is estimated from a given field of the 118 process :math:`X` as follows. 119| The estimation of :math:`\lambda` given below is optimized in the case 120 when :math:`h_\lambda(X_{\vect{t}}) \sim \cN(\beta , \sigma^2 )` at 121 each vertex :math:`\vect{t}`. If it is not the case, that estimation 122 can be considered as a proposition, with no guarantee. 123| The parameters :math:`(\beta,\sigma,\lambda)` are then estimated by 124 the maximum likelihood estimators. We note 125 :math:`\Phi_{\beta, \sigma}` and :math:`\phi_{\beta, \sigma}` 126 respectively the cumulative distribution function and the density 127 probability function of the :math:`\cN(\beta , \sigma^2)` 128 distribution. 129| For all vertices :math:`\vect{t}`, we have: 130 131 .. math:: 132 :label: cdfYt 133 134 \forall v \geq 0, \, \Prob{ X_{\vect{t}} \leq v } = \Prob{ h_\lambda(X_{\vect{t}}) \leq h_\lambda(v) } \\ 135 = \Phi_{\beta, \sigma} \left(h_\lambda(v)\right) 136 137from which we derive the density probability function :math:`p` of 138:math:`X_{\vect{t}}` for all vertices :math:`\vect{t}`: 139 140.. math:: 141 :label: pdfYt 142 143 p(v) = h_\lambda'(v)\phi_{\beta, \sigma}(v) = v^{\lambda - 1}\phi_{\beta, \sigma}(v) 144 145Using :eq:`pdfYt`, the likelihood of the values 146:math:`(x_0, \dots, x_{N-1})` with respect to the model :eq:`cdfYt` 147writes: 148 149.. math:: 150 :label: LKH 151 152 L(\beta,\sigma,\lambda) = 153 \underbrace{ \frac{1}{(2\pi)^{N/2}} 154 \times 155 \frac{1}{(\sigma^2)^{N/2}} 156 \times 157 \exp\left[ 158 -\frac{1}{2\sigma^2} 159 \sum_{k=0}^{N-1} 160 \left( 161 h_\lambda(x_k)-\beta 162 \right)^2 163 \right] 164 }_{\Psi(\beta, \sigma)} 165 \times 166 \prod_{k=0}^{N-1} x_k^{\lambda - 1} 167 168We notice that for each fixed :math:`\lambda`, the likelihood equation 169is proportional to the likelihood equation which estimates 170:math:`(\beta, \sigma^2)`. Thus, the maximum likelihood estimator for 171:math:`(\beta(\lambda), \sigma^2(\lambda))` for a given :math:`\lambda` 172are: 173 174.. math:: 175 :label: eqBetaSigma 176 177 \hat{\beta}(\lambda) = \frac{1}{N} \sum_{k=0}^{N-1} h_{\lambda}(x_k) \\ 178 \hat{\sigma}^2(\lambda) = \frac{1}{N} \sum_{k=0}^{N-1} (h_{\lambda}(x_k) - \beta(\lambda))^2 179 180| Substituting :eq:`eqBetaSigma` into :eq:`LKH` and taking the 181 :math:`\log-`\ likelihood, we obtain: 182 183 .. math:: 184 :label: lLambda 185 186 \ell(\lambda) = \log L( \hat{\beta}(\lambda), \hat{\sigma}(\lambda),\lambda ) = C - 187 \frac{N}{2} 188 \log\left[\hat{\sigma}^2(\lambda)\right] 189 \;+\; 190 \left(\lambda - 1 \right) \sum_{k=0}^{N-1} \log(x_i)\,, 191 192where :math:`C` is a constant. 193 194The parameter :math:`\hat{\lambda}` is the one maximizing :math:`\ell(\lambda)` defined in :eq:`lLambda`. 195 196.. topic:: API: 197 198 - See :class:`~openturns.BoxCoxTransform` 199 - See :class:`~openturns.InverseBoxCoxTransform` 200 - See :class:`~openturns.BoxCoxFactory` 201 202.. topic:: Examples: 203 204 - See :doc:`/auto_probabilistic_modeling/stochastic_processes/plot_box_cox_transform` 205 206