Wolfram Language

Quantities in Probability & Statistics

Tunnels

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

In[1]:=
Click for copyable input
tunnels = TunnelData[];
In[2]:=
Click for copyable input
Length[tunnels]
Out[2]=

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

In[3]:=
Click for copyable input
rawData = TunnelData[tunnels, {"Countries", "Length"}];

Clean the data to remove missing values.

In[4]:=
Click for copyable input
data = DeleteMissing[rawData, 1, 2];

Convert the length data to miles.

In[5]:=
Click for copyable input
data[[All, 2]] = UnitConvert[N[data[[All, 2]]], "Miles"];
In[6]:=
Click for copyable input
lengths = data[[All, 2]];
In[7]:=
Click for copyable input
MinMax[lengths]
Out[7]=
In[8]:=
Click for copyable input
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]:=
Click for copyable input
dist = MixtureDistribution[{w1, w2}, {ParetoDistribution[a1, a2, a3, a4], WeibullDistribution[b1, b2]}];
In[10]:=
Click for copyable input
edist = EstimatedDistribution[lengths, dist]
Out[10]=

Test goodness of fit against the parametric family mixture distributions.

In[11]:=
Click for copyable input
DistributionFitTest[lengths, dist, "TestDataTable"]
Out[11]=

Plot the PDF of the fitted distribution against the histogram.

In[12]:=
Click for copyable input
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]:=
Click for copyable input
res = GroupBy[data, First, Flatten[Take[#, All, -1]] &];

Some tunnels are located in more than one country.

In[14]:=
Click for copyable input
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]:=
Click for copyable input
split = GroupBy[ Flatten[Map[{{{#[[1]]}, res[#]}, {{#[[2]]}, res[#]}} &, shared], 1], First, Flatten[#[[All, 2]]] &];
In[16]:=
Click for copyable input
together = Join[KeyDrop[res, shared], split, 2];
In[17]:=
Click for copyable input
tc = SortBy[Select[Normal[together], Length[#[[2]]] >= 10 &], Length@*Last];
In[18]:=
Click for copyable input
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]:=
Click for copyable input
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]=

Related Examples

de es fr ja ko pt-br ru zh