Paired T Test chart plugin for Apache Superset that visualizes statistical differences between groups.
npx @tessl/cli install tessl/npm-superset-ui--legacy-plugin-chart-paired-t-test@0.18.0A specialized chart plugin for Apache Superset that provides paired t-test statistical analysis and visualization in a tabular format. This plugin enables users to compare statistical differences between groups using paired t-test methodology, displaying results with configurable precision and significance testing.
Dependencies: This plugin requires distributions for statistical calculations and reactable for table rendering.
npm install @superset-ui/legacy-plugin-chart-paired-t-testimport PairedTTestChartPlugin from '@superset-ui/legacy-plugin-chart-paired-t-test';For CommonJS:
const PairedTTestChartPlugin = require('@superset-ui/legacy-plugin-chart-paired-t-test');Import specific components:
import PairedTTestChartPlugin, { dataPropType } from '@superset-ui/legacy-plugin-chart-paired-t-test';import PairedTTestChartPlugin from '@superset-ui/legacy-plugin-chart-paired-t-test';
// Register the plugin with Superset
new PairedTTestChartPlugin().configure({ key: 'paired-t-test' }).register();
// Use with SuperChart
<SuperChart
chartType="paired-t-test"
width={600}
height={600}
formData={{
groupby: ['experiment_group'],
metrics: ['conversion_rate', 'click_through_rate'],
significance_level: 0.05,
pvalue_precision: 6,
liftvalue_precision: 4
}}
queriesData={[{
data: {
conversion_rate: [
{
group: ['control'],
values: [{ x: 1, y: 0.15 }, { x: 2, y: 0.16 }, { x: 3, y: 0.14 }]
},
{
group: ['treatment'],
values: [{ x: 1, y: 0.18 }, { x: 2, y: 0.19 }, { x: 3, y: 0.17 }]
}
]
}
}]}
/>The plugin follows Superset's chart plugin architecture with these key components:
Main plugin class that extends Superset's ChartPlugin to provide paired t-test functionality.
class PairedTTestChartPlugin extends ChartPlugin {
constructor();
}The plugin exports a default class that can be instantiated, configured and registered with Superset.
The plugin includes metadata that describes its characteristics to Superset.
/**
* Chart metadata configuration
* Contains display information and behavioral settings for the chart
*/
const metadata = {
category: 'Correlation',
description: 'Table that visualizes paired t-tests, which are used to understand statistical differences between groups.',
name: 'Paired t-test Table',
tags: ['Legacy', 'Statistical', 'Tabular'],
thumbnail: string, // Path to thumbnail image
useLegacyApi: true
};Usage:
import PairedTTestChartPlugin from '@superset-ui/legacy-plugin-chart-paired-t-test';
// Configure and register the plugin
new PairedTTestChartPlugin().configure({ key: 'paired-t-test' }).register();Main React component for rendering the paired t-test visualization.
/**
* React component that renders paired t-test analysis tables
* @param alpha - Significance level threshold (default: 0.05)
* @param className - CSS class name for styling
* @param data - Object containing metric data for analysis
* @param groups - Array of group names for comparison
* @param liftValPrec - Decimal precision for lift values (default: 4)
* @param metrics - Array of metric names to analyze
* @param pValPrec - Decimal precision for p-values (default: 6)
*/
class PairedTTest extends React.PureComponent {
static propTypes: {
alpha: PropTypes.number,
className: PropTypes.string,
data: PropTypes.objectOf(dataPropType).isRequired,
groups: PropTypes.arrayOf(PropTypes.string).isRequired,
liftValPrec: PropTypes.number,
metrics: PropTypes.arrayOf(PropTypes.string).isRequired,
pValPrec: PropTypes.number
};
static defaultProps: {
alpha: 0.05,
className: '',
liftValPrec: 4,
pValPrec: 6
};
}React component that renders individual metric t-test analysis tables with interactive features.
/**
* React component that renders a statistical analysis table for a single metric
* @param alpha - Significance level threshold for determining statistical significance
* @param data - Array of data groups with statistical values
* @param groups - Array of group names for table columns
* @param liftValPrec - Number of decimal places for lift value display
* @param metric - Name of the metric being analyzed
* @param pValPrec - Number of decimal places for p-value display
*/
class TTestTable extends React.Component {
static propTypes: {
alpha: PropTypes.number,
data: dataPropType.isRequired,
groups: PropTypes.arrayOf(PropTypes.string).isRequired,
liftValPrec: PropTypes.number,
metric: PropTypes.string.isRequired,
pValPrec: PropTypes.number
};
static defaultProps: {
alpha: 0.05,
liftValPrec: 4,
pValPrec: 6
};
/**
* Calculate lift percentage between two data series
* @param values - Target group values
* @param control - Control group values
* @returns Formatted lift percentage string
*/
computeLift(values: DataPoint[], control: DataPoint[]): string;
/**
* Calculate p-value using Student's t-test
* @param values - Target group values
* @param control - Control group values
* @returns Formatted p-value string or NaN for invalid calculations
*/
computePValue(values: DataPoint[], control: DataPoint[]): string | number;
/**
* Compute statistical analysis for all groups against selected control
* @param control - Index of the control group
*/
computeTTest(control: number): void;
/**
* Get CSS class name for styling lift values based on their status
* @param row - Row index to check
* @returns CSS class name ('control', 'invalid', 'true', or 'false')
*/
getLiftStatus(row: number): string;
/**
* Get CSS class name for styling p-values based on their status
* @param row - Row index to check
* @returns CSS class name ('control', 'invalid', or '')
*/
getPValueStatus(row: number): string;
/**
* Determine if a result is statistically significant
* @param row - Row index to check
* @returns 'control' for control group, boolean for significance status
*/
getSignificance(row: number): string | boolean;
}Function that transforms Superset chart properties into component-specific props.
/**
* Transform Superset chart props to component props
* @param chartProps - Chart properties from Superset containing formData and queriesData
* @returns Transformed props object for PairedTTest component
*/
function transformProps(chartProps: {
formData: {
groupby: string[],
liftvaluePrecision: string | number,
metrics: string[] | MetricObject[],
pvaluePrecision: string | number,
significanceLevel: number
},
queriesData: Array<{ data: any }>
}): {
alpha: number,
data: any,
groups: string[],
liftValPrec: number,
metrics: string[],
pValPrec: number
};PropTypes definition for data validation, exported for external use.
/**
* PropTypes definition for validating data structure passed to TTestTable
* Can be imported and reused in other components
*/
export const dataPropType: PropTypes.Validator<Array<{
group: string[],
values: Array<{ x: number, y: number }>
}>>;Configuration object that defines the chart's control panel interface in Superset.
/**
* Control panel configuration for Superset UI
* Defines the form controls available when configuring the chart
*/
const config: ControlPanelConfig = {
controlPanelSections: [
// Legacy time controls section
{
label: string,
expanded: boolean,
controlSetRows: Array<string[] | ControlConfig[]>
},
// Query configuration section
{
label: 'Query',
expanded: true,
controlSetRows: [
['metrics'],
['adhoc_filters'],
[{
name: 'groupby',
override: {
validators: [validateNonEmpty]
}
}], // Required field with validation
['limit', 'timeseries_limit_metric'],
['order_desc'],
[{
name: 'contribution',
config: {
type: 'CheckboxControl',
label: 'Contribution',
default: false,
description: 'Compute the contribution to the total'
}
}], // Checkbox for contribution calculation
['row_limit', null]
]
},
// Parameters section
{
label: 'Parameters',
expanded: false,
controlSetRows: [
[{
name: 'significance_level',
config: {
type: 'TextControl',
label: 'Significance Level',
default: 0.05,
description: 'Threshold alpha level for determining significance'
}
}], // Alpha threshold (default: 0.05)
[{
name: 'pvalue_precision',
config: {
type: 'TextControl',
label: 'p-value precision',
default: 6,
description: 'Number of decimal places with which to display p-values'
}
}], // P-value decimal places (default: 6)
[{
name: 'liftvalue_precision',
config: {
type: 'TextControl',
label: 'Lift percent precision',
default: 4,
description: 'Number of decimal places with which to display lift values'
}
}] // Lift value decimal places (default: 4)
]
}
]
};/**
* Data structure for individual data points in time series
*/
interface DataPoint {
x: number; // Time or sequence value
y: number; // Metric value
}
/**
* PropTypes definition for data validation
* Represents the structure of data passed to TTestTable
*/
const dataPropType = PropTypes.arrayOf(
PropTypes.shape({
group: PropTypes.arrayOf(PropTypes.string), // Group identifier values
values: PropTypes.arrayOf(
PropTypes.shape({
x: PropTypes.number, // Time or sequence value
y: PropTypes.number // Metric value
})
)
})
);
/**
* Metric object structure when metrics are objects rather than strings
*/
interface MetricObject {
label: string; // Display name for the metric
}
/**
* Control configuration for form controls
*/
interface ControlConfig {
name: string;
config?: {
type: string;
label: string;
default: any;
description: string;
};
override?: {
validators: Function[];
};
}
/**
* Control panel configuration structure from @superset-ui/chart-controls
*/
interface ControlPanelConfig {
controlPanelSections: Array<{
label: string;
expanded: boolean;
controlSetRows: Array<string[] | ControlConfig[]>;
}>;
}The plugin supports several configuration options through Superset's control panel:
The plugin handles several error conditions: