Curve fitting

stellanhakansson

New Member
Joined
Dec 30, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I have a data set showing survival of preterm infants by gestational age in days (d154-195). Excel gives a logarithmic trend line which seems to fit nicely, but the equation <y=22.22ln(x)+12.752> given for the line doesn't produce the y-values I expect by entering 'x'. I would be grateful for some advice.

All the best,
Stellan Hakansson
SurvivalByGestationalAge.png
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I'm puzzled by the trendline shown in your plot. I don't see the same extent of curvature and the fit is not very good. One issue I see is related to the representation of the y data, described as a survival percentage. Excel will treat 9 % as 0.09. I can't tell from the image included in your post what values are actually being used. Is the first y value about 9.09 or 0.0909? This becomes an issue because of the relative disparity when the numerical representations of x differ by two orders of magnitude and they are being multiplied by ln(x), which will have a value of approximately 5 over the entire range represented here.
Book1
HIJKLMNO
12.546680906-12.38901459
2Observed Survival_%(y)GA_d (x)Observed Survival (y)Original Estimated y=22.22ln(x)+12.752Semi-Log Regression (ln-lin)0.2282306291.177663775
39.0909090911540.090909091124.67308680.4384964260.7568524050.103088872
428.571428571550.285714286124.81690610.454979855124.509133140
546.153846151560.461538462124.95980050.4713572811.3231978370.425092619
630.769230771570.307692308125.10178180.487630057
754.166666671580.541666667125.24286160.503799514
8521590.52125.38305140.519866955
969.230769231600.692307692125.52236220.535833659
10601610.6125.6608050.551700881
1146.153846151620.461538462125.79839060.567469853
1270.588235291630.705882353125.93512950.583141785
1372.41379311640.724137931126.0710320.598717864
1464.864864861650.648648649126.20610840.614199254
1578.260869571660.782608696126.34036870.629587101
1676.190476191670.761904762126.47382250.644882528
1758.823529411680.588235294126.60647960.660086638
18701690.7126.73834940.675200516
19801700.8126.86944130.690225226
2062.162162161710.621621622126.99976420.705161813
2176.315789471720.763157895127.12932730.720011307
22751730.75127.25813920.734774716
2377.272727271740.772727273127.38620870.749453032
2482.857142861750.828571429127.51354430.764047232
2591.428571431760.914285714127.64015440.778558274
2684.615384621770.846153846127.76604710.792987099
271001781127.89123050.807334635
2882.758620691790.827586207128.01571260.821601793
2977.272727271800.772727273128.13950120.835789467
3087.234042551810.872340426128.2626040.849898538
3187.755102041820.87755102128.38502860.863929874
3285.714285711830.857142857128.50678230.877884324
3386.666666671840.866666667128.62787250.891762729
3494.230769231850.942307692128.74830640.905565911
3591.836734691860.918367347128.86809110.919294682
3691.48936171870.914893617128.98723350.932949841
3796.8751880.96875129.10574040.946532171
3890.909090911890.909090909129.22361870.960042446
39881900.88129.34087490.973481427
4093.333333331910.933333333129.45751560.986849861
4197.142857141920.971428571129.57354721.000148486
4296.774193551930.967741936129.6889761.013378027
4395.774647891940.957746479129.80380831.026539198
4491.780821921950.917808219129.91805021.039632702
Sheet1
Cell Formulas
RangeFormula
N1:O5N1=LINEST(K3:K44,LN(J3:J44),1,1)
K3:K44K3=H3/100
M3:M44M3=$N$1*LN(J3)+$O$1
Dynamic array formulas.

1685856360767.png
 
Upvote 0
Hi, Many thanks for advice and time spent. Actually I don't expect survival to be linear to gestational age (gradually improving by GA), and I tried instead a polynomial trend line giving R2 close to .9. I think that will do.
Best, Stellan
1685870119469.png
 
Upvote 0
Hi Stellan,

I wouldn't necessarily expect a linear trend either. I can't tell if that comment is due to my use of the LINEST function(?), but LINEST can be used to return the coefficients for many types of regression. In my last post, I used it for your original log-linear approach, and below I've extended it to perform a 2nd order polynomial regression and a linear regression. I am not surprised that log-linear (of the form y=a*ln(x) + c and shown in red) is very close to linear (of the form y = m*x + b and shown in blue)...that was the point I was making about the natural log of x over the domain shown. The range represented by ln(150) and ln(200) is [5.01, 5.3] -- hardly any variation at all -- and when multiplied by a coefficient (constant), there is very little variation in the first term of the log-lin model, so it appears to be nearly linear. Comparing the two curves on the plot confirms this. In the results delivered by LINEST, I've shown the fit coefficients in bold font and the R2 fit metric also in bold font.

