Initial Exploration

$\mathrm{RandomInteger}\left[\left\{0,1\right\},\text{}20\right]$

$\left\{1,1,1,1,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0,0\right\}$

$\mathrm{RandomVariate}\left[\mathrm{UniformDistribution}\left[\left\{0,1\right\}\right]\right]$

$0.6531459162175581$

$\mathrm{Count}\left[\mathrm{RandomInteger}\left[\left\{0,1\right\},\text{}20\right],\text{}0\right]$

$8$

$\mathrm{ListLinePlot}\left[\mathrm{Table}\left[\mathrm{Accumulate}\left[\mathrm{RandomReal}\left[\left\{-1,1\right\},250\right]\right],\left\{3\right\}\right],\mathrm{Filling}\to \mathrm{Axis},\mathrm{PlotLegends}\to \left\{"one","two","three"\right\}\right]$ $\mathrm{Accumulate}\left[\mathrm{RandomInteger}\left[\left\{0,1\right\},\text{}10\right]\right]$

$\left\{1,1,2,2,3,4,5,5,6,7\right\}$

$\mathrm{ListLinePlot}\left[%\right]$ $\mathrm{Table}\left[\mathrm{RandomInteger}\left[\left\{0,1\right\},1\right],10\right]$ $\mathrm{MovingAverage}\left[\left\{\left\{0\right\},\left\{1\right\},\left\{1\right\},\left\{1\right\},\left\{0\right\},\left\{1\right\},\left\{0\right\},\left\{1\right\},\left\{0\right\},\left\{1\right\}\right\}\right]$

$\mathrm{Accumulate}\left[\mathrm{RandomInteger}\left[\mathrm{BernoulliDistribution}\left[0.5\right],1000\right]\right]/\mathrm{Range}\left[1000\right]\text{}//\text{}\mathrm{ListPlot}$ $\mathrm{Accumulate}\left[\mathrm{RandomVariate}\left[\mathrm{NormalDistribution}\left[\right],5000\right]\right]/\mathrm{Range}\left[5000\right]\text{}//\text{}\mathrm{ListPlot}$ $\mathrm{ListPlot}\left[\mathrm{RandomVariate}\left[\mathrm{NormalDistribution}\left[\right],1000\right],\mathrm{Filling}\to \mathrm{Axis}\right]$ $\mathrm{ListPlot}\left[\mathrm{RandomVariate}\left[\mathrm{GeometricDistribution}\left[1/2\right],50\right],\mathrm{Filling}\to \mathrm{Axis}\right]$ $\mathrm{Accumulate}\left[\mathrm{RandomInteger}\left[\left\{0,1\right\},100\right]\right]/\mathrm{Range}\left[100\right]\text{}//\text{}\mathrm{ListPlot}$ $\mathrm{Plot}\left[6x\left(1-x\right),\left\{x,0,1\right\},\mathrm{Filling}->\mathrm{Bottom}\right]$ $\mathrm{Integrate}\left[6x\left(1-x\right)x,\left\{x,0,1\right\}\right]$

$\frac{1}{2}$

${\int }_{0}^{1}6x\left(1-x\right)xdx$

$\frac{1}{2}$

$\mathrm{data}\text{}=\text{}\mathrm{SemanticImport}\left["/Users/codingquark/Documents/Wolfram Mathematica/doing_bayesian_data_analysis/DBDA2Eprograms/HairEyeColor.csv"\right]$ $\mathrm{Mean}\left[\mathrm{data}\right]$

$\mathrm{Hair}\to \frac{1}{16}\left(4\mathrm{Black}+4\mathrm{Blond}+4\mathrm{Brown}+4\mathrm{Red}\right),\mathrm{Eye}\to \frac{1}{16}\left(4\mathrm{Blue}+4\mathrm{Brown}+4\mathrm{Green}+4\mathrm{Hazel}\right),\mathrm{Count}\to 37$

$\mathrm{Length}\left[\mathrm{data}\right]$

$16$

$\mathrm{Normal}\left[\mathrm{data}\right]$

