Reputation: 11
I am working in Mathematica with data set and have plotted them in the form of 2D graph. How to take Mean and SD of some specific range in the graph and to show them using horizontal and vertical lines on the graph (the range and the mean value).
I have tried and I am able to take only the General mean (all range included), What I am looking for is to get mean from specific range in the graph and also to show in on the graph curve.
Upvotes: 1
Views: 112
Reputation: 8655
pts = {{1., 1.}, {1.331, 1.416}, {1.432, 1.118}, {1.775, 1.155},
{1.856, 1.789}, {2.179, 2.572}, {2.199, 1.938}, {2.461, 1.938},
{2.501, 2.498}, {2.723, 3.505}, {2.945, 2.647}, {3.046, 1.938},
{3.207, 2.796}, {3.288, 4.102}, {3.611, 3.468}, {3.732, 4.587},
{3.873, 6.042}, {4.337, 3.58}, {4.156, 1.826}, {4.64, 2.311},
{4.539, 4.512}, {4.378, 5.892}, {4.922, 6.676}, {5.124, 4.251},
{4.963, 3.356}, {5.467, 3.43}, {5.346, 4.773}, {5.487, 5.706},
{5.79, 5.034}, {5.89, 4.363}, {6.153, 3.691}, {6.395, 4.661},
{6.576, 4.214}};
rangebound = Select[pts, 3 <= First[#] <= 6 &];
mean = Mean[Last /@ rangebound];
sd = StandardDeviation[Last /@ rangebound];
ListPlot[{Complement[pts, rangebound], rangebound},
PlotStyle -> {Green, Blue},
Epilog -> {Gray, Line[{{3, 0}, {3, 7}}], Line[{{6, 0}, {6, 7}}],
Red, Line[{{3, mean}, {6, mean}}],
Orange, Line[{{3, mean + sd}, {6, mean + sd}}],
Line[{{3, mean - sd}, {6, mean - sd}}]},
PlotLegends -> Placed[LineLegend[{Red, Orange},
{"mean", "mean +/- 1 sd"}, LegendFunction -> "Frame",
LegendLayout -> "Column", Joined -> True], {0.25, 0.75}],
ImageSize -> 400]
Re. 68–95–99.7 rule, up to 68.27% of the blue points fall within the orange lines.
12 out 19 are within the orange lines. If it were 13 out of 19 that would be 68.4% which is outside of the one-sigma range.
Upvotes: 0