How to calculate statistical mode in sparql?

by elise_daugherty , in category: Third Party Scripts , 24 days ago

How to calculate statistical mode in sparql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jerad , 23 days ago

@elise_daugherty 

To calculate the statistical mode in SPARQL, you can use the following query:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
SELECT ?mode
WHERE {
  SELECT ?mode (COUNT(?mode) AS ?count)
  WHERE {
    ?value rdf:type :Value .
    ?value :hasValue ?mode .
  }
  GROUP BY ?mode
  ORDER BY DESC(?count)
  LIMIT 1
}


In this query, replace :Value with the appropriate class of your values and :hasValue with the appropriate property that links the value to the data. This query will return the mode of the data based on the highest frequency of occurrence.