Ideally, some underlying theory of the phenomena being investigated would offer insight into the model form used for regression. Given the biological nature of the data and assuming the data are representative of a single species, early deaths would shift the health of the gestating population upward (generally better health) and the number of premature deaths would therefore continue to decline. So I would expect the survivability rate to continuously increase, but at a lower rate, as a function of increasing gestational age until perhaps late term risks become significant and survivability might then decrease. I don't see clear indications in the data shown that such a downturn is real at very late gestational ages.

I would hesitate to apply a polynomial model to the data as it has the potential to introduce inflection points around which the local slope of the curve changes. These changes might be difficult to explain, and in some cases, the slope changes may defy logic. In any case, I suspect the preferred distributional models to consider for these data are found in survivability theory or reliability theory.
MrExcel_20230604.xlsx
HIJKLMNOPQR
1Regression Analysis
2Observed Survival_%(y)GA_d (x)Observed Survival (y)Original Estimated y=22.22ln(x)+12.752Semi-Log Regression (ln-lin)Polynomial 2o RegressionLinear RegressionSemi-Log (ln-lin)
39.0909090911540.090909091124.67308680.4384964260.3182028640.4537444892.546680906-12.38901459
428.571428571550.285714286124.81690610.4549798550.3525184980.4682247640.2282306291.177663775
546.153846151560.461538462124.95980050.4713572810.3858423650.4827050390.7568524050.103088872
630.769230771570.307692308125.10178180.4876300570.4181744630.497185313124.509133140
754.166666671580.541666667125.24286160.5037995140.4495147940.5116655881.3231978370.425092619
8521590.52125.38305140.5198669550.4798633560.526145862
969.230769231600.692307692125.52236220.5358336590.5092201510.540626137Polynomial (2nd order)
10601610.6125.6608050.5517008810.5375851770.555106412-0.0004958840.187543789-16.80315582
1146.153846151620.461538462125.79839060.5674698530.5649584350.5695866869.89452E-050.0345484913.004223678
1270.588235291630.705882353125.93512950.5831417850.5913399260.5840669610.8418817710.08419096#N/A
1372.41379311640.724137931126.0710320.5987178640.6167296490.598547235103.825438639#N/A
1464.864864861650.648648649126.20610840.6141992540.6411276030.613027511.4718538640.276436591#N/A
1578.260869571660.782608696126.34036870.6295871010.664533790.627507785
1676.190476191670.761904762126.47382250.6448825280.6869482080.641988059Linear
1758.823529411680.588235294126.60647960.6600866380.7083708590.6564683340.014480275-1.776217799
18701690.7126.73834940.6752005160.7288017410.6709486080.0013569460.237357593
19801700.8126.86944130.6902252260.7482408560.6854288830.7400488120.106591531
2062.162162161710.621621622126.99976420.7051618130.7666882020.699909158113.875041940
2176.315789471720.763157895127.12932730.7200113070.7841437810.7143894321.2938202740.454470182
22751730.75127.25813920.7347747160.8006075910.728869707
2377.272727271740.772727273127.38620870.7494530320.8160796340.743349981
2482.857142861750.828571429127.51354430.7640472320.8305599090.757830256
2591.428571431760.914285714127.64015440.7785582740.8440484150.772310531
2684.615384621770.846153846127.76604710.7929870990.8565451540.786790805
271001781127.89123050.8073346350.8680501240.80127108
2882.758620691790.827586207128.01571260.8216017930.8785633270.815751354
2977.272727271800.772727273128.13950120.8357894670.8880847620.830231629
3087.234042551810.872340426128.2626040.8498985380.8966144280.844711903
3187.755102041820.87755102128.38502860.8639298740.9041523270.859192178
3285.714285711830.857142857128.50678230.8778843240.9106984580.873672453
3386.666666671840.866666667128.62787250.8917627290.916252820.888152727
3494.230769231850.942307692128.74830640.9055659110.9208154150.902633002
3591.836734691860.918367347128.86809110.9192946820.9243862420.917113276
3691.48936171870.914893617128.98723350.9329498410.92696530.931593551
3796.8751880.96875129.10574040.9465321710.9285525910.946073826
3890.909090911890.909090909129.22361870.9600424460.9291481140.9605541
39881900.88129.34087490.9734814270.9287518690.975034375
4093.333333331910.933333333129.45751560.9868498610.9273638550.989514649
4197.142857141920.971428571129.57354721.0001484860.9249840741.003994924
4296.774193551930.967741936129.6889761.0133780270.9216125251.018475199
4395.774647891940.957746479129.80380831.0265391980.9172492081.032955473
4491.780821921950.917808219129.91805021.0396327020.9118941221.047435748
Sheet1
Cell Formulas
RangeFormula
M3:M44M3=$P$3*LN(J3)+$Q$3
N3:N44N3=$P$10*J3^2+$Q$10*J3+$R$10
O3:O44O3=$P$17*J3+$Q$17
P3:Q7P3=LINEST(K3:K44,LN(J3:J44),1,1)
P10:R14P10=LINEST(K3:K44,J3:J44^{1,2},1,1)
P17:Q21P17=LINEST(K3:K44,J3:J44,1,1)
K3:K44K3=H3/100
Dynamic array formulas.