$\left\{\mathrm{Hair}\to \mathrm{Black},\mathrm{Eye}\to \mathrm{Blue},\mathrm{Count}\to 20,\mathrm{Hair}\to \mathrm{Black},\mathrm{Eye}\to \mathrm{Brown},\mathrm{Count}\to 68,\mathrm{Hair}\to \mathrm{Black},\mathrm{Eye}\to \mathrm{Green},\mathrm{Count}\to 5,\mathrm{Hair}\to \mathrm{Black},\mathrm{Eye}\to \mathrm{Hazel},\mathrm{Count}\to 15,\mathrm{Hair}\to \mathrm{Blond},\mathrm{Eye}\to \mathrm{Blue},\mathrm{Count}\to 94,\mathrm{Hair}\to \mathrm{Blond},\mathrm{Eye}\to \mathrm{Brown},\mathrm{Count}\to 7,\mathrm{Hair}\to \mathrm{Blond},\mathrm{Eye}\to \mathrm{Green},\mathrm{Count}\to 16,\mathrm{Hair}\to \mathrm{Blond},\mathrm{Eye}\to \mathrm{Hazel},\mathrm{Count}\to 10,\mathrm{Hair}\to \mathrm{Brown},\mathrm{Eye}\to \mathrm{Blue},\mathrm{Count}\to 84,\mathrm{Hair}\to \mathrm{Brown},\mathrm{Eye}\to \mathrm{Brown},\mathrm{Count}\to 119,\mathrm{Hair}\to \mathrm{Brown},\mathrm{Eye}\to \mathrm{Green},\mathrm{Count}\to 29,\mathrm{Hair}\to \mathrm{Brown},\mathrm{Eye}\to \mathrm{Hazel},\mathrm{Count}\to 54,\mathrm{Hair}\to \mathrm{Red},\mathrm{Eye}\to \mathrm{Blue},\mathrm{Count}\to 17,\mathrm{Hair}\to \mathrm{Red},\mathrm{Eye}\to \mathrm{Brown},\mathrm{Count}\to 26,\mathrm{Hair}\to \mathrm{Red},\mathrm{Eye}\to \mathrm{Green},\mathrm{Count}\to 14,\mathrm{Hair}\to \mathrm{Red},\mathrm{Eye}\to \mathrm{Hazel},\mathrm{Count}\to 14\right\}$

$\mathrm{data}\left[\mathrm{Histogram},"Count"\right]$ $\mathrm{data}\left[\mathrm{GroupBy}\left["Hair"\right],\mathrm{Total},\text{}"Count"\right]$ $\mathrm{data}\left[\mathrm{GroupBy}\left["Eye"\right],\mathrm{Total},"Count"\right]$ $\mathrm{data}\left[\mathrm{All},"Count"\right]\text{}//\text{}\mathrm{Total}$

$592$   $\mathrm{data}\left[\mathrm{GroupBy}\left["Hair"\right],\mathrm{Mean},"Count"\right]$ $\mathrm{data}\left[\mathrm{GroupBy}\left["Eye"\right],\mathrm{Mean},"Count"\right]$ $\mathrm{data}$ $\mathrm{titanic}=\text{}\mathrm{ExampleData}\left[\left\{"Dataset","Titanic"\right\}\right]$ $\mathrm{titanic}\left[\mathrm{Histogram},"age"\right]$ $\mathrm{titanic}\left[\mathrm{GroupBy}\left[\mathrm{Key}\left["sex"\right]\right],\mathrm{Counts},"class"\right]$ $\mathrm{data}\left[\mathrm{Histogram},"Count"\right]$ $\mathrm{data}\left[\mathrm{ListPlot},"Count"\right]$ $\mathrm{data}\left[\mathrm{GroupBy}\left["Hair"\right],\mathrm{GroupBy}\left["Eye"\right]\right]$  $592$

$592$

$\mathrm{data}\left[\mathrm{Mean},"Count"\right]$

$37$

$\mathrm{data}\left[\mathrm{Median},"Count"\right]$

$\frac{37}{2}$

$\mathrm{data}\left[\mathrm{Counts},"Hair"\right]$ $\mathrm{data}\left[\mathrm{Counts},"Eye"\right]$ $\mathrm{data}\left[\mathrm{MinMax},"Count"\right]$ $\mathrm{data}\left[\mathrm{StandardDeviation},"Count"\right]$

