0
$\begingroup$

I am wondering in Mathematica

Can we generate histogram plot with descriptive statistics, such as mean, median, and skewness, attached to the plot ?

For example, we may place all the statistics to the right of the plot

Here is what I have done. First I created the function:

descriptivestatistics[
  data_] := {{"Mean", "Median", "Stdv.", "Skewness", 
    "Kurtosis"}, {Mean[data], Median[data], StandardDeviation[data], 
    Skewness[data], Kurtosis[data]}} // TableForm

Then, I placed them on the same list as follows:

{Histogram[data,"PDF",Automatic],descriptivestatistics[data]},

but I think there is better way to do it.

Also, I want to export to be a report e.g., .doc or .pdf

Can any one give me suggestions ?

Thank you

$\endgroup$
2
$\begingroup$

Mathematica's symbolic graphics architecture gives you a lot of flexibility to construct composite graphics. A simple way could be:

d = RandomVariate[NormalDistribution[], 100];
descriptivestatistics[data_] := {{"Mean", "Median", "Stdv.", "Skewness", 
   "Kurtosis"}, {Mean[data], Median[data], 
   StandardDeviation[data], Skewness[data], Kurtosis[data]}} // 
 Transpose // Grid // Panel;
GraphicsGrid[{{Histogram@d, descriptivestatistics@d}}]

enter image description here

The documentation on Export will explain how you can export to various formats.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks a lot. How do you move the box on the right to get close to the histogram plot? $\endgroup$ – newbie Feb 26 '14 at 7:46
3
$\begingroup$

Alternatively, with

d = RandomVariate[NormalDistribution[], 100];
descriptivestatistics[data_] := {Mean[data], Median[data], 
  StandardDeviation[data], Skewness[data], Kurtosis[data]}

we construct labels & legend

hdr = {"Mean", "Median", "Std. Dev.", "Skewn.", "Kurt"};
tds = ToString@PaddedForm[#, {5, 2}] & /@ descriptivestatistics[d];
ltxt = StringJoin[hdr[[#]], ": ", tds[[#]]] & /@ Range[5];
lgd = Text[Style[ltxt[[#]], Bold], {-3, 25 - 1.4 #}, {-1, 0}] & /@ 
   Range[5];

We can use this as

Histogram[d, 10,
 Frame -> True,
 FrameLabel -> {"Band", "Count"},
 ImagePadding -> {{Automatic, 2}, {Automatic, 2}},
 Epilog -> lgd
 ]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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