--------------------------------------------------- lines 6-157 of file: example/user/data_mismatch.cpp --------------------------------------------------- {xrst_begin data_mismatch.cpp} {xrst_spell nowrap } Random Effects Variance May Cause Data Mismatch ############################################### Model ***** .. math:: \B{p}( z | \theta ) \sim \B{N} ( \theta , \sigma_z^2 ) .. math:: \B{p}( y | \theta ) \sim \B{N} [ \exp( u ) \theta , \sigma_y^2 ] .. math:: \B{p}( u | \theta ) \sim \B{N} ( 0 , \sigma_u^2 ) The fixed likelihood :ref:`g(theta)` is .. math:: g( \theta ) = \frac{1}{2} \left[ \log ( 2 \pi \sigma_z^2 ) + ( z - \theta )^2 \right] The random likelihood :ref:`f(theta, u)` is .. math:: f(\theta , u ) = \frac{1}{2} \left[ \log ( 2 \pi \sigma_u^2 ) + u^2 / \sigma_u^2 + \log ( 2 \pi \sigma_y^2 ) + [ y - \exp(u) \theta ]^2 / \sigma_y^2 \right] Mismatch ******** In the case where :math:`y = z`, one might expect the solution :math:`\theta = z` and :math:`u = 0` because all the data residuals are zero, :math:`\B{p}(u | \theta )` is maximal, and there is no prior for :math:`\theta`. This example demonstrates that :math:`\theta = z` and :math:`u = 0` may not be optimal for the this case. To be specific it shows that the derivative of :ref:`L(theta)` may be non-zero. Theory ****** See the :ref:`theory-title` section for the theory behind the calculations below: Derivatives *********** .. math:: :nowrap: \begin{eqnarray} g_\theta ( \theta ) & = & ( \theta - z ) \sigma_z^{-2} \\ f_\theta ( \theta , u ) & = & [ \exp(u) \theta - y ] \exp(u) \sigma_y^{-2} \\ f_u ( \theta , u ) & = & u / \sigma_u^2 + [ \exp(u) \theta - y ] \exp(u) \theta \sigma_y^{-2} \\ f_{u,u} ( \theta , u ) & = & \sigma_u^{-2} + [ 2 \exp(u) \theta - y ] \exp(u) \theta \sigma_y^{-2} \\ f_{u,\theta} ( \theta , u ) & = & [ 2 \exp(u) \theta - y ] \exp(u) \sigma_y^{-2} \\ \hat{u}_\theta ( \theta ) & = & - f_{u,\theta} [ \theta , \hat{u} ( \theta ) ] / f_{u,u} [ \theta , \hat{u} ( \theta ) ] \\ f_{u,u,u} ( \theta , u ) & = & [ 4 \exp(u) \theta - y ] \exp(u) \theta \sigma_y^{-2} \\ f_{u,u,\theta} ( \theta , u ) & = & [ 4 \exp(u) \theta - y ] \exp(u) \sigma_y^{-2} \end{eqnarray} Objective ********* .. math:: :nowrap: \begin{eqnarray} h( \theta , u ) & = & \frac{1}{2} \log f_{u,u} ( \theta , u ) + f( \theta , u ) - \log( 2 \pi ) \\ h_\theta ( \theta , u ) & = & \frac{1}{2} f_{u,u,\theta} ( \theta , u ) / f_{u,u} ( \theta , u ) + f_\theta ( \theta , u ) \\ h_u ( \theta , u ) & = & \frac{1}{2} f_{u,u,u} ( \theta , u ) / f_{u,u} ( \theta , u ) + f_u ( \theta , u ) \\ L( \theta ) & = & h [ \theta , \hat{u} ( \theta ) ] + g ( \theta ) \\ L_\theta ( \theta ) & = & h_\theta [ \theta , \hat{u} ( \theta ) ] + h_u [ \theta , \hat{u} ( \theta ) ] \hat{u}_\theta ( \theta ) + g_\theta ( \theta ) \end{eqnarray} {xrst_literal // BEGIN C++ // END C++ } {xrst_end data_mismatch.cpp}