Jump to content

Help:RiskModel: Difference between revisions

From RiskiPedia
Created page with "= Help:RiskModel = The `<riskmodel>` tag defines a risk model on a wiki page, specifying a calculation and a unique name for use in other features, such as RiskDisplay. Variables in the calculation should match column names in a DataTable2 table. == Syntax == The `<riskmodel>` tag supports these attributes: * `name`: (Required) A unique name for the risk model on the page. * `calculation`: (Required) The mathematical expre..."
 
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Help:RiskModel =
= Help:RiskModel =


The `<riskmodel>` tag defines a risk model on a wiki page, specifying a calculation and a unique name for use in other features, such as [[Help:RiskDisplay|RiskDisplay]]. Variables in the calculation should match column names in a [[Extension:DataTable2|DataTable2]] table.
The &lt;riskmodel&gt; tag defines a risk model on a wiki page, specifying a calculation and a unique name for use in a [[Help:RiskDisplay|RiskDisplay]] (most likely on another page; best practice is to put the risk model on a /Data subpage along with the data about a risk). Variables in the calculation must match column names in a [[Help:DataTable2|DataTable2]] table. The text inside the tag describes the risk and should include the `{result}` placeholder.


== Syntax ==
== Syntax ==
The `<riskmodel>` tag supports these attributes:
The &lt;riskmodel&gt; tag supports these attributes:


* `name`: (Required) A unique name for the risk model on the page.
* `name`: (Required) A unique name for the risk model on the page.
Line 11: Line 11:
Basic syntax:
Basic syntax:
<pre><nowiki>
<pre><nowiki>
<riskmodel name="ModelName" calculation="base_probability * distraction_odds_ratio">Optional description</riskmodel>
<riskmodel name="ModelName" calculation="base_probability * distraction_odds_ratio">Your risk is about {result}%</riskmodel>
</nowiki></pre>
</nowiki></pre>


== Usage ==
== Usage ==
1. Use the `<riskmodel>` tag in your wikitext, specifying the `name` and `calculation` attributes.
2. Ensure variable names in the `calculation` match column names in a DataTable2 table.
3. Optionally, include a description between the opening and closing tags to document the model.
4. Reference the model by its `name` in other tags, like `<riskdisplay>`.


The `calculation` defines a mathematical expression using variables that correspond to DataTable2 column names, enabling risk computations when combined with other wiki features.
# Use the &lt;riskmodel&gt; tag in your wikitext, specifying the `name` and `calculation` attributes.
# Ensure variable names in the `calculation` match column names in a DataTable2 table.
# Include text between the opening and closing tags to describe the risk, using the `{result}` placeholder to show the calculated value.
# Optionally, use wikitext markup or templates like <nowiki>{{One_In_X|{result}}}</nowiki>, which converts fractional probabilities (e.g., 0.1) into text like "1 in 10".
# Reference the model by its `name` in other tags, like &lt;riskdisplay&gt;.
 
The `calculation` defines a mathematical expression using DataTable2 column names, and the text with `{result}` describes the risk outcome for display.


== Examples ==
== Examples ==


=== Basic Risk Model ===
=== Basic Risk Model ===
Define a risk model named "SimpleRisk" with a calculation:
Define a risk model named "ColdRisk" with a calculation and result description:
<pre><nowiki>
<pre><nowiki>
<riskmodel name="SimpleRisk" calculation="base_probability * distraction_odds_ratio">Multiplies base probability by distraction odds</riskmodel>
<riskmodel name="ColdRisk" calculation="base_probability * exposure_factor">Your risk of catching a cold is about {result}%</riskmodel>
</nowiki></pre>
</nowiki></pre>
This creates a model called "SimpleRisk" that multiplies `base_probability` and `distraction_odds_ratio` from a DataTable2 table.
This creates a model called "ColdRisk" that multiplies `base_probability` and `exposure_factor`, displaying the result as a percentage.
 
=== Risk Model with Template ===
Use the `One_In_X` template for human-friendly probability:
<pre><nowiki>
<riskmodel name="AccidentRisk" calculation="base_probability * distraction_odds_ratio">Your chance of an accident is {{One_In_X|{result}}}</riskmodel>
</nowiki></pre>
This model, "AccidentRisk", computes `base_probability * distraction_odds_ratio` and displays the result as "1 in X" (e.g., "1 in 10" for 0.1).


=== Risk Model with Complex Calculation ===
=== Risk Model with Complex Calculation ===
Define a model with a more complex expression:
Define a model with a more complex expression and wikitext formatting:
<pre><nowiki>
<pre><nowiki>
<riskmodel name="RiskScore" calculation="base_probability * severity_weight + mitigation_factor / 2">Calculates a weighted risk score</riskmodel>
<riskmodel name="RiskScore" calculation="base_probability * severity_weight + mitigation_factor / 2">The weighted risk score is '''{result}''' points</riskmodel>
</nowiki></pre>
</nowiki></pre>
This model, "RiskScore", computes `base_probability * severity_weight + mitigation_factor / 2`, using DataTable2 column names.
This model, "RiskScore", computes `base_probability * severity_weight + mitigation_factor / 2`, displaying the result in bold.


