Least Square Regression¶
Chi-squared and maximum likelihood estimation¶
Suppose that our measurement data \(y_i\) is independent of each other and obeys \(N(\bar{y}_i, \sigma_i)\). Then likelihood function \(\mathcal{L}(\bar{\mathbf{y}} | \mathbf{y})\) is given by
, for some constant \(C\).
Define \(\chi^2\) as
then,
So, the log likelihood function \(\log \mathcal{L}(\bar{\mathbf{y}} | \mathbf{y})\) is
Thus, maximizing likelihood or log-likelihood is the same as minimizing \(\chi^2\).
In common fitting process we estimate \(\bar{y}_i\) as
, so our likelihood, log-likelihood and chi-squared function are the function of fitting parameter \(\mathbf{\theta}\).
Linear Least Square¶
Suppose that our fitting function \(f(x, \mathbf{\theta})\) is the linear combination of some function \(g_i(x)\) which does not depend on \(\mathbf{\theta}\).
Define matrix \(G\) as
and set \(\mathbf{y}' = \mathbf{y}/\mathbf{\sigma}\) then
To minimize \(\chi^2\), we require
Then, we have the following equation, usually called the normal equation.
The \((G^T G)^{-1}\) is called the parameter covariance matrix, which is denoted by \({Cov}\).
The standard error of paramter \({Err}(\mathbf{\theta})\) is defined as
, where \(N\) is the total number of data points, and \(p\) is the number of parameter.
Note that the \(G\) is also the scaled Jacobian of the model function \(f(x, \mathbf{\theta})\) concerning parameter \(\mathbf{\theta}\).
So, one can extend the definition of the parameter’s standard error in linear least square regression to a non-linear one.
, where \(J\) is the scaled jacobian of non-linear model function \(f(x, \mathbf{\theta})\) with respect to paramter \(\mathbf{\theta}\).
Such parameter error estimation is called Asymptotic Standard Error. However, strictly speaking, Asymptotic Standard Error estimation should not be used in non-linear least square regression.
Our package TRXASprefitpack provides an alternative error parameter estimation method based on the F-test.
Alternative Paramter Error Estimation¶
Define \(\chi^2_i(x)\) as
Then the number of parameters corresponding to \(\chi^2_i\) is \(P-1\).
F-test based paramter error estimation¶
Let \(\chi^2_0 = \chi^2(\theta_0)\) be the minimum chi-square value. One can estimates confidence interval of \(i\)th optimal parameter \(\theta_{0, i}\) with significant level \(\alpha\) by
Compare two different fit¶
Assume that model 2 is the restriction of model 1. Then, you can compare two models based on the f-test.
Separation Scheme¶
Suppose that
Then
The optimization problem
is just a linear least square problem described in a linear least square section, and we know the exact solution to such a problem. Let \(\mathbf{\theta}_{l} = \mathbf{C}(\mathbf{\theta})\) be the least norm solution of the linear least square problem then,
So, by chain rule the gradient of \(\chi^2(\mathbf{C}(\mathbf{\theta}), \mathbf{\theta})\) is
Because of \(\frac{\partial \mathbf{C}(\mathbf{\theta})}{\partial \mathbf{\theta}}\) term, the analytic hessian of \(\chi^2(\mathbf{C}, \mathbf{\theta})\) is quite complicated. Since v0.8, the analytic Hessian is implemented for the following three fitting drivers.
fit_static_voigtfit_transient_expfit_transient_raise
The Hessian of \(\chi^2(\mathbf{C}, \mathbf{\theta})\) is
Note that \(\frac{\partial \chi^2(\mathbf{C}(\mathbf{\theta}), \mathbf{\theta})}{\partial \mathbf{C}_j(\mathbf{\theta})} = 0\) for all \(\theta\). Take derivative of \(\mathbf{\theta}_i\) then
For simplicity, denote \(H_c = [\frac{\partial^2 \chi^2}{\partial C_i \partial C_j}]_{ij}\), \(H_{\theta} = [\frac{\partial^2 \chi^2}{\partial \theta_i \partial \theta_j}]_{ij}\), \(H_{\theta c} = [\frac{\partial^2 \chi^2}{\partial \theta_i \partial C_j}]_{ij}\), and \(B = [\frac{\partial C_i}{\partial \theta_j}]_{ij}\). Let the hessian matrix of \(\chi^2(\mathbf{C}, \mathbf{\theta})\) be \(H'\) then
The solution \(B\) satisfying \(H_{\theta c}^T = - H_c B\) is in general not unique. Let \(B' = B + N\), where \(H_c N = 0\). Then
Therefore, \(H'\) is well defined, even though \(B\) is not unique.
The separation scheme reduces the dimension of the optimization problem, and the gradient of \(\chi^2(C,\theta)\) is the same as that of the original \(\chi^2\) function, so implementing a separation scheme will speed up the optimization process.