$\sqrt{\frac{6314}{5}}$   $\mathrm{PieChart}\left[\mathrm{data}\left[\mathrm{GroupBy}\left["Eye"\right],\mathrm{Total},"Count"\right],\mathrm{ChartLegends}->\mathrm{Automatic}\right]$ $\mathrm{PieChart}\left[\mathrm{data}\left[\mathrm{GroupBy}\left["Hair"\right],\mathrm{Total},"Count"\right],\mathrm{ChartLegends}->\mathrm{Automatic}\right]$ $\mathrm{data}\left[\mathrm{GroupBy}\left["Eye"\right]\right]\text{}//\mathrm{Normal}$

$\mathrm{Blue}\to \left\{\mathrm{Hair}\to \mathrm{Black},\mathrm{Eye}\to \mathrm{Blue},\mathrm{Count}\to 20,\mathrm{Hair}\to \mathrm{Blond},\mathrm{Eye}\to \mathrm{Blue},\mathrm{Count}\to 94,\mathrm{Hair}\to \mathrm{Brown},\mathrm{Eye}\to \mathrm{Blue},\mathrm{Count}\to 84,\mathrm{Hair}\to \mathrm{Red},\mathrm{Eye}\to \mathrm{Blue},\mathrm{Count}\to 17\right\},\mathrm{Brown}\to \left\{\mathrm{Hair}\to \mathrm{Black},\mathrm{Eye}\to \mathrm{Brown},\mathrm{Count}\to 68,\mathrm{Hair}\to \mathrm{Blond},\mathrm{Eye}\to \mathrm{Brown},\mathrm{Count}\to 7,\mathrm{Hair}\to \mathrm{Brown},\mathrm{Eye}\to \mathrm{Brown},\mathrm{Count}\to 119,\mathrm{Hair}\to \mathrm{Red},\mathrm{Eye}\to \mathrm{Brown},\mathrm{Count}\to 26\right\},\mathrm{Green}\to \left\{\mathrm{Hair}\to \mathrm{Black},\mathrm{Eye}\to \mathrm{Green},\mathrm{Count}\to 5,\mathrm{Hair}\to \mathrm{Blond},\mathrm{Eye}\to \mathrm{Green},\mathrm{Count}\to 16,\mathrm{Hair}\to \mathrm{Brown},\mathrm{Eye}\to \mathrm{Green},\mathrm{Count}\to 29,\mathrm{Hair}\to \mathrm{Red},\mathrm{Eye}\to \mathrm{Green},\mathrm{Count}\to 14\right\},\mathrm{Hazel}\to \left\{\mathrm{Hair}\to \mathrm{Black},\mathrm{Eye}\to \mathrm{Hazel},\mathrm{Count}\to 15,\mathrm{Hair}\to \mathrm{Blond},\mathrm{Eye}\to \mathrm{Hazel},\mathrm{Count}\to 10,\mathrm{Hair}\to \mathrm{Brown},\mathrm{Eye}\to \mathrm{Hazel},\mathrm{Count}\to 54,\mathrm{Hair}\to \mathrm{Red},\mathrm{Eye}\to \mathrm{Hazel},\mathrm{Count}\to 14\right\}$

Given the structure so far, we need to figure out a way to have named rows, nested with further named rows. Like so: {“Brown Eye”->{“Black Hair”->4, “Blond Hair”->10}, “Blue Eye”->...}
Not sure if this should be done at import time, or as the next step after import.

Importing Data

How should it look like?

We want our Hair + Eye colour data to be structured “nicely” before we start doing analysis. What is this “nice” structure?

If imported simply, this is what it looks like:  This structure is not bad, it correctly figures out that the first row of the CSV is column names. But is this how we want things to be? Could we have more structure to it?

One approach can be to add some named rows. For example, we can imagine that the actual data point in the entire dataset is the `Count` column, rest are just names! Which means, we can have rows of rows.

Let’s try. What does the structure look like?

$\mathrm{planets}\text{}=\text{}\mathrm{ExampleData}\left[\left\{"Dataset","Planets"\right\}\right]$ $\mathrm{planets}//\mathrm{Normal}$

