I have two different data sets to be fitted with two different models with the NonlinearModelFit, that is model1 will fit data1 and model2 will fit data2. The data takes also into account the error of the measurement. Both models share the same parameters a and b which are the ones we are interested in fitting. In the attached and runnable code I fitted the parameters without taking into account the errors. My question is how to consider the errors through the Weights command of the NonlinearModelFit where each error data set should be associated to the considered data set. How to do this association/splitting when fitting? Thanks a lot in advance.
data1 = {{1, 1, 1/2}, {2, 2, 0.1}, {3, 3, 0.4}, {4, 4, 0.2}, {5, 5, 0.3}, {6, 2, 0.1}}
data1xy = Table[{data1[[i, 1]], data1[[i, 2]]}, {i, 1, Length[data1]}]
error1 = Table[data1[[i, 3]], {i, 1, Length[data1]}]
data2 = {{1, 2, 0.1}, {2, 4, 0.2}, {3, 5, 0.5}, {4, 7, 0.3}, {5, 3, 0.2}, {6, 1, 0.1}}
data2xy = Table[{data2[[i, 1]], data2[[i, 2]]}, {i, 1, Length[data2]}]
error2 = Table[data2[[i, 3]], {i, 1, Length[data2]}]
allData = Join[{1, Sequence @@ #} & /@ data1xy, {2, Sequence @@ #} & /@ data2xy]
model1par[index_, x_] := KroneckerDelta[index - 1]*(1 + a*x + b*x^2) + KroneckerDelta[index - 2]*(1 + a*x + b*x^3)
fit1par = NonlinearModelFit[allData, model1par[index, x], {a, b}, {index, x}, PrecisionGoal -> 2, WorkingPrecision -> 10]
fit1par["BestFitParameters"]
fit1par["EstimatedVariance"]
fit1par["ParameterConfidenceIntervalTable"]