Jump to content

Help:RiskModel

From RiskiPedia

Help:RiskModel

The <riskmodel> tag defines a reusable risk model on a wiki page. It specifies a unique name, an optional set of pre-calculation parameters, and the final wikitext to be rendered.

Risk models are defined on a page (best practice is to put them on a /Data subpage) and are saved to the database when the page is edited. They are then used by the <riskdisplay> tag to show interactive risk calculations.

Syntax

The <riskmodel> tag supports these attributes:

  • `name`: (Required) A unique name for the risk model on the page.
  • `data-*`: (Optional) A set of attributes to define pre-calculation steps. For example, `data-base_risk="100"` or data-adjusted_risk="{{#expr: {base_risk} * {user_factor}}}".

---

Basic Syntax

<riskmodel name="ModelName">
  Your risk is about {{#expr: {base_probability} * {distraction_odds_ratio} }}%
</riskmodel>

---

Syntax with Pre-calculations

You can use `data-` attributes to define intermediate variables. This makes complex models much easier to read and manage.

<riskmodel name="AdvancedModel"
  data-base_score="{{#expr: {age} * 1.5}}"
  data-smoker_penalty="{{#expr: {is_smoker} * 100}}"
  data-total_risk="{{#expr: {base_score} + {smoker_penalty}}}"
>
  Your total risk score is {total_risk}.
  (Base: {base_score}, Smoker Penalty: {smoker_penalty})
</riskmodel>

Usage

  1. Define the model with a `name` attribute.
  2. (Optional) Define pre-calculations using `data-` attributes.
    • These create new placeholders (like `{base_score}`) that can be used in other `data-` attributes or in the main content.
    • The expressions can use external placeholders (like `{age}` from a dropdown) or placeholders from other `data-` attributes.
    • For clarity, it's best to define `data-` attributes in a logical, top-to-bottom order.
  3. Write the main content between the opening and closing tags. This is the wikitext that will be rendered by a <riskdisplay> tag.
  4. Use placeholders (like `{total_risk}`) to show the final calculated values.

Magic Placeholders

The following placeholders are available for use in your `data-` attributes and in the main content of the <riskmodel> tag:

  • `{variable}` (from `data-` attributes): Any placeholder you define in a `data-` attribute (e.g., `data-foo="..."` creates `{foo}`).
  • `{variable}` (from page state): Any value set by a DropDown, RiskParameter, or RiskDataLookup (e.g., `{age}`).
  • `{pagestate}`: All key/value pairs from the page state, formatted as a single string: `key1=value1|key2=value2|...`. This is useful for passing all inputs to a template, e.g., {{SomeTemplate|{pagestate}}}.

Examples

Basic Risk Model

Define a risk model named "ColdRisk" with a simple calculation:

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

This creates a model that multiplies `base_probability` and `exposure_factor` (which must be provided by DropDowns, RiskParameters, or RiskDataLookup).

Risk Model with Pre-calculations

This example breaks a complex calculation into named steps using `data-` attributes.

<riskmodel name="HeartRisk"
  data-age_risk="{{#expr: {age} * 1.2}}"
  data-bmi_risk="{{#expr: {bmi} * 0.8}}"
  data-lifestyle_risk="{{#expr: {is_smoker} * 50 + {exercises_weekly} * -10}}"
  data-total_score="{{#expr: {age_risk} + {bmi_risk} + {lifestyle_risk}}}"
>
  The weighted risk score is '''{total_score}''' points.
</riskmodel>

This model uses `{age}`, `{bmi}`, `{is_smoker}`, and `{exercises_weekly}` from the page state, computes four intermediate values, and finally displays `{total_score}` in bold.

Notes

  • The `name` attribute must be unique on the page.
  • Placeholders (like `{age}`) used in `data-` expressions must be defined either by another `data-` attribute or by an external source like a DropDown.
  • The text inside the tag can include any wikitext, including formatting (bold) or templates.
  • `data-` expressions can appear in any order and will be evaluated in the correct dependency order, but circular references (e.g., `data-foo="{bar}"` and `data-bar="{foo}"`) are not allowed.

Troubleshooting

  • Error: "riskmodel: missing name attribute" – You must include the `name` attribute in the tag.
  • Error: "Circular reference detected..." – Your `data-` attributes have a logic loop. You must fix the logic to break the cycle.
  • 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 or shows wikitext – Verify that all placeholders are spelled correctly and are available (either from a `data-` attribute or page state).

For related features, see RiskDisplay documentation.