← All procedures

statistics.bradleyTerry

The Bradley-Terry fit of `comparisons` among `items` items. The function does not sort or change its inputs. An empty list of comparisons gives the prior for each item. The function throws a RangeError for a bad index, a bad outcome, a bad weight and a bad option.

CLI
Package
@procedures/statistics · README
Path
["statistics","bradleyTerry"]
CLI
mark statistics bradleyTerry --items <number> --comparisons <object[]>
As data
{"$proc":["statistics","bradleyTerry"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/statistics/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["statistics","bradleyTerry"], { items: 1, comparisons: [] });
console.log(JSON.stringify(result));

From the command line

$ mark statistics bradleyTerry --items <number> --comparisons <object[]>

As data, in a program

{
  "$proc": ["statistics", "bradleyTerry"],
  "input": { "items": 1, "comparisons": [] }
}

Input

FieldTypeRequiredDefaultDescription
itemsnumberyes
comparisonsobject[]yes
optionsobjectno

Output

FieldTypeRequiredDefaultDescription
strengthsnumber[]yesThe log-strength of each item. An item with no comparison has the prior mean.
senumber[]yesThe standard error of each log-strength: the square root of the diagonal of the inverse of the Hessian of the negative log posterior. An item with no comparison has the prior SD.
tienumberyesThe Davidson tie parameter. It is 0 with the model `"half"`, and when no comparison is a tie.
logLikelihoodnumberyesThe log-likelihood of the comparisons at the fit, with no prior term.
iterationsnumberyesThe number of Newton steps.
convergedbooleanyesTrue when the last full Newton step moved no parameter more than the tolerance.
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "items": {
        "type": "number"
      },
      "comparisons": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "a": {
              "type": "number"
            },
            "b": {
              "type": "number"
            },
            "outcome": {
              "type": "string",
              "enum": [
                "a",
                "b",
                "tie"
              ]
            },
            "weight": {
              "type": "number",
              "description": "The weight of the comparison. The default is 1. A weight of 2 counts as two equal comparisons."
            }
          },
          "required": [
            "a",
            "b",
            "outcome"
          ],
          "additionalProperties": {}
        }
      },
      "options": {
        "type": "object",
        "properties": {
          "priorMean": {
            "type": "number",
            "description": "The mean of the prior of each log-strength. The default is 0."
          },
          "priorSd": {
            "type": "number",
            "description": "The standard deviation of the prior of each log-strength. The default is 1. A smaller value pulls the strengths together."
          },
          "ties": {
            "type": "string",
            "enum": [
              "davidson",
              "half"
            ],
            "description": "The model of a tie. With `\"davidson\"` (the default), the fit also gives a tie parameter. With `\"half\"`, a tie counts as half a win and half a loss of each item, and the tie parameter is 0."
          },
          "tiePriorSd": {
            "type": "number",
            "description": "The standard deviation of the normal prior of the log of the tie parameter, with mean 0. The default is 10. The prior is weak. It keeps the parameter finite when each comparison is a tie."
          },
          "maxIterations": {
            "type": "number",
            "description": "The largest number of Newton steps. The default is 100."
          },
          "tolerance": {
            "type": "number",
            "description": "The fit stops when the full Newton step moves no parameter more than this value. The default is 1e-10."
          }
        },
        "additionalProperties": {}
      }
    },
    "required": [
      "items",
      "comparisons"
    ],
    "additionalProperties": false
  },
  "output": {
    "type": "object",
    "properties": {
      "strengths": {
        "type": "array",
        "items": {
          "type": "number"
        },
        "description": "The log-strength of each item. An item with no comparison has the prior mean."
      },
      "se": {
        "type": "array",
        "items": {
          "type": "number"
        },
        "description": "The standard error of each log-strength: the square root of the diagonal of the inverse of the Hessian of the negative log posterior. An item with no comparison has the prior SD."
      },
      "tie": {
        "type": "number",
        "description": "The Davidson tie parameter. It is 0 with the model `\"half\"`, and when no comparison is a tie."
      },
      "logLikelihood": {
        "type": "number",
        "description": "The log-likelihood of the comparisons at the fit, with no prior term."
      },
      "iterations": {
        "type": "number",
        "description": "The number of Newton steps."
      },
      "converged": {
        "type": "boolean",
        "description": "True when the last full Newton step moved no parameter more than the tolerance."
      }
    },
    "required": [
      "strengths",
      "se",
      "tie",
      "logLikelihood",
      "iterations",
      "converged"
    ],
    "additionalProperties": {}
  }
}