metbit.utility
Statistics and utilities module in metbit 7.3.11.
import metbit.utilityClasses
lazypair
Methods
__init__(self, dataset, column_name)
get_index(self)
get_name(self)
get_meta(self)
get_column_name(self)
get_dataset(self)
gen_page
Methods
__init__(self, data_path)
This function takes in the path to the data folder and returns the HTML files for the OPLS-DA plots.
Parameters
data_pathstrThe path to the data folder. gen_page(data_path).get_files()
get_files(self)
oplsda_path
Methods
__init__(self, data_path)
make_path(self)
get_path(self)
Normality_distribution
Methods
__init__(self, data: pd.DataFrame)
plot_distribution(self, feature)
pca_distributions(self)
Normalise
Methods
__init__(self, data: pd.DataFrame, compute_missing: bool=True)
This function takes in a dataframe and returns the normalised dataframe.
Parameters
datapandas dataframeThe dataframe to be used. Normalise(data).normalise()
pqn_normalise(self, ref_index: list=None, plot: bool=True)
decimal_place_normalisation(self, decimals: int=2)
This function returns the dataframe with values rounded to a specified number of decimal places.
Parameters
decimalsintThe number of decimal places to round to.
z_score_normalisation(self)
This function returns the dataframe normalized using Z-Score.
linear_normalisation(self)
This function returns the dataframe normalized using Min-Max (linear normalization).
normalize_to_100(self)
This function returns the dataframe with values normalized to 100.
clipping_normalisation(self, lower: float, upper: float)
This function returns the dataframe with values clipped to the specified range.
Parameters
lowerfloatThe lower bound for clipping.
upperfloatThe upper bound for clipping.
standard_deviation_normalisation(self)
This function returns the dataframe normalized using Standard Deviation.
univar_stats
A class for creating univariate box or violin plots with statistical annotations.
This class supports group comparisons using t-tests, ANOVA, or nonparametric tests, along with effect size computation and multiple testing correction. It outputs interactive Plotly figures.
Parameters
dfpd.DataFrameInput DataFrame containing the data to plot.
x_colstrColumn name to use for grouping (x-axis categories).
y_colstrColumn name for numeric values (y-axis).
group_orderlist, optionalCustom group ordering (default: inferred from data).
custom_colorsdict, optionalMapping of group names to Plotly color codes.
stats_optionslist of str, optionalStatistical options to apply. Choices: ['t-test', 'anova', 'nonparametric', 'effect-size'].
p_value_thresholdfloat, default=0.05Significance threshold for annotations.
annotate_stylestr, default='value'Annotation format. 'value' shows p-values, 'symbol' shows *, **, ***.
y_offset_factorfloat, default=0.35Controls vertical spacing of annotation lines.
show_non_significantbool, default=TrueShow non-significant comparisons or not.
correct_pstr or None, default='bonferroni'Correction method for multiple comparisons (e.g., 'bonferroni', 'fdr_bh').
title_str, optionalPlot title. Defaults to y_col if not set.
y_labelstr, optionalLabel for y-axis. Defaults to y_col.
x_labelstr, optionalLabel for x-axis. Defaults to x_col.
fig_heightint, default=800Height of the plot in pixels.
fig_widthint, default=600Width of the plot in pixels.
plot_typestr, default='box'Type of plot'box' or 'violin'.show_axis_linesbool, default=TrueWhether to show axis lines around the plot.
Returns
plotly.graph_objects.Figure Interactive Plotly figure.
Examples
>>> import pandas as pd >>> from univar_stats import univar_stats >>> import numpy as np
>>> # Create example data >>> df = pd.DataFrame({ ... "group": np.repeat(["A", "B", "C"], 30), ... "value": np.concatenate([ ... np.random.normal(5, 1, 30), ... np.random.normal(6, 1, 30), ... np.random.normal(7, 1, 30) ... ]) ... })
>>> # Initialize the plotting object >>> plotter = univar_stats( ... df, x_col="group", y_col="value", ... stats_options=["t-test", "effect-size"], ... annotate_style="symbol", plot_type="box" ... )
>>> # Generate and show the plot >>> fig = plotter.plot() >>> fig.show()