== Notes ==
== Notes ==
* The `name` attribute must be unique on the page to avoid conflicts.
* The `name` attribute must be unique on the page to avoid conflicts.
* Variable names in the `calculation` must match column names in a DataTable2 table (e.g., `base_probability`, `severity_weight`). Mismatched names will cause errors when used.
* Variable names in the `calculation` must match column names in a DataTable2 table (e.g., `base_probability`, `exposure_factor`). Mismatched names will cause errors.
* The `calculation` must be a valid mathematical expression. Invalid expressions will cause an error when used (e.g., in `<riskdisplay>`).
* The `{result}` placeholder must be included in the tag’s text to show the calculated value.
* The description inside the tag is optional but helps document the model’s purpose.
* The text inside the tag can include wikitext markup (e.g., `'''bold'''`) or templates like `{{One_In_X|{result}}}` for formatting the result.
* Risk models can be defined on the current page or a "Data/" subpage and referenced by name in other tags.
* Risk models can be defined on the current page or a "Data/" subpage and referenced by name in other tags.


Line 51: Line 61:
* **Model not found in `<riskdisplay>`** – Ensure the `name` matches exactly and the model is defined on the current page or a "Data/" subpage.
* **Model not found in `<riskdisplay>`** – Ensure the `name` matches exactly and the model is defined on the current page or a "Data/" subpage.
* **Calculation fails** – Verify that all variable names in the `calculation` match column names in the associated DataTable2 table.
* **Calculation fails** – Verify that all variable names in the `calculation` match column names in the associated DataTable2 table.
* **Result not displayed** – Ensure the `{result}` placeholder is included in the tag’s text and the calculation is valid.


For related features, see [[Help:RiskDisplay|RiskDisplay documentation]] or [[Extension:DataTable2|DataTable2 documentation]].
For related features, see [[Help:RiskDisplay|RiskDisplay documentation]]

Latest revision as of 17:10, 5 September 2025

Help:RiskModel

The <riskmodel> tag defines a risk model on a wiki page, specifying a calculation and a unique name for use in a RiskDisplay (most likely on another page; best practice is to put the risk model on a /Data subpage along with the data about a risk). Variables in the calculation must match column names in a DataTable2 table. The text inside the tag describes the risk and should include the `{result}` placeholder.

Syntax

The <riskmodel> tag supports these attributes:

  • `name`: (Required) A unique name for the risk model on the page.
  • `calculation`: (Required) The mathematical expression defining the model, using variable names that match DataTable2 column names (e.g., `base_probability * distraction_odds_ratio`).

Basic syntax:

<riskmodel name="ModelName" calculation="base_probability * distraction_odds_ratio">Your risk is about {result}%</riskmodel>

Usage

  1. Use the <riskmodel> tag in your wikitext, specifying the `name` and `calculation` attributes.
  2. Ensure variable names in the `calculation` match column names in a DataTable2 table.
  3. Include text between the opening and closing tags to describe the risk, using the `{result}` placeholder to show the calculated value.
  4. Optionally, use wikitext markup or templates like {{One_In_X|{result}}}, which converts fractional probabilities (e.g., 0.1) into text like "1 in 10".
  5. Reference the model by its `name` in other tags, like <riskdisplay>.

The `calculation` defines a mathematical expression using DataTable2 column names, and the text with `{result}` describes the risk outcome for display.

Examples

Basic Risk Model

Define a risk model named "ColdRisk" with a calculation and result description:

<riskmodel name="ColdRisk" calculation="base_probability * exposure_factor">Your risk of catching a cold is about {result}%</riskmodel>

This creates a model called "ColdRisk" that multiplies `base_probability` and `exposure_factor`, displaying the result as a percentage.

Risk Model with Template

Use the `One_In_X` template for human-friendly probability:

<riskmodel name="AccidentRisk" calculation="base_probability * distraction_odds_ratio">Your chance of an accident is {{One_In_X|{result}}}</riskmodel>

This model, "AccidentRisk", computes `base_probability * distraction_odds_ratio` and displays the result as "1 in X" (e.g., "1 in 10" for 0.1).

Risk Model with Complex Calculation

Define a model with a more complex expression and wikitext formatting:

<riskmodel name="RiskScore" calculation="base_probability * severity_weight + mitigation_factor / 2">The weighted risk score is '''{result}''' points</riskmodel>

This model, "RiskScore", computes `base_probability * severity_weight + mitigation_factor / 2`, displaying the result in bold.

Notes

  • The `name` attribute must be unique on the page to avoid conflicts.
  • Variable names in the `calculation` must match column names in a DataTable2 table (e.g., `base_probability`, `exposure_factor`). Mismatched names will cause errors.
  • The `{result}` placeholder must be included in the tag’s text to show the calculated value.
  • The text inside the tag can include wikitext markup (e.g., `bold`) or templates like `Error: Invalid probability}` for formatting the result.
  • Risk models can be defined on the current page or a "Data/" subpage and referenced by name in other tags.

Troubleshooting

  • **Error: "riskmodel: missing name attribute"** – Include the `name` attribute in the tag.
  • **Error: "riskmodel: missing calculation attribute"** – Include the `calculation` attribute.
  • **Error: "riskmodel [expression]: [error message]"** – Check the `calculation` for syntax errors (e.g., unbalanced parentheses or invalid operators).
  • **Model not found in `<riskdisplay>`** – Ensure the `name` matches exactly and the model is defined on the current page or a "Data/" subpage.
  • **Calculation fails** – Verify that all variable names in the `calculation` match column names in the associated DataTable2 table.
  • **Result not displayed** – Ensure the `{result}` placeholder is included in the tag’s text and the calculation is valid.

For related features, see RiskDisplay documentation