$\mathrm{Mercury}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Moons}\to ,\mathrm{Venus}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Moons}\to ,\mathrm{Earth}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Moons}\to \mathrm{Moon}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Mars}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Moons}\to \mathrm{Phobos}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Deimos}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Jupiter}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Moons}\to \mathrm{Metis}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Adrastea}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Amalthea}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Thebe}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Io}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Europa}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Ganymede}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Callisto}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Themisto}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Leda}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Himalia}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Lysithea}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Elara}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\text{S/2000 J11}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\text{S/2003 J12}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Carpo}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Euporie}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\text{S/2003 J3}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\text{S/2003 J18}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Orthosie}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Euanthe}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Harpalyke}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Praxidike}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Thyone}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\text{S/2003 J16}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Iocaste}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Mneme}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Hermippe}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Thelxinoe}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Helike}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Ananke}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\text{S/2003 J15}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Eurydome}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Arche}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Herse}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Pasithee}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\text{S/2003 J10}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Chaldene}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Isonoe}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Erinome}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Kale}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Aitne}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Taygete}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\text{S/2003 J9}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Carme}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Sponde}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Megaclite}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\text{S/2003 J5}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\text{S/2003 J19}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\text{S/2003 J23}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Kalyke}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Kore}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Pasiphae}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Eukelade}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\text{S/2003 J4}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Sinope}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Hegemone}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Aoede}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Kallichore}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Autonoe}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Callirrhoe}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Cyllene}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\text{S/2003 J2}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Saturn}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Moons}\to \mathrm{Tarqeq}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Pan}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Daphnis}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Atlas}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Prometheus}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Pandora}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Epimetheus}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Janus}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Aegaeon}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Mimas}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Methone}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Anthe}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Pallene}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Enceladus}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Tethys}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Calypso}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Telesto}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Polydeuces}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Dione}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Helene}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Rhea}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Titan}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Hyperion}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Iapetus}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Kiviuq}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Ijiraq}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Phoebe}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Paaliaq}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Skathi}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Albiorix}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\text{S/2007 S2}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Bebhionn}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Erriapo}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Siarnaq}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Skoll}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Tarvos}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Greip}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\text{S/2004 S13}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Hyrrokkin}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Mundilfari}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\text{S/2006 S1}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Jarnsaxa}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Narvi}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Bergelmir}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\text{S/2004 S17}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Suttungr}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Hati}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\text{S/2004 S12}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Bestla}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Farbauti}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Thrymr}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\text{S/2007 S3}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Aegir}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\text{S/2004 S7}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\text{S/2006 S3}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Kari}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Fenrir}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Surtur}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Ymir}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Loge}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Fornjot}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Uranus}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Moons}\to \mathrm{Cordelia}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Ophelia}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Bianca}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Cressida}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Desdemona}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Juliet}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Portia}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Rosalind}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Cupid}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Belinda}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Perdita}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Puck}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Mab}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Miranda}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Ariel}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Umbriel}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Titania}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Oberon}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Francisco}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Caliban}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Stephano}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Trinculo}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Sycorax}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Margaret}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Prospero}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Setebos}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Ferdinand}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Neptune}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Moons}\to \mathrm{Naiad}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Thalassa}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Despina}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Galatea}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Larissa}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Proteus}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Triton}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Nereid}\to \mathrm{Mass}\to ,\mathrm{Radius}\to ,\mathrm{Halimede}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Sao}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Laomedeia}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Psamathe}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to ,\mathrm{Neso}\to \mathrm{Mass}\to \mathrm{Missing}\left[\mathrm{NotAvailable}\right],\mathrm{Radius}\to $

Okay, now that we know how data is represented, we can try manually creating a row or two for our data.

$\mathrm{dataset}=\mathrm{Dataset}\left[\text{<|}"Black"->\text{<|}"Blue"->\text{<|}"Count"->20\text{|>},\text{<|}"Brown"->\text{<|}"Count"->68\text{|>}\text{|>}\text{|>}\text{|>}\right]$ Does this look good? We don’t have column names for Hair and Eye, but we do for Count. Is that normal? If you look at the Moons in the planet dataset, you can see that the names of of moons are not column-named, but their properties are column-named. Which is analogous to what we have for our dataset as well.

