# Graphing the average and standard deviation of multiple data sets

I am working with 5 different stress/strain data sets that I have graphed individually using ListPlot. Is there a way I can graph the average of the 5 sets and possibly show some form of a standard deviation using a shaded region? They have different increments of strain (some data sets may measure in increments of 1%, others in increments of .5%) if that affects the process.

Thank you so much!

• If you provide data with a sample image of the specified plot, makes answering a lot easier. Feb 20, 2021 at 7:38
• You may interpolate your data using Interpolateand then calculate data for common values of the independent variable. With these values you may get the mean and STD. Feb 20, 2021 at 13:34
• Do the datasets overlap at specific strain values? If so, it might be scientifically prudent to only average at those values, depending on how much you want to approximate. Otherwise, using Mathematica's curve-fitting functions (as Daniel Huber suggested) is a good idea. Feb 21, 2021 at 1:20
• Also, just to reiterate, if you provide the data, that would make this question answerable in more concrete terms! Feb 21, 2021 at 1:23
• Besides the data you also need to describe how the data was collected because if the calculation of the standard deviation is to make any sense, there should be an underlying model describing the error structure. In other words, it's not just about the data values.
– JimB
Feb 21, 2021 at 18:32

Let's start by creating some example datasets:

signal = Table[Sin[x], {x, Subdivide[0, 2 Pi, 100]}];
noise = {
RandomVariate[NormalDistribution[0.2, 0.1], 101],
RandomVariate[NormalDistribution[0.1, 0.2], 101],
RandomVariate[NormalDistribution[0.4, 0.3], 101],
RandomVariate[NormalDistribution[-0.1, 0.3], 101],
RandomVariate[NormalDistribution[-0.2, 0.25], 101]
};
data = signal + # & /@ noise;

Dimensions[data]


{5, 101}

ListPlot[data, ImageSize -> 500]


Now, for each point along the x-axis, compute the mean and standard deviation:

{mean, std} = Transpose[
{Mean[#], StandardDeviation[#]} & /@ Transpose[data]
];

ListPlot[
Append[data, mean],
Joined -> {False, False, False, False, False, True},
ImageSize -> 500
]


Now let us plot the standard deviation as a shaded area:

upper = mean + std;
lower = mean - std;
ListPlot[
Join[data, {mean, upper, lower}],
Joined -> {False, False, False, False, False, True, True, True},
ImageSize -> 500,
PlotStyle -> {Automatic, Automatic, Automatic, Automatic, Automatic, Automatic, None, None},
Filling -> {8 -> {7}}
]


You may find further inspiration in the post Plot confidence interval around curve.

Please let me know if this is not what you were looking for.