# Finding best fit curve line for a list of data .

Hi I have a question to find the best average fit curve for a range of data. I have calculated the best fit curve for each sample and plotted them on the same graph.

However, I would need to find one best average fit curve for the samples.

Each 5cm and 10cm sample strips have a different resolution of data point due to the length.

n of 5cm= 4 data point. n of 10cm=7 data point.

How can I present all these data using one fit curve function to best describe the material property? Appreciate the help. Thank you.

Strain5S1A ={{0, 11.908}, {1/5, 10.95}, {2/5, 9.31429}, {3/5, 7.925}}

Strain5S2A = {{0, 9.79}, {1/5, 10.0533}, {2/5, 8.29143}, {3/5, 7.255}}

Strain5S3A = {{0, 9.062}, {1/5, 9.66}, {2/5, 7.94}, {3/5, 6.88}}

Fit[Strain5S1A, {1, x, x^2, x^3, x^4, x^5, x^6, x^7, x^8, x^9}, x]
11.908 - 3.56549 x - 4.91491 x^2 - 5.19945 x^3 - 4.22877 x^4 -
1.51311 x^5 + 3.93156 x^6 + 13.864 x^7 + 31.2896 x^8 + 61.2614 x^9

Fit[Strain5S2A, {1, x, x^2, x^3, x^4, x^5, x^6, x^7, x^8, x^9}, x]
9.79 + 4.23116 x - 9.92041 x^2 - 18.8954 x^3 - 20.2853 x^4 -
12.5264 x^5 + 7.85467 x^6 + 47.7993 x^7 + 119.711 x^8 + 244.784 x^9

Fit[Strain5S3A, {1, x, x^2, x^3, x^4, x^5, x^6, x^7, x^8, x^9}, x]
9.062 + 6.23579 x - 10.8221 x^2 - 21.8441 x^3 - 23.9361 x^4 -
15.3418 x^5 + 7.88265 x^6 + 53.6945 x^7 + 136.361 x^8 + 280.29 x^9

Strain10YS1A={{0, 10.26}, {1/10, 13.1455}, {1/5, 11.7917}, {3/10, 10.9769}, {2/5,10.1643}, {1/2, 9.49333}, {3/5, 8.78125}}

Strain10YS2A = {{0, 10.07}, {1/10, 11.9545}, {1/5, 10.7667}, {3/10, 9.95385}, {2/5, 9.42857}, {1/2, 8.73333}, {3/5, 8.18125}

Strain10YS3A ={{0, 11.14}, {1/10, 14.4455}, {1/5, 12.0583}, {3/10, 10.8769}, {2/5,10.0643}, {1/2, 9.40667}, {3/5, 8.7625}}

Fit[Strain10YS1A, {1, x, x^2, x^3, x^4, x^5, x^6, x^7, x^8, x^9}, x]
10.26 + 82.9517 x - 749.402 x^2 + 2225.02 x^3 - 961.595 x^4 -
4466.33 x^5 - 982.501 x^6 + 9738.87 x^7 + 14133.2 x^8 - 25235.3 x^9

Fit[Strain10YS2A, {1, x, x^2, x^3, x^4, x^5, x^6, x^7, x^8, x^9}, x]
10.07 + 55.5134 x - 496.657 x^2 + 1368.24 x^3 - 421.139 x^4 -
2602.53 x^5 - 901.393 x^6 + 5061.21 x^7 + 7973.12 x^8 - 12754.1 x^9

Fit[Strain10YS3A, {1, x, x^2, x^3, x^4, x^5, x^6, x^7, x^8, x^9}, x]
11.14 + 108.573 x - 1052. x^2 + 3163.19 x^3 - 1319.32 x^4 -
6310.38 x^5 - 1519.02 x^6 + 13487.1 x^7 + 19828.8 x^8 - 34740.2 x^9

Combine =
Show[ListPlot[{Strain5S1A, Strain5S2A, Strain5S3A},
PlotLegends -> {"5cm"}, PlotStyle -> Pink],
ListPlot[{Strain10YS1A, Strain10YS2A, Strain10YS3A},
PlotLegends -> {"10cm"}, PlotStyle -> Green],
PlotStyle -> Pink],
PlotStyle -> Green], PlotRange -> {0, 25},
PlotLabel -> "All Strips Measurement ",
AxesLabel -> {"\[CurlyEpsilon]", "k\[CapitalOmega]/ cm"}]

