← All procedures

statistics.fitRatings

The log-strengths of `items` items with one rating model. The model `"bradley-terry"` uses `bradleyTerry`, or `bradleyTerrySparse` above `denseLimit` items. The models `"elo"` and `"glicko2"` use `eloReplay` and `glicko2Replay`, and they refuse a weight other than 1. A log of 0 items gives empty lists.

CLI
Package
@procedures/statistics · README
Path
["statistics","fitRatings"]
CLI
mark statistics fitRatings --model <"bradley-terry" | "elo" | "glicko2"> --items <number> --comparisons <object[]>
As data
{"$proc":["statistics","fitRatings"],"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","fitRatings"], { model: "bradley-terry", items: 1, comparisons: [] });
console.log(JSON.stringify(result));

From the command line

$ mark statistics fitRatings --model <"bradley-terry" | "elo" | "glicko2"> --items <number> --comparisons <object[]>

As data, in a program

{
  "$proc": ["statistics", "fitRatings"],
  "input": { "model": "bradley-terry", "items": 1, "comparisons": [] }
}

Input

FieldTypeRequiredDefaultDescription
model"bradley-terry" | "elo" | "glicko2"yes
itemsnumberyes
comparisonsobject[]yes
optionsobjectno

Output

FieldTypeRequiredDefaultDescription
strengthsnumber[]yesThe log-strength of each item. `strengthToRating` gives the rating.
senumber[]yesThe standard error of each log-strength. Elo has no standard error, so each value is `undefined`. For Glicko-2, it is the RD as a log-strength.
tienumberyesThe Davidson tie parameter of the Bradley-Terry fit, or 0 for the other models.
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "model": {
        "type": "string",
        "enum": [
          "bradley-terry",
          "elo",
          "glicko2"
        ]
      },
      "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": {
          "bradleyTerry": {
            "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": {},
            "description": "The options of the Bradley-Terry fit. They go to `bradleyTerry` and to `bradleyTerrySparse`."
          },
          "denseLimit": {
            "type": "number",
            "description": "The largest number of items for the dense fit `bradleyTerry`. A larger log uses `bradleyTerrySparse`. The default is 200."
          },
          "elo": {
            "type": "object",
            "properties": {
              "start": {
                "type": "number",
                "description": "The rating of each item before its first pick. The default is 1500."
              },
              "k": {
                "type": "number",
                "description": "The largest change of a rating after one result (the K factor). The default is 32."
              },
              "center": {
                "type": "number",
                "description": "The rating of the log-strength 0. The default is 1500. Elo uses only differences, so it does not read it."
              },
              "scale": {
                "type": "number",
                "description": "The number of points that gives odds of `base` to 1. The default is 400."
              },
              "base": {
                "type": "number",
                "description": "The base of the odds. The default is 10."
              }
            },
            "additionalProperties": {},
            "description": "The options of the Elo replay. Its scale also converts the ratings to log-strengths."
          },
          "glicko2": {
            "type": "object",
            "properties": {
              "start": {
                "type": "object",
                "properties": {
                  "rating": {
                    "type": "number"
                  },
                  "rd": {
                    "type": "number",
                    "description": "The rating deviation, in rating points. It is above 0."
                  },
                  "volatility": {
                    "type": "number",
                    "description": "The volatility: the expected size of a change of the true strength in one rating period. It is above 0."
                  }
                },
                "required": [
                  "rating",
                  "rd",
                  "volatility"
                ],
                "additionalProperties": {},
                "description": "The rating of each item before its first pick. The default is the rating 1500, the RD 350 and the volatility 0.06."
              },
              "tau": {
                "type": "number",
                "description": "The constraint on the change of the volatility over time (tau). The default is 0.5. Glickman uses 0.3 to 1.2."
              },
              "tolerance": {
                "type": "number",
                "description": "The tolerance of the iteration for the new volatility (epsilon). The default is 0.000001, as in the paper."
              }
            },
            "additionalProperties": {},
            "description": "The options of the Glicko-2 replay."
          }
        },
        "additionalProperties": {}
      }
    },
    "required": [
      "model",
      "items",
      "comparisons"
    ],
    "additionalProperties": false
  },
  "output": {
    "type": "object",
    "properties": {
      "strengths": {
        "type": "array",
        "items": {
          "type": "number"
        },
        "description": "The log-strength of each item. `strengthToRating` gives the rating."
      },
      "se": {
        "type": "array",
        "items": {
          "type": "number"
        },
        "description": "The standard error of each log-strength. Elo has no standard error, so each value is `undefined`. For Glicko-2, it is the RD as a log-strength."
      },
      "tie": {
        "type": "number",
        "description": "The Davidson tie parameter of the Bradley-Terry fit, or 0 for the other models."
      }
    },
    "required": [
      "strengths",
      "se",
      "tie"
    ],
    "additionalProperties": {}
  }
}