Suppose you have N correlated data points and M parameters to fit a model. Then, you can construct the $\chi^2$ function as

$\chi^2 = (\vec{y}_{data} - \vec{y}_{theo}) \cdot C^{-1} \cdot (\vec{y}_{data} - \vec{y}_{theo})$ ,

where $\vec{y}_{data}$ is the vector with the data points, $\vec{y}_{theo}$ is the theoretical vector with the M parameters that follows the model under test and $C^{-1}$ is the covariance matrix of data points. Thus, to best fit the model, you need to minimize $\chi^2$ with respect to the M parameters, i.e.,

$\frac{\partial \chi^2}{\partial a_i} = 0, \quad i=0,1,...,M-1$.

What is the best function on Mathematica to do this job? In addition, a correlation matrix must be a sub-product of this procedure. NonlinearModelFit didn't work in this situation, and I'm not finding any useful build-in function.

Thanks in advance, Gabriel.

  • 1
    $\begingroup$ I am quite confident that it isLinearModelFit or NonlinearModelFit what should be employed here. What happend when you tried NonlinearModelFit? What was the code? Why do you think it did not work? How the the model look? Many. many questions that are open... $\endgroup$ – Henrik Schumacher Mar 10 '18 at 16:55
  • $\begingroup$ You should use NMinimize $\endgroup$ – OkkesDulgerci Mar 10 '18 at 19:42
  • 1
    $\begingroup$ If you have real data and the model with parameters, please share to get quick response. $\endgroup$ – OkkesDulgerci Mar 10 '18 at 19:43
  • $\begingroup$ You didn't even mention if the model is linear or not. $\endgroup$ – J. M.'s technical difficulties Mar 10 '18 at 22:14
  • $\begingroup$ The model isn't linear. I found an alternative to this type of analysis: one can minimize the function with Nminimize and then define a $\Delta \chi^2$ function such that $\Delta \chi^2 = \chi^2 - \chi_{min}^2$, where $\chi_{min}^2$ is the value of the function in the minimum. Then, you can consult tables of confidence intervals to plot the regions of interest using the ConditionalExpression in the Plot. Anyway, thanks all for the time and the help. Hope this helps, too. Best regards, Gabriel $\endgroup$ – Gabriel Das Neves Mar 11 '18 at 14:43