Skip to content

Commit

Permalink
fixes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
schochastics committed Dec 15, 2023
1 parent ce02a1a commit caed190
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions vignettes/indirect_relations.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,39 +61,46 @@ the `type` parameter.
data("dbces11")
g <- dbces11
#adjacency
A <- indirect_relations(g,type = "identity")
#shortest path distances
D <- indirect_relations(g,type="dist_sp")
#dyadic dependencies (as used in betweenness centrality)
B <- indirect_relations(g,type = "depend_sp")
#resistance distance (as used in information centrality)
R <- indirect_relations(g,type="dist_resist")
#Logarithmic forest distance (parametrized family of distances)
LF <- indirect_relations(g, type = "dist_lf",lfparam = 1)
#Walk distance (parametrized family of distances)
WD <- indirect_relations(g, type = "dist_walk",dwparam = 0.001)
#Random walk distance
WD <- indirect_relations(g, type = "dist_rwalk")
#See ?indirect_relations for further options
# adjacency
A <- indirect_relations(g, type = "adjacency")
# shortest path distances
D <- indirect_relations(g, type = "dist_sp")
# dyadic dependencies (as used in betweenness centrality)
B <- indirect_relations(g, type = "depend_sp")
# resistance distance (as used in information centrality)
R <- indirect_relations(g, type = "dist_resist")
# Logarithmic forest distance (parametrized family of distances)
LF <- indirect_relations(g, type = "dist_lf", lfparam = 1)
# Walk distance (parametrized family of distances)
WD <- indirect_relations(g, type = "dist_walk", dwparam = 0.001)
# Random walk distance
WD <- indirect_relations(g, type = "dist_rwalk")
# See ?indirect_relations for further options
```

Indirect relations are represented as matrices, similar to the adjacency matrix. The below matrices show
the distance matrix based on sahortest paths, and the pairwise dependencies (used for e.g. betweenness).
```{r example_mat}
D
B
```

The function takes an additional parameter `FUN` which can be used to pass a function
to further transform relations. The main use is to obtain indirect relations based on walk counts.

```{r indirwalks}
#count the limit proportion of walks (used for eigenvector centrality)
W <- indirect_relations(g,type = "walks",FUN = walks_limit_prop)
#count the number of walks of arbitrary length between nodes, weighted by
#the inverse factorial of their length (used for subgraph centrality)
S <- indirect_relations(g,type = "walks",FUN = walks_exp)
# count the limit proportion of walks (used for eigenvector centrality)
W <- indirect_relations(g, type = "walks", FUN = walks_limit_prop)
# count the number of walks of arbitrary length between nodes, weighted by
# the inverse factorial of their length (used for subgraph centrality)
S <- indirect_relations(g, type = "walks", FUN = walks_exp)
```

Additional parameters can also be passed to calculate parameterized versions of
relations.
```{r indirparam}
#Calculate dist(s,t)^-alpha
D <- indirect_relations(g,type="dist_sp",FUN=dist_dpow,alpha = 2)
# Calculate dist(s,t)^-alpha
D <- indirect_relations(g, type = "dist_sp", FUN = dist_dpow, alpha = 2)
```

To view all predefined transformation functions see `?transform_relations`. The
Expand All @@ -104,10 +111,10 @@ The predefined functions are not exhaustive and just constitute the most common
transformations. It is, however, straightforward to pass your own transformation function.

```{r own_func}
dist_integration <- function(x){
x <- 1 - (x - 1)/max(x)
dist_integration <- function(x) {
x <- 1 - (x - 1) / max(x)
}
D <- indirect_relations(g,type="dist_sp",FUN=dist_integration)
D <- indirect_relations(g, type = "dist_sp", FUN = dist_integration)
```

The function `dist_integration()` computes
Expand Down

0 comments on commit caed190

Please sign in to comment.