Help:RiskModel: Difference between revisions
m Fix missing nowiki |
No edit summary |
||
Line 1: | Line 1: | ||
= Help:RiskModel = | = Help:RiskModel = | ||
The <riskmodel> tag defines a risk model on a wiki page, specifying | The <riskmodel> tag defines a risk model on a wiki page, specifying 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) and text that is displayed to the user after they select any risk parameters. | ||
== Syntax == | == Syntax == | ||
Line 7: | Line 7: | ||
* `name`: (Required) A unique name for the risk model on the page. | * `name`: (Required) A unique name for the risk model on the page. | ||
Basic syntax: | Basic syntax: | ||
<pre><nowiki> | <pre><nowiki> | ||
<riskmodel name="ModelName | <riskmodel name="ModelName">Your risk is about {{#expr: {base_probability} * {distraction_odds_ratio} }}%</riskmodel> | ||
</nowiki></pre> | </nowiki></pre> | ||
== Usage == | == Usage == | ||
# Include text between the opening and closing tags to describe the risk, using the `{variable}` placeholder to show user-selected values (`variable` will be a column name from a DropDown). | |||
# Use the {{#expr: }} extension to compute a risk score from user-selected values | |||
# Include text between the opening and closing tags to describe the risk, using the `{ | # Optionally, use templates like <nowiki>{{One_In_X|...}}</nowiki>, which converts fractional probabilities (e.g., 0.1) into text like "1 in 10". | ||
# Optionally, use | |||
# Reference the model by its `name` in other tags, like [[Help:RiskDisplay|RiskDisplay]]. | # Reference the model by its `name` in other tags, like [[Help:RiskDisplay|RiskDisplay]]. | ||
Line 25: | Line 23: | ||
The following placeholders in the text between the opening and closing riskmodel tags are replaced before any templates or other WikiText are processed: | The following placeholders in the text between the opening and closing riskmodel tags are replaced before any templates or other WikiText are processed: | ||
* {pagestate} : all of the key/value pairs from [[Help:DropDown|DropDown]] or [[Help:RiskParameter|RiskParameter]] as a single string in the format: key1=value1|key2=value2|...etc. This is so you can easily pass the page state to templates. For example, <nowiki>{{SomeFancyTemplate|result={result}|{pagestate}}}</nowiki> might have logic to display "The risk of 58-year-old male who eats a poppy-seed bagel four times a week of failing a drug test is about ..." | * {pagestate} : all of the key/value pairs from [[Help:DropDown|DropDown]] or [[Help:RiskParameter|RiskParameter]] as a single string in the format: key1=value1|key2=value2|...etc. This is so you can easily pass the page state to templates. For example, <nowiki>{{SomeFancyTemplate|result={result}|{pagestate}}}</nowiki> might have logic to display "The risk of 58-year-old male who eats a poppy-seed bagel four times a week of failing a drug test is about ..." | ||
* {''variable''} where ''variable'' is any of the values set by a [[Help:DropDown|DropDown]] or [[Help:RiskParameter|RiskParameter]] | * {''variable''} where ''variable'' is any of the values set by a [[Help:DropDown|DropDown]] or [[Help:RiskParameter|RiskParameter]] | ||
Line 34: | Line 31: | ||
Define a risk model named "ColdRisk" with a calculation and result description: | Define a risk model named "ColdRisk" with a calculation and result description: | ||
<pre><nowiki> | <pre><nowiki> | ||
<riskmodel name="ColdRisk | <riskmodel name="ColdRisk">Your risk of catching a cold is about {{#expr: {base_probability}*{exposure_factor} }}%</riskmodel> | ||
</nowiki></pre> | </nowiki></pre> | ||
This creates a model called "ColdRisk" that multiplies `base_probability` and `exposure_factor`, displaying the result as a percentage. | This creates a model called "ColdRisk" that multiplies `base_probability` and `exposure_factor`, displaying the result as a percentage. | ||
Line 41: | Line 38: | ||
Use the `One_In_X` template for human-friendly probability: | Use the `One_In_X` template for human-friendly probability: | ||
<pre><nowiki> | <pre><nowiki> | ||
<riskmodel name="AccidentRisk" calculation="base_probability * distraction_odds_ratio">Your chance of an accident is {{One_In_X|{ | <riskmodel name="AccidentRisk" calculation="base_probability * distraction_odds_ratio">Your chance of an accident is {{One_In_X|{{#expr: {base_probability}*{distraction_odds_ration} }} }}</riskmodel> | ||
</nowiki></pre> | </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). | 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). | ||
Line 48: | Line 45: | ||
Define a model with a more complex expression and wikitext formatting: | Define a model with a more complex expression and wikitext formatting: | ||
<pre><nowiki> | <pre><nowiki> | ||
<riskmodel name="RiskScore | <riskmodel name="RiskScore">The weighted risk score is '''{{#expr: {base_probability} * {severity_weight} + {mitigation_factor} / 2}}''' points</riskmodel> | ||
</nowiki></pre> | </nowiki></pre> | ||
This model, "RiskScore", computes `base_probability * severity_weight + mitigation_factor / 2`, displaying the result in bold. | This model, "RiskScore", computes `base_probability * severity_weight + mitigation_factor / 2`, displaying the result in bold. | ||
Line 56: | Line 53: | ||
* 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 RiskData table (e.g., `base_probability`, `exposure_factor`). Mismatched names will cause errors. | * Variable names in the `calculation` must match column names in a RiskData table (e.g., `base_probability`, `exposure_factor`). Mismatched names will cause errors. | ||
* The text inside the tag can include wikitext markup (e.g., `'''bold'''`) or templates like `{{One_In_X|{result}}}` for formatting the result. | * 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. | ||
== Troubleshooting == | == Troubleshooting == | ||
* | * ''Error: "riskmodel: missing name attribute"'' – Include the `name` attribute in the tag. | ||
* | * ''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 RiskData 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]] | For related features, see [[Help:RiskDisplay|RiskDisplay documentation]] |
Latest revision as of 19:23, 17 September 2025
Help:RiskModel
The <riskmodel> tag defines a risk model on a wiki page, specifying 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) and text that is displayed to the user after they select any risk parameters.
Syntax
The <riskmodel> tag supports these attributes:
- `name`: (Required) A unique name for the risk model on the page.
Basic syntax:
<riskmodel name="ModelName">Your risk is about {{#expr: {base_probability} * {distraction_odds_ratio} }}%</riskmodel>
Usage
- Include text between the opening and closing tags to describe the risk, using the `{variable}` placeholder to show user-selected values (`variable` will be a column name from a DropDown).
- Use the extension to compute a risk score from user-selected values
- Optionally, use templates like {{One_In_X|...}}, which converts fractional probabilities (e.g., 0.1) into text like "1 in 10".
- Reference the model by its `name` in other tags, like RiskDisplay.
Magic placeholders
The following placeholders in the text between the opening and closing riskmodel tags are replaced before any templates or other WikiText are processed:
- {pagestate} : all of the key/value pairs from DropDown or RiskParameter as a single string in the format: key1=value1|key2=value2|...etc. This is so you can easily pass the page state to templates. For example, {{SomeFancyTemplate|result={result}|{pagestate}}} might have logic to display "The risk of 58-year-old male who eats a poppy-seed bagel four times a week of failing a drug test is about ..."
- {variable} where variable is any of the values set by a DropDown or RiskParameter
Examples
Basic Risk Model
Define a risk model named "ColdRisk" with a calculation and result description:
<riskmodel name="ColdRisk">Your risk of catching a cold is about {{#expr: {base_probability}*{exposure_factor} }}%</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|{{#expr: {base_probability}*{distraction_odds_ration} }} }}</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">The weighted risk score is '''{{#expr: {base_probability} * {severity_weight} + {mitigation_factor} / 2}}''' 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 RiskData table (e.g., `base_probability`, `exposure_factor`). Mismatched names will cause errors.
- The text inside the tag can include wikitext markup (e.g., `bold`) or templates like `Error: Invalid probability {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.
Troubleshooting
- Error: "riskmodel: missing name attribute" – Include the `name` attribute in the tag.
- 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 RiskData 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