3
$\begingroup$

I have a data

Clear["Global`*"];
data = {134, 121, 147, 158, 178, 127, 141, 175, 123, 145, 147, 132, 
   161, 172, 156, 123, 163, 126, 127, 163, 155, 148, 177, 142, 168, 
   179, 136, 164, 174, 156, 137, 130, 140, 145, 160, 169, 136, 130, 
   128, 148, 157, 121, 153, 156, 120, 127, 133, 169, 133, 130};

I tried

Mean[data]
Median[data]
Quartiles[data]
Variance[data]
StandardDeviation[data]

and got

enter image description here

If I have a table

enter image description here

I tried

ClearAll["Global`*"]
data = {{120, 130}, {130, 140}, {140, 150}, {150, 160}, {160, 
    170}, {170, 180}};
freq = {10, 10, 9, 7, 8, 6};
list = Table[Mean[data[[i]]], {i, 1, Length[data]}];
n = Sum[freq[[i]], {i, 1, Length[data]}]
mymean = freq . list/n
myVariance = 
 Sum[freq[[i]]*(list[[i]] - mymean)^2, {i, 1, Length[data]}]/n
myStandardDeviation = Sqrt[myVariance]

enter image description here

How can I find Median, Quartiles of above grouped frequency table?

$\endgroup$
1
  • $\begingroup$ Through[{Mean, Median, Quartiles, Variance, StandardDeviation}[data]] is a nice way to map several functions across one dataset $\endgroup$ Commented Sep 4 at 4:11

1 Answer 1

7
$\begingroup$

There are probably several alternatives depending on exactly what kind of statistics you want, your context, and what data you actually have. If you literally just have that table (i.e. if we ignore the data you provided, which seems to be the basis of that table), then I might try WeightedData and/or HistogramDistribution.

boundaries = Range[120, 180, 10];
frequencies = {10, 10, 9, 7, 8, 6};
binMeans = Mean /@ Partition[boundaries, 2, 1];
weighted = WeightedData[binMeans, frequencies];
weightedHist = HistogramDistribution[weighted, {10}];

{Mean[weightedHist], Mean[weighted]}
(* {736/5, 736/5} *)

{Variance[weightedHist], Variance[weighted]}
(* {289.493, 339.565} *)

{StandardDeviation[weightedHist], StandardDeviation[weighted]}
(* {17.0145, 18.4273} *)

... and so forth

Based on your updates, I thought I should point out that Mathematica uses unbiased variance, while your "by hand" computations use biased variance. So, again, it depends on which statistics exactly that you want and how you want to model the data represented by your table.

$\endgroup$
1
  • $\begingroup$ I tried two methods of your code. I don't get similar result with OP'S code. How can I do? $\endgroup$ Commented Sep 5 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.