# Wolfram Mathematica

## Tunnels

TunnelData provides information about tunnels, such as their length and the location.

In[1]:=
`tunnels = TunnelData[];`
In[2]:=
`Length[tunnels]`
Out[2]=

For each tunnel, find its length and location given by country or countries.

In[3]:=
`rawData = TunnelData[tunnels, {"Countries", "Length"}];`

Clean the data to remove missing values.

In[4]:=
`data = DeleteMissing[rawData, 1, 2];`

Convert the length data to miles.

In[5]:=
`data[[All, 2]] = UnitConvert[N[data[[All, 2]]], "Miles"];`
In[6]:=
`lengths = data[[All, 2]];`
In[7]:=
`MinMax[lengths]`
Out[7]=
In[8]:=
```h = Histogram[lengths, {1, 12, .5}, PDF, FrameLabel -> Automatic, PlotTheme -> "Detailed"]```
Out[8]=

The data might be described by a mixture of long-tailed distributions.

In[9]:=
```dist = MixtureDistribution[{w1, w2}, {ParetoDistribution[a1, a2, a3, a4], WeibullDistribution[b1, b2]}];```
In[10]:=
`edist = EstimatedDistribution[lengths, dist]`
Out[10]=

Test goodness of fit against the parametric family mixture distributions.

In[11]:=
`DistributionFitTest[lengths, dist, "TestDataTable"]`
Out[11]=

Plot the PDF of the fitted distribution against the histogram.

In[12]:=
```Show[h, Plot[PDF[edist, Quantity[x, "Miles"]], {x, 1, 12}, PlotRange -> All] // Quiet]```
Out[12]=

Visualize the locations of the tunnels.

Group by country.

In[13]:=
`res = GroupBy[data, First, Flatten[Take[#, All, -1]] &];`

Some tunnels are located in more than one country.

In[14]:=
`shared = Select[Keys[res], Length[#] > 1 &]`
Out[14]=

Distribute the shared tunnels and select countries that have at least 10 tunnels. Plot the length distribution chart.

show complete Wolfram Language input
In[15]:=
```split = GroupBy[ Flatten[Map[{{{#[[1]]}, res[#]}, {{#[[2]]}, res[#]}} &, shared], 1], First, Flatten[#[[All, 2]]] &];```
In[16]:=
`together = Join[KeyDrop[res, shared], split, 2];`
In[17]:=
```tc = SortBy[Select[Normal[together], Length[#[[2]]] >= 10 &], Length@*Last];```
In[18]:=
```DistributionChart[tc[[All, 2]], ChartLabels -> tc[[All, 1, 1]], BarOrigin -> Left, BarSpacing -> .3, FrameLabel -> {"Miles"}, LabelingFunction -> (Placed[Length[#1], After] &), ChartStyle -> "SandyTerrain", ImageSize -> Large]```
Out[18]=

The total tunnel mileage per country with shared tunnels included in full length for each country.

show complete Wolfram Language input
In[19]:=
```vals = KeyMap[First, Map[Total, together]]; title = Style["tunnel mileage", 24, Bold, GrayLevel[.2], FontFamily -> "Osaka"]; GeoRegionValuePlot[vals, GeoProjection -> "Mercator", GeoRange -> {{-65, 80}, {-170, 190}}, PlotLegends -> Automatic, ColorFunction -> (ColorData["StarryNightColors", 2 #] &), Epilog -> Inset[title, {30, -65}], ImageSize -> 500]```
Out[19]=