1685889649305.png
 
Upvote 0
@ stellanhakansson: To me, it looks like a classic case of y=c-2^((a-x)/b).
The best fit is achieved with a=150.1493, b=7.811379, c=0.945035, R2=0.866651.
I think, however, that c should be set to the actual survival rate of full-term neonates (probably, around 0.98).
Good luck with your research!
 
Upvote 0
Hi,
Thank you for replies and bringing my question to higher levels. Much appreciated. I am still puzzled by the fact that Excel creates two different trend lines if the same data is depicted in a line-diagram or in a scatter-plot. The trend line of the line-diagram agrees well with my clinical impression, in that very few babies born at the limit of viability (gestational age 154 days) survive. Also there is a sharp increase in survival day by day thereafter, eventually tapering out close to 1. The trend line looks the same regardless of if survival is given as percent or actual ratio (survivors/live births). Excel changes the equation accordingly. Nevertheless the y-values calculated do not at all fit with the trend line although R2 is given as 0.8905. In contrast, the trend line of the scatter-plot gives a weaker fit (R2=0.7569), but calculated y-values agree with the line presented. To me the trend line given in the line-diagram gives a visual fit which corresponds nicely with my clinical experience, but the equation given by Excel remains a conundrum.

All the best,
Stellan
 

Attachments

  • Trend lines_survival_2.jpg
    Trend lines_survival_2.jpg
    154.4 KB · Views: 20
Upvote 0
Think I got it. The equation y=0.2222*ln(x-153)+0.1275 generates the trend line in the line-diagram, with x-values starting on 154. R2=0.8905.
Cheers!
Stellan
 
Upvote 0
Stellan, you've made some interesting observations. Until now, I was unable to reproduce your original plot. But you mentioned something about a line plot, as opposed to a scatter plot. I rarely use line plots in Excel because they seldom are appropriate for x-y data. See Microsoft's description about how the x-axis is handled differently for each of these plot types.
Your x-data cover the interval [154,195], and when your x-y data pairs are selected and a Line chart inserted, Excel will default to creating two curves: 1) one curve of the actual x-data, but treated as though they are y values having assumed x-values of 1, 2, 3,...; and 2) the other curve of the actual y-data, again having assumed x-values of 1, 2, 3, etc. If you then delete the line containing the actual x-values you are left with the actual y-data, and its shape is identical to what you would expect because your actual x-data increases is a sequence increasing by 1 (so there is no stretching or compression of the curve horizontally). Nearly anything can then be specified for the x-axis labels, but the underlying values used by Excel are 1, 2, 3, etc. The actual x-values are irrelevant. Below is an example where I substituted your actual x-values with the Fibonacci sequence (completely non-sensical, but illustrative). The Line chart depiction appears to have the correct shape, but the x-axis labels mean nothing with regard to how regression is handled. I selected the curve and added a logarithm trend line, and the results are the same as what you originally showed. But there is a clue here that helps to arrive at your most recent preferred model form. Note that the trend line appearance is the same as what you wanted. Excel obtained this trend line assuming x-values covering the interval [1,42], so the "x" in the trendline equation -- let's call it x0 -- needs to produce those values when using the actual x-values of [154,195]...therefore x0 = x-153, which leads to your most recent model form: y=0.2222*ln(x-153)+0.1275
1685988342740.png
 
Upvote 0
Dear Kirk,
Many thanks for you engagement and sharing your Excel wit. I have definitely learned a lot. Problem solved.
All the best,
/Stellan
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top