# fitting different data sets with different models with NonlinearModelFit

GROUPS:
 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"]
4 years ago
6 Replies
 Hi, you may find some of the material in this post to be useful for your own situation:http://community.wolfram.com/groups/-/m/t/53970In short, the built in model fitters don't have this ability, but it's usually feasible to write some code to resolve the issue. In particular consider the links below:In Wolfram Library there is an upload:Multiple-Response Fitting by Bruce MillerDaniel sent a few links - perhaps they will be useful:http://mathematica.stackexchange.com/questions/866/simultaneously-fitting-multiple-datasetshttp://forums.wolfram.com/mathgroup/archive/2011/Sep/msg00555.html (this one links to the four below)http://forums.wolfram.com/mathgroup/archive/2004/Oct/msg00031.htmlhttp://forums.wolfram.com/mathgroup/archive/2006/Apr/msg00011.htmlhttp://forums.wolfram.com/mathgroup/archive/2006/Apr/msg00020.htmlhttp://forums.wolfram.com/mathgroup/archive/2010/Apr/msg00280.html
4 years ago
 Hi Sean, first of all thank you for your kindly attention. I know the links you provided to me, but as far as know none of them treat what I want to do, none of them consider errors in a serious way. I want to find the way to select each error data set depending the data to be fitted with a given model. I did (in the simple code attached as an example) something similiar to the example given in the link below (see at the end, it is done without errors) but now I want to consider errors. http://mathematica.stackexchange.com/questions/15905/combined-fitting-via-nonlinearmodelfitTo sum up, I agree with you I have to write a code to resolve the issue, but after fighting for a week I still have not found the right way to deal with. Any idea would be more than appreciated. Thanks a lot. Sergi
4 years ago
 I checked this Fitting Multiple-Response Data Bruce Miller's package, but it does not consider errors.I mean, I know how to fit different data sets with different models, I provided a simple example, but now I have to find the way to select the corresponding error data sets when fitting a given data sets with the corresponding model. Thanks a lot