Confidence interval
daspi.plotlib.plotter.ConfidenceInterval(source, target, n_groups=1, feature='', show_center=True, bars_same_color=False, skip_na=None, target_on_y=True, confidence_level=0.95, ci_func=mean_ci, color=None, marker=None, ax=None, visible_spines=None, hide_axis=None, **kwds)
¶
Bases: Errorbar
Class for creating plotters with error bars representing optical distinction tests.
This class is useful for visually testing whether there is a statistically significant difference between groups or conditions. By plotting confidence intervals around the actual value, it provides a visual representation of the uncertainty in the estimate and allows for a quick assessment of whether the intervals overlap or not.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Pandas long format DataFrame containing the data source for the plot.
TYPE:
|
target
|
Column name of the target variable for the plot.
TYPE:
|
n_groups
|
Number of groups (variable combinations) for the Bonferroni
adjustment. A good way to do this is to pass
TYPE:
|
feature
|
Column name of the feature variable for the plot, by default ''.
TYPE:
|
show_center
|
Flag indicating whether to show the center points, by default True.
TYPE:
|
bars_same_color
|
Flag indicating whether to use same color for error bars as markers for center. If False, the error bars are black, by default False
TYPE:
|
skip_na
|
Flag indicating whether to skip missing values in the feature grouped data, by default None - None, no missing values are skipped - all', grouped data is skipped if all values are missing - any', grouped data is skipped if any value is missing
TYPE:
|
target_on_y
|
Flag indicating whether the target variable is plotted on the y-axis, by default True.
TYPE:
|
confidence_level
|
Confidence level for the confidence intervals, by default 0.95.
TYPE:
|
ci_func
|
Function for calculating the confidence intervals. The following
two arguments are passed to the function: The sample data and
the confidence level. The returned values must be three floats
in order: center value, lower confidence limit and upper
confidence limit.
Default is
TYPE:
|
color
|
Color to be used to draw the artists. If None, the first color is taken from the color cycle, by default None.
TYPE:
|
marker
|
The marker style for the center points. Available markers see: https://matplotlib.org/stable/api/markers_api.html, by default None
TYPE:
|
ax
|
The axes object for the plot. If None, the current axes is
fetched using
TYPE:
|
visible_spines
|
Specifies which spines are visible, the others are hidden. If 'none', no spines are visible. If None, the spines are drawn according to the stylesheet. Defaults to None.
TYPE:
|
hide_axis
|
Specifies which axes should be hidden. If None, both axes are displayed. Defaults to None.
TYPE:
|
**kwds
|
Additional keyword arguments that have no effect and are only used to catch further arguments that have no use here (occurs when this class is used within chart objects).
DEFAULT:
|
Examples:
Apply to an existing Axes object:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from daspi import ConfidenceInterval, variance_ci
fig, ax = plt.subplots()
df = pd.DataFrame(dict(
x = ['first'] * 50 + ['second'] * 50 + ['third'] * 50,
y = (
list(np.random.normal(loc=3, scale=1, size=50))
+ list(np.random.normal(loc=4, scale=1, size=50))
+ list(np.random.normal(loc=2, scale=1, size=50)))))
ci = ConfidenceInterval(
source=df, target='y', feature='x', show_center=True, ci_func=variance_ci,
n_groups=df.x.nunique(), confidence_level=0.95, bars_same_color=True,
ax=ax)
ci(kw_center=dict(s=30, marker='_'))
ci.label_feature_ticks()
Apply using the plot method of a DaSPi Chart object:
import numpy as np
import daspi as dsp
import pandas as pd
df = pd.DataFrame(dict(
x = ['first'] * 50 + ['second'] * 50 + ['third'] * 50,
y = (
list(np.random.normal(loc=1, scale=3, size=50))
+ list(np.random.normal(loc=1, scale=4, size=50))
+ list(np.random.normal(loc=1, scale=2, size=50)))))
chart = dsp.SingleChart(
source=df,
target='y',
feature='x',
categorical_feature=True, # neded to label the feature tick labels
).plot(
dsp.ConfidenceInterval,
show_center=True,
ci_func=dsp.variance_ci,
n_groups=df.x.nunique(),
confidence_level=0.95,
bars_same_color=True,
kw_call=dict(kw_center=dict(s=30, marker='_'))
).label() # neded to label the feature tick labels
confidence_level = confidence_level
instance-attribute
¶
Confidence level for the confidence intervals.
ci_func = ci_func
instance-attribute
¶
Provided function for calculating the confidence intervals.
n_groups = n_groups
instance-attribute
¶
Number of unique feature values.
transform(feature_data, target_data)
¶
Perform the transformation on the target data by using the given function `ci_func' and return the transformed data.
| PARAMETER | DESCRIPTION |
|---|---|
feature_data
|
Base location (offset) of feature axis coming from
TYPE:
|
target_data
|
Feature grouped target data used for transformation, coming
from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
data
|
The transformed data source for the plot.
TYPE:
|