@varia-bly/variably-sdk
Version:
Official JavaScript/TypeScript SDK for Variably feature flags, experimentation, LLM experiments with React hooks, and real-time dynamic configurations
100 lines • 3.01 kB
TypeScript
/**
* Statistical analysis utilities for A/B testing and experimentation
* Implements advanced analytics features from the metrics collection documentation
*/
export interface ABTestResult {
treatmentGroup: string;
controlGroup: string;
treatmentConversion: number;
controlConversion: number;
treatmentSampleSize: number;
controlSampleSize: number;
conversionLift: number;
conversionLiftPercent: number;
pValue: number;
statisticalSignificance: boolean;
confidenceLevel: number;
confidenceInterval: [number, number];
minimumDetectableEffect: number;
power: number;
requiredSampleSize?: number;
testDuration?: number;
}
export interface CohortAnalysisResult {
cohortName: string;
cohortSize: number;
retentionRates: {
period: string;
retainedUsers: number;
retentionRate: number;
}[];
ltv?: number;
churnRate: number;
}
export interface FunnelStep {
stepName: string;
eventName: string;
userCount: number;
conversionRate: number;
dropoffRate: number;
}
export interface FunnelAnalysisResult {
funnelName: string;
totalUsers: number;
overallConversionRate: number;
steps: FunnelStep[];
biggestDropoff: {
fromStep: string;
toStep: string;
dropoffRate: number;
};
}
export declare class StatisticalAnalysis {
private static readonly Z_SCORE_95_CONFIDENCE;
private static readonly Z_SCORE_99_CONFIDENCE;
/**
* Calculate statistical significance for A/B test
*/
static calculateABTestSignificance(treatmentConversions: number, treatmentTotal: number, controlConversions: number, controlTotal: number, confidenceLevel?: number): ABTestResult;
/**
* Calculate required sample size for A/B test
*/
static calculateRequiredSampleSize(baselineConversion: number, minimumDetectableEffect: number, power?: number, confidenceLevel?: number): number;
/**
* Perform cohort analysis for user retention
*/
static analyzeCohort(cohortUsers: string[], userEvents: {
userId: string;
eventName: string;
timestamp: Date;
}[], retentionEvent?: string, periods?: string[]): CohortAnalysisResult;
/**
* Analyze conversion funnel
*/
static analyzeFunnel(funnelSteps: string[], userEvents: {
userId: string;
eventName: string;
timestamp: Date;
}[], timeWindow?: number): FunnelAnalysisResult;
/**
* Normal cumulative distribution function approximation
*/
private static normalCDF;
/**
* Calculate Minimum Detectable Effect
*/
private static calculateMDE;
/**
* Calculate statistical power
*/
private static calculatePower;
/**
* Get Z-score for given statistical power
*/
private static getZScoreForPower;
/**
* Parse period string to days
*/
private static parsePeriodToDays;
}
//# sourceMappingURL=statistical-analysis.d.ts.map