Skip to content

Instantly share code, notes, and snippets.

@albertmeronyo
Created April 29, 2015 14:32
Show Gist options
  • Save albertmeronyo/3cb0dac842255ad966af to your computer and use it in GitHub Desktop.
Save albertmeronyo/3cb0dac842255ad966af to your computer and use it in GitHub Desktop.
Standard deviation in (pure) SPARQL
SELECT ((SUM((?n - ?mean)*(?n - ?mean)))/(COUNT(?n) - 1) AS ?sdev) WHERE {
?obs qb:value ?n .
{
SELECT (AVG(?n) AS ?mean) WHERE {
?obs qb:value ?n .
}
}
@bas-stringer
Copy link

This actually calculates variance, (including Bessel's correction). To go from this to a standard deviation requires a square root operation, which isn't available in pure SPARQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment