I am trying to fit my data to a combined function model. Say I have two functions with some common parameter(s)
f[x_]:= a*x^2 + b*x + c
g[x_]:= d*x^2 + e*x + c
Also, I have separate data and errors for these two functions.
Performing the fit is easy: I create the chi-squared function manually and minimize via NMinimize
. In my work the code is rather lengthy, but looks similar to
Chi2[data_, errors_, dataprime_, errorsprime] :=
Sum[((data[[i, 2]] - f[data[[i, 1]]])/errors[[i]])^2,{i, 1, Length[data]}] +
Sum[((data[[i, 2]] - g[data[[i, 1]]])/errors[[i]])^2,{i, 1, Length[data]}];
where data
and dataprime
are the different datasets for the functions f[x]
and g[x]
respectively (data[[i,1]]
represents, say, the i-th x value while data[[i,2]]
represents what f[data[[i,1]]]
should be, say, y).
However, I would like to perform, using the values obtained from NMinimize
, a NonlinearModelFit.
This would give me error estimation for parameters (which are hard to get with my current technique) and also provides confidence band levels and other features which are quite useful to me.
However, I haven't been able to find the way to implement a NonlinearModelFit ... any suggestion?
(I already did a search and found some links related to calculating the errrors through the Hessian. However, this is not convenien for me due to errors in calculating the inverse of the Hessian.)
Thanks in advance!
myfunc[y_, x_] := (a*x)*KroneckerDelta[1 - y];
And then performed the NonlinearModelFiteo = NonlinearModelFit[{{1, 1, 2.6}, {1, 2, 6.1}, {1, 3, 9.3}, {1, 4,11.9}, {1, 5, 15.4}}, myfunc[y, x], {a}, {y, x}]
Howevere I get some error: "Experimental`NumericalFunction::dimsl: "{x} given in {y,x} should be a list of dimensions for a particular argument" Though fit seems ok. I don't get the problem, do you wonder what may be? THanks in advance! $\endgroup$