Let’s finalise on this structure for now, and find out how to convert the imported data.

Structuring Imported Dataset

So far, I have not found any simple way to morph the dataset. The important note found so far is that we cannot modify existing Dataset, but instead have to create new Dataset with the structure we want. What this means, is that we will have to define Column/Row structure and select proper Count columns for the new Dataset definition.

This manual approach is too much hassle. And figuring out “script-like” way to change the structure is not attractive right now.

Hence, we will try to roll with what we have and see what happens when we try doing operations on the data.

References

https://www.wolfram.com/wolfram-u/courses/data-science/becoming-a-data-curator-dat906/

Basic Analysis

Exercises from 4.6

Exercise 4.1

The eye-color hair-color data is frequencies of eye and hair color for males and females. Run the (some, we are going to ignore them) R code.

In your write-up, include each line above and its results. Explain what each line does (in a bit more detail than the inline comments). Extend above commands by also computing the probabilities of the hair colors given brown eyes, and the probabilities of the eye colors given Brown hair.

First, let’s import the data and show it.  Run equivalent of: Funnily enough, the R code given by the book loads the CSV, generates Male/Female split, and then store in the variable “HairEyeColor”. The “sum” application then gives the data we have got already!

Next line is dividing each cell by the total.  To find total counts of each hair-color:

$\mathrm{hairfrequencydataset}=\mathrm{dataset}\left[\mathrm{GroupBy}\left["Hair"\right],\mathrm{Total},"Count"\right]$ Like we added the Frequency column above for all rows, do the same but for the grouped data:

$\mathrm{hairproportions}=\mathrm{hairfrequencydataset}\left[\mathrm{All},\text{<|}"Frequency"->\mathrm{#1}/\mathrm{counttotal}\text{|>}&\right]$ Same operations now for eye colors:   Calculate conditional probability of Hair, given Blue eye color (table 4.2):

$\mathrm{haireyeproportion}\left[\mathrm{Select}\left[\mathrm{#Eye}=="Blue"&\right]\right]\left[\mathrm{All},\text{<|}"Hair"->\mathrm{#Hair},"Frequency"->N\left[\mathrm{#Frequency}/\mathrm{eyeproportions}\left["Blue","Frequency"\right]\right]\text{|>}&\right]$ Calculate conditional probability of hair colors given brown eyes:

$\mathrm{haireyeproportion}\left[\mathrm{Select}\left[\mathrm{#Eye}=="Brown"&\right]\right]\left[\mathrm{All},\text{<|}"Hair"->\mathrm{#Hair},"Frequency"->N\left[\mathrm{#Frequency}/\mathrm{eyeproportions}\left["Brown","Frequency"\right]\right]\text{|>}&\right]$ Calculate conditional probability of eye colors given brown hair:

$\mathrm{haireyeproportion}\left[\mathrm{Select}\left[\mathrm{#Hair}=="Brown"&\right]\right]\left[\mathrm{All},\text{<|}"Eye"->\mathrm{#Eye},"Frequency"->N\left[\mathrm{#Frequency}/\mathrm{hairproportions}\left["Brown","Frequency"\right]\right]\text{|>}&\right]$ Let’s now try to understand, verbally, what the exercise was about.

We were given raw counts for hair+eye colour combos. Just like one of the section in the chapter, we wanted to get to finding out conditional probabilities.

To get to conditional probabilities, we needed some basic information derived first:

Proportions of each hair+eye colour combo

Proportions of each hair colour

Proportions of each eye colour

When we calculate hair+eye proportions, we are calculating joint probabilities. For example, the probability of finding someone with both Brown eyes and Black hair is 0.11 i.e. 11% and so on.

When we calculate the proportions of only hair or only eye colours, we are measuring probability of finding, for example, a person with black hair; a person with blue eyes and so on. For example, the probability of finding a person with Black hair is 0.18 / 18%; a person with Brown eyes is 0.37 / 37%

Finally, we can use the derived information to calculate conditional probabilities. To calculate the probability of a person having Hazel eyes, given we know that the person has Blond hair we need to divide independent probability by marginal probability. So, for the specific case, the calculation is: 0.0168919/0.214527 = 0.078 (~7%)

Thus ends a successful Exercise 4.1! Notice how the entire exercise was about calculating proportions in various ways and it did not feel the way it did when reading the section of the book.

Exercise 4.2

Modify the coin flipping program in Section 4.5 to simulate a biased coin that has p(H)=0.8. Change the height of the reference line in the plot to match p(H). Comment your code.

Okay, this is more involved since it is mainly about R code. We will have to first write code to simulate coin flips, then make the coin flips biased.

Alright, let’s think about this. The R code uses `sample` function that takes probability values with with to take the samples. We need something similar in Mathematica. But what is our real goal? We want to flip a coin - [H,T]. And when it is flipped we want to specify how biased the coin is. Having flipped the coin N times, we want to plot the running proportion of H and know the end proportion.

First, we have RandomVariate function that can take some distribution. The one we might find useful is DiscreteUniformDistribution. Let’s try.

$\mathrm{RandomVariate}\left[\mathrm{DiscreteUniformDistribution}\left[\left\{0,1\right\}\right],10\right]\text{}//\text{}\mathrm{Short}$

$\left\{1,0,0,0,1,1,0,0,1,1\right\}$

$\mathrm{Histogram}\left[\mathrm{RandomVariate}\left[\mathrm{DiscreteUniformDistribution}\left[\left\{0,1\right\}\right],500\right]\right]$ $\mathrm{tosses}=\mathrm{RandomVariate}\left[\mathrm{DiscreteUniformDistribution}\left[\left\{0,1\right\}\right],500\right];$

$N\left[\frac{\mathrm{Count}\left[\mathrm{tosses},1\right]}{500}\right]$

$0.456$

$N\left[\frac{\mathrm{Count}\left[\mathrm{tosses},0\right]}{500}\right]$

$0.544$

There, we got the end proportions of the fair die after 500 tosses.

$\mathrm{manytosses}=\mathrm{RandomVariate}\left[\mathrm{DiscreteUniformDistribution}\left[\left\{0,1\right\}\right],50000\right];$

$\mathrm{ListPlot}\left[\mathrm{Accumulate}\left[\frac{\mathrm{manytosses}}{\mathrm{Length}\left[\mathrm{manytosses}\right]}\right]\right]$ $\mathrm{ListLinePlot}\left[\mathrm{Accumulate}\left[\mathrm{Select}\left[\mathrm{tosses},#==1&\right]\right]\right]$ Still no idea how to get “running proportion”! FoldList works, but does not give access to current index of the list. MapIndex does not keep track of previous elements. Looks like we will have to write our own function. Not fun, I must say.

Stolen the following code from https://mathematica.stackexchange.com/questions/190503/how-to-make-foldlistindexed-ie-foldlist-with-an-index-or-iterator $\left\{x,f\left[x,a,1\right],f\left[f\left[x,a,1\right],b,2\right],f\left[f\left[f\left[x,a,1\right],b,2\right],c,3\right],f\left[f\left[f\left[f\left[x,a,1\right],b,2\right],c,3\right],d,4\right]\right\}$

$\mathrm{fewtosses}=\left\{1,1,0,1,1,0,1,0,0,0\right\}$

$\left\{1,1,0,1,1,0,1,0,0,0\right\}$

This approach may not be the thing we want. What we want is a list: $\left\{\frac{1}{1},\frac{2}{2},\frac{2}{3},\frac{3}{4},\frac{4}{5},\frac{4}{6},\frac{5}{7},\frac{5}{8},\frac{5}{9},\frac{5}{10}\right\}$ and so on.

$\mathrm{For}\left[i=1;\mathrm{res}=\left\{\right\},i<=\mathrm{Length}\left[\mathrm{tosses}\right],i++,\mathrm{AppendTo}\left[\mathrm{res},\mathrm{Last}@\frac{\mathrm{FoldList}\left[\mathrm{Plus},0,\mathrm{tosses}\left[\left[\text{;;}i\right]\right]\right]}{i}\right]\right]$

$\mathrm{ListLinePlot}\left[\mathrm{res}\right]$ Well what do we have here! It worked! It is the ugliest way to do things because it is not functional, but it got the job done. We will refine this somehow.

$\mathrm{MapIndexed}\left[\frac{\mathrm{FoldList}\left[\mathrm{Plus},0,\mathrm{fewtosses}\left[\left[\text{;;}\mathrm{First}\left[\mathrm{#2}\right]\right]\right]\right]}{\mathrm{First}\left[\mathrm{#2}\right]}&,\mathrm{fewtosses}\right]$

$\left\{\left\{0,1\right\},\left\{0,\frac{1}{2},1\right\},\left\{0,\frac{1}{3},\frac{2}{3},\frac{2}{3}\right\},\left\{0,\frac{1}{4},\frac{1}{2},\frac{1}{2},\frac{3}{4}\right\},\left\{0,\frac{1}{5},\frac{2}{5},\frac{2}{5},\frac{3}{5},\frac{4}{5}\right\},\left\{0,\frac{1}{6},\frac{1}{3},\frac{1}{3},\frac{1}{2},\frac{2}{3},\frac{2}{3}\right\},\left\{0,\frac{1}{7},\frac{2}{7},\frac{2}{7},\frac{3}{7},\frac{4}{7},\frac{4}{7},\frac{5}{7}\right\},\left\{0,\frac{1}{8},\frac{1}{4},\frac{1}{4},\frac{3}{8},\frac{1}{2},\frac{1}{2},\frac{5}{8},\frac{5}{8}\right\},\left\{0,\frac{1}{9},\frac{2}{9},\frac{2}{9},\frac{1}{3},\frac{4}{9},\frac{4}{9},\frac{5}{9},\frac{5}{9},\frac{5}{9}\right\},\left\{0,\frac{1}{10},\frac{1}{5},\frac{1}{5},\frac{3}{10},\frac{2}{5},\frac{2}{5},\frac{1}{2},\frac{1}{2},\frac{1}{2},\frac{1}{2}\right\}\right\}$

$\mathrm{MapIndexed}\left[\mathrm{List}\left[\mathrm{#1},\mathrm{First}@\mathrm{#2}\right]&,\mathrm{fewtosses}\right]$

$\left\{\left\{1,1\right\},\left\{1,2\right\},\left\{0,3\right\},\left\{1,4\right\},\left\{1,5\right\},\left\{0,6\right\},\left\{1,7\right\},\left\{0,8\right\},\left\{0,9\right\},\left\{0,10\right\}\right\}$

$\mathrm{MapIndexed}\left[\frac{\mathrm{Total}\left[\mathrm{tosses}\left[\left[\text{;;}\mathrm{First}@\mathrm{#2}\right]\right]\right]}{\mathrm{First}@\mathrm{#2}}&,\mathrm{tosses}\right];$

$\mathrm{ListLinePlot}\left[%\right]$ There we go, it is now functional - nice and neat.

Now we need to bias the coin such that the probability of Heads is 0.8.

There’s BernoulliDistribution which “represents a Bernoulli distribution with probability parameter p. Also known as the coin toss distribution or Bernoulli trial”. Since it literally says “coin toss” in there, we should try it out.

$\mathrm{RandomVariate}\left[\mathrm{BernoulliDistribution}\left[0.8\right],10\right]$

$\left\{1,0,1,1,1,1,1,1,1,1\right\}$ $0.746$

$0.254$

Yes! Looks good! Let’s plot!

$\mathrm{ListLinePlot}\left[\mathrm{MapIndexed}\left[\frac{\mathrm{Total}\left[\mathrm{biasedtosses}\left[\left[\text{;;}\mathrm{First}@\mathrm{#2}\right]\right]\right]}{\mathrm{First}@\mathrm{#2}}&,\mathrm{biasedtosses}\right],\mathrm{PlotRange}->\mathrm{All}\right]$ And thus concludes the exercise!

Exercise 4.4

Consider a spinner with a [0,1] scale on its circumference. Suppose that the spinner is slanted or magnetized or bent in some way such that it is biased, and its probability density function is p(x) = 6x(1-x) over the interval x ∈ [0,1].

Adapt the program IntegralOfDensity.R to plot this density function and approximate its integral. Comment your code. Be careful to consider values of x only in the interval [0,1]. Hint: You can omit the first couple of lines regarding meanval and sdval, because those parameter values pertain only to the normal distribution. Then set xlow=0 and xhigh=1, and set dx to some small value.

Derive the exact integral using calculus.

Does this function satisfy equation 4.3?

From inspecting the graph, what is the maximal values of p(x)?

Here is the R code from the file:

source("DBDA2E-utilities.R")
# Graph of normal probability density function, with comb of intervals.
meanval = 0.0               # Specify mean of distribution.
sdval = 0.2                 # Specify standard deviation of distribution.
xlow  = meanval - 3.5*sdval # Specify low end of x-axis.
xhigh = meanval + 3.5*sdval # Specify high end of x-axis.
dx = sdval/10               # Specify interval width on x-axis
# Specify comb of points along the x axis:
x = seq( from = xlow , to = xhigh , by = dx )
# Compute y values, i.e., probability density at each value of x:
y = ( 1/(sdval*sqrt(2*pi)) ) * exp( -.5 * ((x-meanval)/sdval)^2 )
# Plot the function. "plot" draws the intervals. "lines" draws the bell curve.
openGraph(width=7,height=5)
plot( x , y , type="h" , lwd=1 , cex.axis=1.5, xlab="x" , ylab="p(x)", cex.lab=1.5, main="Normal Probability Density" , cex.main=1.5 )
lines( x , y , lwd=3 ,  col="skyblue" )
# Approximate the integral as the sum of width * height for each interval.
area = sum( dx * y )
# Display info in the graph.
text( meanval-sdval , .9*max(y) , bquote( paste(mu ," = " ,.(meanval)) ), adj=c(1,.5) , cex=1.5 )
text( meanval-sdval , .75*max(y) , bquote( paste(sigma ," = " ,.(sdval)) ), adj=c(1,.5) , cex=1.5 )
text( meanval+sdval , .9*max(y) , bquote( paste(Delta , "x = " ,.(dx)) ), adj=c(0,.5) , cex=1.5 )
text( meanval+sdval , .75*max(y) ,bquote( sum({},x,{}) *" "* Delta *"x p(x) = "* .(signif(area,3)) ) ,adj=c(0,.5) , cex=1.5 )
# Save the plot to an EPS file.
saveGraph( file = "IntegralOfDensity" , type="eps" )

That’s a lot of code just to display graphs. Disregard those lines, and we are left with a few important lines:

# Specify comb of points along the x axis:
x = seq( from = xlow , to = xhigh , by = dx )

# Compute y values, i.e., probability density at each value of x:
y = ( 1/(sdval*sqrt(2*pi)) ) * exp( -.5 * ((x-meanval)/sdval)^2 )

# Approximate the integral as the sum of width * height for each interval.
area = sum( dx * y )

Fairly straight forward. Initially I thought we are going to use NormalDistribution function, but no. This is just calculating values of “probability density” in a range (0 to 1) with some interval and plots the values. Can we find some excuse to use NormalDistribution?

Anyway, here we go:  $\mathrm{area}=\mathrm{Total}\left[\mathcal{y}*\delta \right]$

$0.9996$

I am curious how the plot looked liked with the original equation.  $\text{}{\int }_{0}^{1}6x\left(1-x\right)dx$

$1$

In:=

integrate 6x(1-x) from 0 to 1

$\mathrm{Max}\left[\mathcal{y}\right]$

$1.5$

Thus concludes the exercise.

However, there’s something more we can try. That is to see if we can find more Mathematica-like ways of doing this.
Thinking about it, we are given a probability distribution function 6x(1-x). And all we want is to see how it will behave for different values of the variable x. There is one potential function we can try.  Ah! Look what we got here! Perfect.

$\mathrm{Max}\left[\mathrm{PDF}\left[\mathcal{D},x\right]\right]$

 6 (1-x) x 0  To get area under the curve we do CDF[a] - CDF[b] $1$ $0.999534741841929$

As you can observe, this approach is much better. Though it may not be as easy to understand what’s really going on under the hood, it is cleaner once you already have understood what’s going on. For example, if we were to start directly with ProbabilityDistribution, we would not know how 6x(1-x) is executed and plotted.