2
$\begingroup$

I am using Mathematica 9, and have a data set

    frequencyList = {{2474, 190538, 431994, 427498, 327605, 118881, 23976,
    2396, 232}, {16, 33353, 278360, 381675, 373560, 170125, 30784, 
   1996, 165}, {3, 4405, 100438, 209268, 216642, 116648, 23048, 1317, 
   115}, {1, 481, 27457, 84359, 99450, 61592, 14431, 907, 88}, {0, 62,
    6539, 28778, 40288, 28101, 7846, 541, 52}, {0, 9, 1394, 9747, 
   17079, 13422, 4117, 305, 27}, {0, 4, 324, 3265, 7736, 7252, 2436, 
   198, 32}, {0, 10, 308, 1753, 6279, 8942, 4473, 447, 33}}

which represents the number of live births in 2015 in the USA. Rows index the birth "parity" (birth order) and columns index the mothers' age in 5-year blocks: 10≤age<15, 15≤age<20, etc. It is an 8 x 9 matrix.

With the parity and age conjoined, the data appears as

    parityAgeFrequencyTable = 
    Table[{i, j*5 + 7.5, frequencyList[[i, j]]}, {i, 8}, {j, 9}]

    {{{1, 12.5, 2474}, {1, 17.5, 190538}, {1, 22.5, 431994}, {1, 27.5, 
   427498}, {1, 32.5, 327605}, {1, 37.5, 118881}, {1, 42.5, 
   23976}, {1, 47.5, 2396}, {1, 52.5, 232}}, {{2, 12.5, 16}, {2, 17.5,
    33353}, {2, 22.5, 278360}, {2, 27.5, 381675}, {2, 32.5, 
   373560}, {2, 37.5, 170125}, {2, 42.5, 30784}, {2, 47.5, 1996}, {2, 
   52.5, 165}}, {{3, 12.5, 3}, {3, 17.5, 4405}, {3, 22.5, 100438}, {3,
    27.5, 209268}, {3, 32.5, 216642}, {3, 37.5, 116648}, {3, 42.5, 
   23048}, {3, 47.5, 1317}, {3, 52.5, 115}}, {{4, 12.5, 1}, {4, 17.5, 
   481}, {4, 22.5, 27457}, {4, 27.5, 84359}, {4, 32.5, 99450}, {4, 
   37.5, 61592}, {4, 42.5, 14431}, {4, 47.5, 907}, {4, 52.5, 
   88}}, {{5, 12.5, 0}, {5, 17.5, 62}, {5, 22.5, 6539}, {5, 27.5, 
   28778}, {5, 32.5, 40288}, {5, 37.5, 28101}, {5, 42.5, 7846}, {5, 
   47.5, 541}, {5, 52.5, 52}}, {{6, 12.5, 0}, {6, 17.5, 9}, {6, 22.5, 
   1394}, {6, 27.5, 9747}, {6, 32.5, 17079}, {6, 37.5, 13422}, {6, 
   42.5, 4117}, {6, 47.5, 305}, {6, 52.5, 27}}, {{7, 12.5, 0}, {7, 
   17.5, 4}, {7, 22.5, 324}, {7, 27.5, 3265}, {7, 32.5, 7736}, {7, 
   37.5, 7252}, {7, 42.5, 2436}, {7, 47.5, 198}, {7, 52.5, 32}}, {{8, 
   12.5, 0}, {8, 17.5, 10}, {8, 22.5, 308}, {8, 27.5, 1753}, {8, 32.5,
    6279}, {8, 37.5, 8942}, {8, 42.5, 4473}, {8, 47.5, 447}, {8, 52.5,
    33}}}.

I would like to display this data as a 3-d histogram — sort of a boxy version of

ListPlot3D[frequencyList, PlotRange -> All]

with well-defined bins 1 baby x 5 years in size, along with axis labels and tick marks.

I didn't find this question already listed… I hope it's not redundant.

I'm also wondering if there is such a thing as HistogramDistribution for bivariate data like this, since I will have some ugly computations to do with the data.

$\endgroup$
1
  • 4
    $\begingroup$ Have you looked at Histogram3D? $\endgroup$
    – bill s
    Commented Feb 2, 2017 at 21:40

3 Answers 3

2
$\begingroup$

While birth order isn't a continuous variable you could still produce a Histogram3D as suggested by @bills. This uses the WeightedData option to account for the count frequencies.

parityAgeFrequencyTable = Flatten[Table[{i-0.5, j*5 + 7.5, frequencyList[[i, j]]}, {i, 8}, {j, 9}], 1];
x = parityAgeFrequencyTable[[All, {1, 2}]];
w = parityAgeFrequencyTable[[All, 3]];
Histogram3D[WeightedData[x, w], {{0.5, 8.5, 1}, {5}}, 
 AxesLabel -> (Style[#, Bold, Larger] & /@ {"Birth order", "Mother's age", "Frequency"})]

3D histogram

$\endgroup$
1
  • $\begingroup$ Nice solution. I can actually understand it, even though I would not have figured it out myself. Again, sorry my low rep can't increment your answer score. $\endgroup$ Commented Mar 6, 2017 at 21:27
1
$\begingroup$
BarChart3D[frequencyList, ChartLayout -> "Grid", 
  ChartLabels -> {Range[8], Row[{##}, "-"] & @@@ Partition[Range[10, 55, 5], 2, 1]}, 
  AxesLabel -> {"Mother's Age", "BirthOrder",  "Frequency"}, 
  "Canvas" -> False]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ Wow. I will have to study this. Great color choice! Sorry my low rep can't increment your answer score yet. $\endgroup$ Commented Mar 6, 2017 at 21:20
  • $\begingroup$ @kglr woinderful +1 :) The row separators was a neat touch. $\endgroup$
    – ubpdqn
    Commented Apr 4, 2017 at 7:07
  • $\begingroup$ @ubpdqn, thank you for the upvote. $\endgroup$
    – kglr
    Commented Apr 4, 2017 at 20:47
0
$\begingroup$
mydata = Flatten[
  parityAgeFrequencyTable = 
   Table[{i, j*5 + 7.5, frequencyList[[i, j]]}, {i, 8}, {j, 9}], 1]

ListPlot3D[mydata, InterpolationOrder -> 0]
$\endgroup$
2
  • $\begingroup$ This is good enough. I really don't need to show the "sides" of the bins. $\endgroup$ Commented Feb 3, 2017 at 18:25
  • $\begingroup$ @R. Peter DeLong... so does my answer deserve an up-vote or check-acceptance? $\endgroup$ Commented Feb 3, 2017 at 19:36

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.