hb_method module

class HBMethod(database, hb_get_data_func, selected_state_keys, selected_ident, variable)

Bases: object

Module for detecting outliers using the Hidiroglou-Berthelot (HB) method in a Dash application.

This module applies the HB method to identify potential outliers in time-series data by comparing values in the current period (t) with revised values from the previous period (t-1). It includes methods for preprocessing data, visualizing results, and managing interactions in a Dash app.

Parameters:
  • database (object)

  • hb_get_data_func (Callable[[...], DataFrame])

  • selected_state_keys (list[str])

  • selected_ident (str)

  • variable (str)

database

Database connection or interface for fetching data.

Type:

object

hb_get_data

Function for retrieving data based on selected parameters.

Type:

callable

References

More information about the HB method: https://rdrr.io/github/statisticsnorway/Kostra/man/Hb.html

callbacks()

Registers callbacks for the HB method Dash app components.

Return type:

None

Notes

This method registers Dash callbacks for handling user interactions, including running the HB method, toggling the modal, and passing results to variabelvelger.

layout()

Generates the layout for the HB method Dash component.

Returns:

Div containing the modal and interactive elements for the HB method.

Return type:

dash.html.Div

make_hb_data(data_df, pc, pu, pa, ident, variable)

Processes data using the HB method for outlier detection.

Parameters:
  • data_df (pandas.DataFrame) – Input data containing variables for analysis.

  • pc (int) – Confidence interval control parameter.

  • pu (float) – Parameter for adjusting the variable’s level.

  • pa (float) – Parameter for small differences between quartiles and the median.

  • ident (str) – Identifier field name in the dataset.

  • variable (str) – Name of the value variable for analysis.

Returns:

Processed data with outlier results, sorted by “maxX”.

Return type:

pandas.DataFrame

make_hb_figure(data)

Creates a Plotly figure for visualizing HB method results.

Parameters:

data (pandas.DataFrame) – Processed data from the HB method, including outlier and limit values.

Returns:

Plotly figure with scatter plots for observations and limits.

Return type:

plotly.graph_objects.Figure