• Jul 9, 2018 at 16:20
• @MarcoB While I'm certainly not supportive of some aspects of this question (for reasons given below), I think that this is NOT a duplicate as the appropriate answer deals with necessary features that Mathematica doesn't currently have, i.e., mixed models. So this question is much more complex than the suggested duplicate.
– JimB
Jul 9, 2018 at 19:25
• @JimB Thank you for pointing that out. I had overlooked that difficulty. I retracted my close vote. Jul 9, 2018 at 20:22

 Strain5S1A = {{0, 11.908}, {1/5, 10.95}, {2/5, 9.31429}, {3/5, 7.925}};

Strain5S2A = {{0, 9.79}, {1/5, 10.0533}, {2/5, 8.29143}, {3/5, 7.255}};

Strain5S3A = {{0, 9.062}, {1/5, 9.66}, {2/5, 7.94}, {3/5, 6.88}};
Strain10YS1A = {{0, 10.26}, {1/10, 13.1455}, {1/5, 11.7917}, {3/10,
10.9769}, {2/5, 10.1643}, {1/2, 9.49333}, {3/5, 8.78125}};

Strain10YS2A = {{0, 10.07}, {1/10, 11.9545}, {1/5, 10.7667}, {3/10,
9.95385}, {2/5, 9.42857}, {1/2, 8.73333}, {3/5, 8.18125} };
Strain10YS3A = {{0, 11.14}, {1/10, 14.4455}, {1/5, 12.0583}, {3/10,
10.8769}, {2/5, 10.0643}, {1/2, 9.40667}, {3/5, 8.7625}} ;
data = Join[Strain10YS1A, Strain10YS2A, Strain10YS3A, Strain5S1A,
Strain5S2A, Strain5S3A];
g1 = ListPlot[data]
fd = FindFit[data, {a + b*x + c*x^2 + d*x^3 + e*x^4}, {a, b, c, d, e},
x]
fdata = a + b*x + c*x^2 + d*x^3 + e*x^4 /. fd
Show[{g1, Plot[fdata, {x, 0, .6}]}] • While this approach gets curve that goes through the middle of the points, it completely ignores the experimental design where the units of replication are the strip samples (and not the individual data points) and that the 10 cm strips have a smaller variance than the 5 cm strips. While the predictions might very well be adequate, any estimation of the precision of a prediction is at best suspect because of ignoring the experimental design.
– JimB
Jul 9, 2018 at 19:20
• For physical applications, such an approach is common - it is customary to use data obtained in various experiments and to select a general dependence for them. Jul 10, 2018 at 3:32
• I have no doubt about that.
– JimB
Jul 10, 2018 at 4:00
• But more seriously...The fitted coefficients might not be too bad when the experimental design is ignored (although sometimes it can go horribly wrong). But the problem is that the measures of precision ($R^2$, root mean square error, standard errors of the coefficient estimators, etc.) are likely to be very wrong (and usually over-optimistic). I think that's not noticed because it seems that measures of precision are not examined as frequently (as in all of the time) as they should be.
– JimB
Jul 10, 2018 at 4:14

This is not answer to the question but rather an extended comment: You should consult with a statistician.

Fitting a 9th-order polynomial with just 7 unique predictor values is to put it mildly: overly optimistic.

Here's a plot of your data:

ListPlot[{Strain10YS1A, Strain10YS2A, Strain10YS3A, Strain5S1A,
Strain5S2A, Strain5S3A}, PlotRange -> {{0, 0.7}, {6, 15}},
PlotRangeClipping -> False,
PlotMarkers -> \[FilledCircle],
PlotStyle -> {Red, Green, Cyan, Blue, Black, Gray},
PlotLegends -> {"Strain10YS1A", "Strain10YS2A", "Strain10YS3A",
"Strain5S1A", "Strain5S2A", "Strain5S3A"}] At best one has a common curve but with separate intercepts. And the relationship with the predictor variable and the response is pretty linear if one ignores the predictor variable value of zero. Also, most of the responses for the 5cm observations are lower than the 10cm observations.

What you have is called a "mixed model" (and probably a nonlinear mixed model) with separate mean intercepts for 5 cm and 10 cm sample strips along with random intercepts for each sample strip.

Mathematica does not currently have a function (equivalent to NonlinearModelFit, GeneralizedLinearModel, and LinearModelFit) to deal with mixed models. After consulting with a statistician you might want to consider using SAS or R for the analysis.