The sparse Bradley-Terry fit of `comparisons` among `items` items. It has the model, the options and the checks of `bradleyTerry`, and its memory is in proportion to `items` plus the distinct pairs. The function does not sort or change its inputs. It throws a RangeError for a bad index, a bad outcome, a bad weight and a bad option.
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","bradleyTerrySparse"], { items: 1, comparisons: [] });
console.log(JSON.stringify(result));From the command line
$ mark statistics bradleyTerrySparse --items <number> --comparisons <object[]>
As data, in a program
{
"$proc": ["statistics", "bradleyTerrySparse"],
"input": { "items": 1, "comparisons": [] }
}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": {
"maxIterations": {
"type": "number",
"description": "The largest number of MM steps. The default is 10000."
},
"tolerance": {
"type": "number",
"description": "The largest distance of the parameters from the exact optimum at the stop. The default is 1e-8. The distance is the Euclidean norm over the log-strengths and the log of the tie parameter."
},
"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."
}
},
"additionalProperties": {}
}
},
"required": [
"items",
"comparisons"
],
"additionalProperties": false
},
"output": {
"type": "object",
"properties": {
"se": {
"type": "array",
"items": {
"type": "number"
},
"description": "The approximate standard error of each log-strength. For an item in a connected group of `n` items, the variance is `1 / (n * p) + (1 - 1 / n) / h`. Here `p` is the prior precision, and `h` is the diagonal entry of the Hessian. The first term is the variance of the mean of the group, which only the prior sets. An item with no comparison has the prior SD, as in `bradleyTerry`."
},
"iterations": {
"type": "number",
"description": "The number of MM steps."
},
"converged": {
"type": "boolean",
"description": "True when `bound` is the tolerance or less, or when the gradient is at the rounding level of floating point. At the rounding level, a step gains nothing, but a weak prior can keep `bound` above the tolerance."
},
"bound": {
"type": "number",
"description": "An upper bound of the distance of the parameters from the exact optimum: the norm of the gradient over the smallest prior precision. The objective is strongly convex, so this bound holds."
},
"pairs": {
"type": "number",
"description": "The number of distinct pairs of items with a comparison. The memory of the fit is in proportion to it."
},
"strengths": {
"type": "array",
"items": {
"type": "number"
},
"description": "The log-strength of each item. An item with no comparison has the prior mean."
},
"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."
}
},
"required": [
"se",
"iterations",
"converged",
"bound",
"pairs",
"strengths",
"tie",
"logLikelihood"
],
"additionalProperties": {}
}
}