# Network Theory and Switching Behaviors: A User Guide for Analyzing Electronic Records Databases
## 4 A Working Example  
Let us suppose we have an electronic database that, after the application of the Python script in Appendix A, is transformed in the adjacency matrix represented in the graph of Figure 1.  
This is not an example based on real data, but it may be considered a plausible situation. The eight nodes may represent eight different types of pharmaceutical equivalent drugs (i.e., same active ingredients, same dosage form and method of administration, identical in concentration/strength), branded or not. A sample of patients in a given interval of time switched between these different drugs, as represented in the adjacency matrix of Figure 1.  
Figure 1: Example of a graph generated from an adjacency matrix with 8 different types of drugs.  
We are going to compare this setting (called Case Study) with a reference scenario with a fully connected network (Figure 2). It represents a situation where a sample of patients switches from a specific drug to any other drug (given the eight drugs under scrutiny). This may represent an actual situation. Fully connected networks are often used as a benchmark to compare the features of a given network [53; 54; 57].  
Network analyses have been performed with the statistical software R [58] (in particular using the packages _tidyverse_[59] and _igraph_[60]), which easily allows computing the degree, the in-degree, the out-degree, betweenness centrality and closeness for each node and for the two scenarios (Table 2). They are computed giving as input the graph and provide the outputs as defined in Section 2. Appendix B reports the R script employed to obtain the data presented here.  
Drug 2, Drug 3 and Drug 5 have the highest degree (thus, they are more the center of switching behaviors). However, Drugs 2 and 3 have the same in-degree (switching to that drug) equal to four (likewise other kinds of drug, for example, Drugs 1, 4 and 8) and higher than Drug 5 (in-degree equal to three). The high degree scores of these three drugs depend mainly on the out-degree (switching to another drug). It is easy to observe that in the fully connected network, there are no differences among nodes for degree, in-degree and out-degree where all the values have the highest possible amount.  
When drugs are switched in sequence, Drug 5 is the most \"central\" (with a betweenness centrality equal to 5.50), followed by Drugs 1 and 2. This means that these drugs are a sort of recurrent \"bridge\" between other drugs. In other terms, they have a crucial role in the flow of drug switching. The differences among nodes in closeness values are not so high, but results confirm that Drugs 2, 3 and 5 are nearer (in terms of switching) to other drugs. Again, in the fully connected network, the distribution of betweenness centrality  
\begin{table}
\begin{tabular}{c c c c c c c c c c c} \hline \hline  & & & \multicolumn{4}{c}{**Case Study**} & \multicolumn{4}{c}{**Fully Connected Network**} \\ \hline
**Drug** & **Degree** & \begin{tabular}{c} **In-** \\ **Degree** \\ \end{tabular} & \begin{tabular}{c} **Out-** \\ **Certality** \\ \end{tabular} & **Closeness** & **Degree** & \begin{tabular}{c} **In-** \\ **Degree** \\ \end{tabular} & \
\begin{tabular}{c} **Out-** \\ **Degree** \\ \end{tabular} &
\begin{tabular}{c} **Betweenness** \\ **Centrality** \\ \end{tabular} & **Closeness** \\
**1** & 8 & 4 & 4 & 4.00 & 0.10 & 16 & 8 & 8 & 0 & 0.14 \\
**2** & 10 & 4 & 6 & 4.00 & 0.11 & 16 & 8 & 8 & 0 & 0.14 \\
**3** & 9 & 4 & 5 & 1.50 & 0.11 & 16 & 8 & 8 & 0 & 0.14 \\
**4** & 7 & 4 & 3 & 1.50 & 0.09 & 16 & 8 & 8 & 0 & 0.14 \\
**5** & 9 & 3 & 6 & 5.50 & 0.11 & 16 & 8 & 8 and closeness are uniform: specifically, equal to zero for each node and equal to 0.14 for betweenness centrality and closeness, respectively.  
Lastly, the diameter of the Case Study network is three, whereas the diameter of the fully connected network is one, confirming that the former is \"larger\" (i.e., there are some drugs that do not switch directly to each other) than the fully connected network.