# Curve fitting of (x,y) coordinates

I have three (x,y) coordinates that I got from experimental data. The coordinates represent drug solubility at corresponding pH values as appears below:

pH(x)   Solubility(y)
1.2      12.8
4.5      0.252
6.8      54.9


I want to create a function using these three points to describe the solubility as a function of pH. I know there might be an infinite number of functions that can be created. However, I am looking for something that best describe the observed data and doesn't give negative predictions for solubility. I tried quadratic polynomial using Excel. Although it is a good fit for the observed data, it gives negative predictions when the pH is in certain range.

So, I thought of using either:

1) A biexponential function. One exponential term to describe the decline and then another to describe the rise up again in solubility. This will always give positive predictions.

2) To use an exponential-quadratic function. where:

Solubility= EXP(A+B*(pH-D)+C*(pH-D)^2) ; A,B,C,D are coefficients.

Can anybody help me to curve-fit this data into the proposed functions above? or any other appropriate function that describes the data well so I can make inter- or extrapolation? The most important thing is that the function shouldn't give negative predictions (Y) for the pH range of (1-12). I read that curve-fitting can be done in MATLAB but I don't actually know MATLAB programming!

• "inter- or intrapolation": you may be getting confused about the difference between interpolation and extrapolation. Feb 25, 2015 at 9:41
• That was a typo. I corrected it. Cheers! Feb 26, 2015 at 12:36

With so little data, you should not be picking functions essentially "at random" like this.

1) It's essential to use subject-matter knowledge.

For example, in the case of pH dependent drug solubility, discussions such as the ones here or here discuss subject matter knowledge that seem to suggest somewhat different forms from those you have, though maybe you can justify something like your last equation using such considerations.

2) Even if all your observations were with no error whatever, you cannot fit more parameters than you have observations

3) Given that observations will contain error, you should have fewer parameters than observations; unless you can bring some external knowledge of likely parameter values (strong priors in a Bayesian context) or similar suitable information, the situation is almost hopeless.

If you really want to be able to identify the functional form from data without bringing in a lot of subject matter knowledge and not have the consequences of the model selection impact your estimation, you need enough data to identify a suitable model and to estimate the parameters from different parts of the data (or in some other way to separate the estimation from the bias that identification will bring in). Even with very low noise observations that's likely to require well into the dozens of observations to get a good idea of the function and to estimate its parameters -- and that is only if you consider extremely simple functional forms.

• Regarding using knowledge subject matter: I have investigated thoroughly the literature about the pH-solubility profile equations. These equations are theoretical and doesn't affect reality at all in my case. That is why I have experimental data and I am trying to get an empirical function that I may be able to use for interpolation and extrapolation. I agree that the optimal scenario is to have a lot of observations to be confident in choosing a function but unfortunately I am confined to the data that I have which is just three (x,y) coordinates. Feb 25, 2015 at 10:51
• I will be using the solubility function (if I succeed in getting one) in population modelling and I can account for variability in the solubility predictions. The functions that I proposed (the biexponential) and (the quadratic-exponential) are empirical, nevertheless, I have scientific background to explain them if one of them was able to describe the data. So, what I need is a help in how can I get these data fitted into one of these two or any others. I would appreciate if somebody can assist in this even with this limited data. Thank you. Feb 25, 2015 at 10:54
• I understand but as I mentioned before it doesn't need to be the function that I mentioned in the question. A function with 2 or 3 parameters is fine as far as it provides an adequate description of the data. Feb 25, 2015 at 13:25
• It is unclear what else you think we can tell you. Even functions that could be fitted to 3 data points will be spuriously close and there isn't information in the data to distinguish well between them. You need more data. If you want to change the question to what might you do if you had more data, I think that needs a new thread. Feb 25, 2015 at 16:11
• Given that - at least with enough researcher degrees of freedom - there are an infinite number of curves that would pass exactly through three points, what does "adequate description of the data" mean? With no points left over, you have no way to assess inadequacy Feb 25, 2015 at 20:48

I figured a way to do it:

Solubility= EXP(A+B*(pH-D)+C*(pH-D)^2)

log(Solubility) = A + B*(pH-D) + C*(pH-D)^2
= A + B*pH - B*D + C*pH^2 + C*D^2 - 2*C*D*pH
= a + b*pH + c*pH^2

#where a, b ,c are constants.

#let
x = pH, y = log(Solubility)

#by fitting this equation (polynomial regression)
y = a + b*x + c*x^2

y = 0.6305*pH^2 - 4.7843*pH + 7.3827
Solubility = EXP(y)


The function above guarantees positive predictions of solubility and provide an empirical description of the observed data.

• Your proposed solution is "take logs, fit a quadratic, exponentiate." Before you posted this I was working in my spare moments on a demonstration using this as an example of why your situation is hopeless! For example, there's a problem with this proposed solution -- in place of $\log$, I could substitute an infinity of other transformations that would result in an identical fit, but different (yet presumably still plausible) predictions elsewhere. ... (ctd) Feb 26, 2015 at 4:50
• (ctd) ... Worse, it takes no account whatever of the errors - even if the function was right, even modest errors in $x$ or $y$ could potentially yield large prediction errors. Unless you're heavily using in-subject knowledge that is not present in your question (in which case, that's a shabby way to treat potential responders), this is a highly inadvisable solution. Feb 26, 2015 at 4:52
• I am not using anything special Glen_b. I just did transformation for the data. I had a clear aim, in my question, on what I want to achieve. What I proposed is just one way to resolve my issue. I am sure there must be other ways to do it (an infinite; as you mentioned) but non was proposed to me as a potential solution; even if it has limitations to it! Feb 26, 2015 at 7:38
• There's a good reason none were proposed, as I've tried to explain. It's not because we don't know a way (your solution was immediately clear to me when I understood the question- obvious enough ... but the problems with it were equally obvious, hence the caution about actually suggesting it). I will add more to my answer soon, but I fear that it won't induce any additional caution. Feb 26, 2015 at 7:40
• Thanks a lot Glen. I, for sure, learned a lot from your specific comments on how to do things right. Any addition on your answer would be helpful for me and for other people running into such scenarios. Thank you. Feb 26, 2015 at 12:24