Skip to contents

This function calculates the semantic similarities based on Resnik or Lin similarity for a given ontology. Has also the option to calculate a combined version of the two. Returns the full matrix of the data.

Usage

calculate_semantic_sim_mat(similarity_type, ancestor_list, ic_list)

Arguments

similarity_type

String. One of c("resnik", "lin", "combined"). The Resnik similarity is automatically rescaled between 0 and 1 (dividing the values by maximum information content observed).

ancestor_list

List. Names being the term and the elements in the list the names of the ancestors, see get_ontology_ancestry().

ic_list

List. The names being the term and the elements the information content of this given term. Needs to be a single float! See calculate_information_content().

Value

The symmetric similarity matrix for the specified data from the ontology.

Examples

# Resnik similarity matrix over a toy ontology
onto <- data.table::data.table(
  parent = c("a", "b", "b", "b", "c"),
  child = c("b", "c", "d", "e", "f")
)
ancestry <- get_ontology_ancestry(onto)
ic <- calculate_information_content(ancestry$descendants)
round(calculate_semantic_sim_mat("resnik", ancestry$ancestors, ic), 3)
#>   a     b     c     d     e     f
#> a 1 0.000 0.000 0.000 0.000 0.000
#> b 0 1.000 0.102 0.102 0.102 0.102
#> c 0 0.102 1.000 0.102 0.102 0.613
#> d 0 0.102 0.102 1.000 0.102 0.102
#> e 0 0.102 0.102 0.102 1.000 0.102
#> f 0 0.102 0.613 0.102 0.102 1.000