# How to show that many functions (a hundred, a thousand) have the same shape an distribution of values over an interval?

I have functions that on iterval [0,1] all seem to look like this: i.e. they have a zero around 0.4 +ve derivative from zero to 0.4 and around zero or slightly negative derivative up to 1. I plan to show that they are all in fact very similar on this interval. I will need to do that for at least hundreds of such distributions. I thought that this could be done visually by sampling the values of the functions for the same arguments (say 500 evenly spaced x) then plotting one of such functions on a probability plot as reference and the adding hundreds of others on top - should be a more or less a straight line.

Below is a qq plot of two such samples:

Are there any better or more formal methods of doing this -what would be you advice?

A Q-Q plot approach would not be appropriate for your objective. Not only that, it would give you misleading results. This is because a Q-Q plot changes the order of the data, arranging it in ascending order; you thus lose all relationship to the x axis. As a simple counter-example, take the example function in your graph; now mirror it around the line $$x=.5$$ (that is, reverse the order of the data points; the value at $$x=0$$ becomes the value at $$x=1$$, the next sample becomes the next to last sample, etc.). The Q-Q plot of these 2 function $$f(x), f(1-x)$$ would be a perfect diagonal, but the 2 functions would be very different (mirrors of each other).
Yes, you could, as suggested, just superimpose the traces. That will allow you to eyeball the similarities. Good visualization, but does not quite quantify the degree -or lack thereof- of similarity.
Now, the Q-Q plot idea was not w/o merit; you are indeed trying to "compare" 2 (and many more) functions. In fact, you are trying to see how correlated they are. So just plot a scatter plot of these 2 functions. If they are "very similar", that scatter plot will "hug" the diagonal (and in this case, my counter-example would not at all be on the diagonal). But then you can take that comparison much further than an eyeballing test: you can use all the correlation/linear regression tools.

• If the 2 are "similar" you would expect the correlation to be linear. The correlation coefficient(s) ($$R, R^2$$ or other) should be close to 1.
• The slope of the linear regression should also be close to 1; if not there is a multiplicative bias between your 2 variables ($$f_1(x), f_2(x)$$).
• The intercept should also be close to 0; if not there is an additive bias between the 2 functions
• You can obtain CIs for these 2 regression coefficients; if they do not contain, respectively, 1 or 0, you have a significant difference.
• You can look at the sampling distribution of these 2 coefficients (and of $$R^2$$, etc.), and do statistics on that.
• You can even compute a Kolmogorov-Smirnov (K-S) statistics (or other equivalent ones) to provide yet another metric of non-similarity of the 2 functions. K-S looks at the empirical CDF; in your case, compute it directly on the 2 functions.
• Etc. Bottom line, not only can you visualize whether they are "very similar" via the scatter plot, you can quantify how "similar" they are, and express that similarity statistically.

You could perform all pairwise comparisons. But if you have hundreds of functions to compare, that will quickly become impractical. My suggestion is to take the average value at each x, over all the functions. This will be your "archetype" or control function; you can them run hundreds of comparisons to that archetype. Note that, once you have computed this mean value, you can also compute a CI for that mean value, for each x. You could also use the median, or a trimmed mean, etc. and/or perform some smoothing on that control. That should not matter too much. I would stick with the mean and its CI.
Then run a scatter plot of a given function against the control; highlight the diagonal, but you can also plot the CI around the diagonal. And then you can plot one or more function, against the control, on the same graph. For each scatter plot of a single function against the control, you would then compute a linear regression, look at the $$R^2$$ coefficient, at the slope and intercept, and at their CIs, and at the K-S statistic. All these would be diagnostics of "similarity" (up to you to pick thresholds/criteria which are relevant to your end purpose).
Certainly visualizing the data is important, and informative, but using the correlation/regression tools will give you much more quantitative, and actionable information.

• Than you for this very detailed answer. Commented Jul 18 at 0:27
• There is much good detail here. But while pairwise correlations (so long as you check for zero intercept and unit slope) are relevant to comparing any two traces, you need to extend that to the comparison of a thousand or so traces. So you end with thousands and thousands of correlations, intercepts and slopes! Looking at the sampling distribution appears to be your suggestion there. I have to suggest that this raises the spectre of a very elaborate and over-extended analysis. Just possibly, PCA might help but the whole strategy seems a little over the top. Commented Jul 18 at 9:54
• FWIW, the last letters of Kolmogorov and Smirnov are identical in Russian. So,while -ov and -off are respectively modern and old-fashioned ways to transliterate, the choice should be consistent. Commented Jul 18 at 9:56

To show that several functions are more or less the same you could just superimpose them graphically.

I don't think quantile plots of any flavour are directly relevant or likely to be helpful. The point is not whether the distributions are similar, but whether the functional traces are similar. I am a very big fan of quantile plots, but they aren't the answer here. After all, you could draw random samples from a uniform distribution (or any other brand-name distribution) in some sequence; the sample distributions would be very similar by virtue of what you're doing, but the random sequences would be all over the place.

The result of superimposing traces may look like spaghetti, but if they really are all or almost all the same, that shouldn't matter. Conversely, it could be that your impression is exaggerated and if even a few functions are quite different that should show up.

There are many variations on this. For example, calculate the mean across your functions and then plot each function as deviations from the mean function.

As underlined by @Frans Rodenburg in comments, exploit any scope in your software to use transparency.

• (+1) It may also help to use transparency (an alpha channel) for the color of the lines, such that overlap will present itself as a darker color. If you're in R, there's a nice function that does this for you, called densCols. Commented Jul 17 at 11:52
• Indeed, transparency should help. Commented Jul 17 at 11:54

You could fit $$y = a_0 + a_1 x + a_2 (x-0.4)^+$$, which is a piecewise linear function, with a single kink/knot at 0.4. This is a simple linear regression, so should be possible to fit with any statistical software and even excel