Statsig Calculator

Statsig Calculator – Optimize Your Feature Flags :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –input-border-color: #ccc; –card-background: #ffffff; –shadow: 0 2px 4px rgba(0, 0, 0, 0.1); –border-radius: 8px; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); margin: 0; padding: 0; line-height: 1.6; } .container { max-width: 1000px; margin: 20px auto; padding: 20px; background-color: var(–card-background); border-radius: var(–border-radius); box-shadow: var(–shadow); } h1, h2, h3 { color: var(–primary-color); text-align: center; } h1 { margin-bottom: 20px; } h2 { margin-top: 30px; margin-bottom: 15px; border-bottom: 2px solid var(–primary-color); padding-bottom: 5px; } h3 { margin-top: 20px; margin-bottom: 10px; } .loan-calc-container { background-color: var(–card-background); padding: 25px; border-radius: var(–border-radius); box-shadow: var(–shadow); margin-bottom: 30px; border: 1px solid #e0e0e0; } .input-group { margin-bottom: 15px; padding: 10px; border-radius: var(–border-radius); background-color: #fefefe; border: 1px solid var(–input-border-color); } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group input[type="text"], .input-group select { width: calc(100% – 22px); /* Adjust for padding and border */ padding: 10px; margin-bottom: 5px; border: 1px solid var(–input-border-color); border-radius: var(–border-radius); box-sizing: border-box; /* Include padding and border in the element's total width and height */ font-size: 1rem; } .input-group .helper-text { font-size: 0.85em; color: #666; display: block; margin-top: 5px; } .input-group .error-message { color: red; font-size: 0.85em; margin-top: 5px; display: none; /* Hidden by default */ } .button-group { text-align: center; margin-top: 20px; } button { background-color: var(–primary-color); color: white; padding: 12px 25px; border: none; border-radius: var(–border-radius); cursor: pointer; font-size: 1rem; margin: 5px; transition: background-color 0.3s ease; } button:hover { background-color: #003366; } button.secondary { background-color: #6c757d; } button.secondary:hover { background-color: #5a6268; } #result { margin-top: 25px; padding: 20px; background-color: var(–primary-color); color: white; border-radius: var(–border-radius); text-align: center; box-shadow: var(–shadow); } #result h3 { color: white; margin-bottom: 15px; } #result .main-result-value { font-size: 2.5em; font-weight: bold; margin-bottom: 10px; } #result .intermediate-values, #result .key-assumptions { margin-top: 15px; text-align: left; font-size: 0.95em; border-top: 1px solid rgba(255, 255, 255, 0.3); padding-top: 10px; } #result .intermediate-values p, #result .key-assumptions p { margin-bottom: 8px; } #result .intermediate-values span, #result .key-assumptions span { font-weight: bold; min-width: 150px; display: inline-block; } .formula-explanation { font-size: 0.9em; color: #555; margin-top: 15px; padding: 10px; background-color: #e9ecef; border-radius: var(–border-radius); border: 1px solid #dee2e6; } table { width: 100%; border-collapse: collapse; margin-top: 20px; margin-bottom: 30px; box-shadow: var(–shadow); } th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; } thead th { background-color: var(–primary-color); color: white; font-weight: bold; } tbody tr:nth-child(even) { background-color: #f2f2f2; } caption { caption-side: top; font-weight: bold; color: var(–primary-color); margin-bottom: 10px; font-size: 1.1em; text-align: left; } #chartContainer { text-align: center; margin-top: 30px; margin-bottom: 30px; padding: 20px; background-color: var(–card-background); border-radius: var(–border-radius); box-shadow: var(–shadow); } #chartContainer canvas { max-width: 100%; height: auto; } .chart-caption { font-size: 0.9em; color: #666; margin-top: 10px; display: block; } .article-section { margin-top: 40px; margin-bottom: 40px; padding: 20px; background-color: var(–card-background); border-radius: var(–border-radius); box-shadow: var(–shadow); } .article-section h2, .article-section h3 { text-align: left; margin-top: 0; } .article-section p, .article-section ul, .article-section ol { margin-bottom: 15px; } .article-section li { margin-bottom: 8px; } .article-section strong { color: var(–primary-color); } .faq-item { margin-bottom: 15px; padding: 10px; border: 1px solid #e0e0e0; border-radius: var(–border-radius); } .faq-item .question { font-weight: bold; color: var(–primary-color); cursor: pointer; margin-bottom: 5px; } .faq-item .answer { display: none; /* Hidden by default */ font-size: 0.95em; padding-left: 10px; border-left: 2px solid var(–primary-color); } .internal-links-section ul { list-style: none; padding: 0; } .internal-links-section li { margin-bottom: 10px; } .internal-links-section a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .internal-links-section a:hover { text-decoration: underline; } .internal-links-section .explanation { font-size: 0.9em; color: #555; margin-left: 10px; }

Statsig Calculator

Estimate Feature Flag Impact and Experiment Performance

Statsig Impact & Experiment Estimator

Percentage of traffic to be included in the experiment.
The current conversion rate of your control group.
The smallest relative lift you want to be able to detect.
Confidence level (e.g., 95% means alpha of 0.05).
Probability of detecting a true effect (e.g., 80% means beta of 0.20).

Estimated Experiment Metrics

Required Sample Size (per variant):

Total Sample Size:

Minimum Detectible Lift:

Key Assumptions:

Traffic Allocation:

Baseline Conversion Rate:

Statistical Significance (Alpha):

Statistical Power (1-Beta):

Formula Used: This calculator estimates sample size based on the normal approximation to the binomial distribution. It considers traffic allocation, baseline conversion rate, minimum detectible effect (relative lift), desired statistical significance (alpha), and statistical power (1-beta). The formula for sample size per variant (n) for comparing two proportions is roughly:

n = [(Zα/2 + Zβ)2 * (p1(1-p1) + p2(1-p2))] / (p1 – p2)2

Where: Zα/2 is the Z-score for significance level, Zβ is the Z-score for power, p1 is the baseline conversion rate, and p2 is the target conversion rate (baseline * (1 + MDE)).

Sample Size vs. MDE

Impact of Minimum Detectible Effect on required Sample Size.
Experiment Performance Summary
Metric Control Group Variant Group
Conversion Rate (%)
Sample Size
Conversions
Observed Lift (%)
Results copied to clipboard!

What is a Statsig Calculator?

A Statsig calculator is a specialized tool designed to help product managers, data scientists, and engineers estimate the necessary parameters for running effective A/B tests or feature flag experiments using the Statsig platform. It bridges the gap between ideation and execution by providing data-driven insights into experiment design. Instead of launching an experiment blindly, a Statsig calculator allows you to pre-determine crucial metrics like the required sample size, expected lift, and the statistical power needed to confidently detect meaningful changes in user behavior or key performance indicators (KPIs).

Essentially, it's a forward-looking tool that helps you answer questions like: "How many users do I need to show this new feature to in order to be sure if it's better than the old one?" or "What's the smallest improvement I can reliably measure with my current traffic?" This proactive approach minimizes wasted resources, reduces the risk of inconclusive results, and maximizes the chances of making statistically sound product decisions.

Who Should Use a Statsig Calculator?

  • Product Managers: To validate new features, understand potential impact, and prioritize roadmap items based on data.
  • Data Scientists & Analysts: To design robust experiments, determine optimal sample sizes, and ensure statistical validity.
  • Engineers: To understand the implications of rolling out feature flags and experiments, and to estimate resource needs.
  • Marketing Teams: To test different campaign creatives, landing pages, or user flows to optimize conversion rates.
  • Anyone Implementing A/B Testing: To ensure experiments are well-designed and have a high probability of yielding actionable insights.

Common Misconceptions about Statsig Calculators

  • "It guarantees a successful experiment." Misconception: Calculators estimate requirements based on inputs. Actual results depend on the experiment's quality, execution, and real-world user behavior.
  • "More traffic always means better results." Misconception: While larger sample sizes increase power, the key is having *enough* relevant traffic for the desired MDE and significance. Over-sampling can be inefficient.
  • "It replaces statistical expertise." Misconception: Calculators simplify calculations, but understanding the underlying statistical principles (like p-values, confidence intervals, and bias) is still crucial for proper interpretation.
  • "Results are fixed once calculated." Misconception: The calculator provides estimates for a *specific* set of assumptions. If your traffic patterns change, or you decide to target a different MDE, the required sample size will change.

Statsig Calculator Formula and Mathematical Explanation

The core of a Statsig calculator often revolves around determining the required sample size for an A/B test or feature flag experiment. This is typically achieved using formulas derived from statistical principles for comparing two proportions (or means, depending on the metric). A common approach uses the normal approximation to the binomial distribution.

Step-by-Step Derivation (Sample Size for Proportions)

The goal is to find the sample size per variant (n) needed to detect a specific Minimum Detectible Effect (MDE) with a certain level of statistical significance (alpha) and statistical power (1 – beta).

Let:

  • p1 = Baseline Conversion Rate (Control Group)
  • p2 = Target Conversion Rate (Variant Group) = p1 * (1 + Relative MDE)
  • α = Significance Level (e.g., 0.05 for 95% significance)
  • β = Type II Error Rate (e.g., 0.20 for 80% power)
  • Zα/2 = Z-score corresponding to the significance level (for a two-tailed test)
  • Zβ = Z-score corresponding to the statistical power

The standard formula for sample size per group (n) when comparing two proportions is:

n = [ Zα/2 * sqrt(ppooled * (1 - ppooled) * 2) + Zβ * sqrt(p1*(1-p1) + p2*(1-p2)) ]² / (p1 - p2)²

A simplified, commonly used approximation (especially when p1 and p2 are close) focuses on the variance:

n ≈ ( (Zα/2 + Zβ)² * (p1*(1-p1) + p2*(1-p2)) ) / (p1 - p2)²

This formula balances the need for confidence (Zα/2) against the risk of missing a real effect (Zβ), considering the inherent variability in the conversion rates (p1*(1-p1) and p2*(1-p2)), and the size of the effect we want to detect ((p1 - p2)²).

Variable Explanations

  • Traffic Allocation (%): The proportion of your total user base that will be exposed to the experiment (either control or variant). Higher allocation allows for faster results.
  • Baseline Conversion Rate (%): The existing conversion rate of the metric you are trying to improve. This is a critical input for calculating expected outcomes and required sample sizes.
  • Minimum Detectible Effect (MDE) (%): The smallest *relative* change (lift or decrease) in your target metric that you want your experiment to be sensitive enough to detect. A smaller MDE requires a larger sample size.
  • Statistical Significance (Alpha) (%): The probability of rejecting the null hypothesis when it is actually true (a Type I error, or false positive). Commonly set at 95% confidence (α = 0.05). Lower alpha requires larger sample size.
  • Statistical Power (1-Beta) (%): The probability of correctly rejecting the null hypothesis when it is false (i.e., detecting a real effect if it exists). Commonly set at 80% (β = 0.20). Higher power requires larger sample size.

Variables Table

Statsig Calculator Variables
Variable Meaning Unit Typical Range
Traffic Allocation Percentage of users exposed to the experiment. % 1-100%
Baseline Conversion Rate Current conversion rate of the control group. % 0.1% – 50%+ (highly variable by industry/metric)
Minimum Detectible Effect (MDE) Smallest relative change to detect. % 0.5% – 10%+
Statistical Significance (Alpha) Probability of false positive (Type I error). % 90% – 99% (commonly 95%)
Statistical Power (1-Beta) Probability of detecting a true effect (avoiding Type II error). % 70% – 95% (commonly 80%)
Sample Size (per variant) Number of users needed in each group (control/variant). Users Thousands to Millions (highly dependent on other factors)
Total Sample Size Total users needed for the entire experiment. Users 2 * Sample Size (per variant)
Target Conversion Rate Expected conversion rate in the variant group. % Calculated: Baseline * (1 + Relative MDE)

Practical Examples (Real-World Use Cases)

Example 1: Optimizing a Sign-up Button Color

A SaaS company wants to test a new 'Sign Up' button color (e.g., changing from blue to green) to increase user registrations.

  • Current Sign-up Rate (Baseline Conversion Rate): 3%
  • Desired Improvement (MDE): They want to detect at least a 10% relative increase (i.e., reach 3.3% conversion).
  • Traffic Allocation: They can allocate 50% of their website traffic to this experiment.
  • Statistical Significance: 95% (Alpha = 0.05)
  • Statistical Power: 80% (Beta = 0.20)

Using the Statsig calculator with these inputs:

  • Input Values: Traffic Allocation = 50%, Baseline CR = 3%, MDE = 10%, Significance = 95%, Power = 80%.
  • Calculator Output (Estimated):
    • Required Sample Size per Variant: ~10,600 users
    • Total Sample Size: ~21,200 users
    • Target Conversion Rate: 3.3%

Interpretation: To be reasonably confident (95% chance of being correct) that a 10% increase in sign-ups is real and not just random chance, and have an 80% chance of detecting it if it occurs, they need to expose approximately 10,600 users to the green button and 10,600 users to the blue button. If their average daily unique visitors are 1,000, this experiment would take about 21 days to complete (21,200 users / 1,000 users/day).

Example 2: Testing a New Checkout Flow

An e-commerce platform is considering a redesigned checkout process to reduce cart abandonment.

  • Baseline Cart Abandonment Rate: 40% (This means a 'Conversion Rate' of 60% to complete checkout)
  • Desired Reduction in Abandonment (MDE): They want to detect a 5% *absolute* reduction in abandonment (i.e., from 40% down to 35%), which is a relative reduction of 12.5%. The calculator typically uses relative MDE for conversion rates. So, a 12.5% relative reduction on a 60% completion rate means the new rate would need to be 60% * (1 – 0.125) = 52.5% completion rate. MDE in % terms = (60-52.5)/60 = 12.5%.
  • Traffic Allocation: They can route 100% of traffic through the experiment.
  • Statistical Significance: 95% (Alpha = 0.05)
  • Statistical Power: 90% (Beta = 0.10) – They want higher confidence due to the significant change.

Using the Statsig calculator:

  • Input Values: Traffic Allocation = 100%, Baseline CR = 60%, MDE = 12.5% (relative reduction), Significance = 95%, Power = 90%.
  • Calculator Output (Estimated):
    • Required Sample Size per Variant: ~36,500 users
    • Total Sample Size: ~73,000 users
    • Target Conversion Rate: 52.5%

Interpretation: Testing a significant change like a checkout flow requires a substantial number of users, especially when aiming for high power. They need over 73,000 users to participate in the experiment to reliably detect if the new flow reduces abandonment by the targeted amount. The calculator helps justify the time and user volume needed for such a critical test.

How to Use This Statsig Calculator

This Statsig calculator is designed to be intuitive and provide actionable insights for experiment design. Follow these steps to get the most out of it:

  1. Define Your Metric: Clearly identify the key performance indicator (KPI) you want to impact (e.g., conversion rate, click-through rate, sign-up rate, retention rate). This will be your 'Baseline Conversion Rate'.
  2. Set Realistic Expectations (MDE): Determine the smallest *relative* improvement or change you consider meaningful for your business. A smaller MDE requires a larger sample size and longer experiment duration. Start with a reasonable value (e.g., 5-10% relative lift) and adjust if necessary.
  3. Allocate Traffic: Decide what percentage of your user base can be included in the experiment. A higher percentage means faster data collection. Consider if you need to run the experiment year-round or during specific periods.
  4. Choose Statistical Confidence Levels:
    • Significance (Alpha): Typically set at 95%. This means you accept a 5% chance of a false positive (concluding there's an effect when there isn't).
    • Power (1-Beta): Typically set at 80%. This means you have an 80% chance of detecting a real effect of your chosen MDE size if it truly exists. Increasing power requires a larger sample size.
  5. Input Values: Enter the determined values into the corresponding fields in the calculator. Ensure you use percentages correctly (e.g., 5% should be entered as 5, not 0.05, unless specified by the helper text).
  6. Click 'Calculate': The calculator will instantly provide:
    • Primary Result: The minimum required sample size per variant.
    • Intermediate Values: Total sample size needed, and the target conversion rate you aim to achieve.
    • Key Assumptions: A summary of the inputs you used.
  7. Interpret the Results:
    • Sample Size: This is your primary target. Work backward to estimate the duration needed based on your daily/weekly traffic.
    • Total Sample Size: Double the per-variant size to get the total users required for the experiment.
    • Target Conversion Rate: This is the performance level your variant needs to hit to be considered a success under your chosen MDE.
  8. Use the 'Copy Results' Button: Easily copy all calculated metrics and assumptions for documentation or sharing with your team.
  9. Use the 'Reset' Button: Start over with default or previous values if you need to adjust parameters.

Decision-Making Guidance

  • Is the required sample size feasible? If the calculated sample size is extremely large, consider if your traffic can support it within a reasonable timeframe. You might need to increase your MDE or accept lower power/significance.
  • Is the MDE realistic? Aiming for tiny improvements with limited traffic might lead to inconclusive results. Ensure your MDE aligns with business goals and expected impact.
  • Does the target conversion rate make sense? Compare the target CR with your baseline. Is the expected uplift ambitious yet achievable?

Key Factors That Affect Statsig Calculator Results

Several factors significantly influence the outputs of a Statsig calculator, particularly the required sample size. Understanding these can help you refine your experiment design and interpret results more effectively.

  1. Baseline Conversion Rate (BCR): This is arguably the most impactful input.
    • Effect: Lower BCRs generally require larger sample sizes to detect the same *relative* lift. For example, detecting a 10% relative lift from 1% to 1.1% requires a much larger sample than detecting a 10% relative lift from 10% to 11%.
    • Reasoning: The absolute difference between the groups is smaller at lower rates, meaning more data is needed to confidently distinguish the signal from noise.
  2. Minimum Detectible Effect (MDE): The size of the change you want to detect.
    • Effect: Smaller MDEs require significantly larger sample sizes.
    • Reasoning: Detecting subtle improvements is inherently harder and requires more data points to be sure the observed difference isn't random fluctuation. If you only care about large impacts, you need less data.
  3. Statistical Significance (Alpha): The acceptable risk of a false positive.
    • Effect: Lowering the significance level (e.g., moving from 95% to 99% confidence) increases the required sample size.
    • Reasoning: To be *more* certain that a result is not a fluke, you need to see a stronger signal relative to the noise, which demands more data.
  4. Statistical Power (1-Beta): The probability of detecting a true effect.
    • Effect: Increasing statistical power (e.g., from 80% to 90%) increases the required sample size.
    • Reasoning: Having a higher chance of finding a real effect means you need to be more sensitive to smaller signals, necessitating more data.
  5. Traffic Allocation: The percentage of your user base exposed to the experiment.
    • Effect: While it doesn't change the *per-variant* sample size calculation, it dramatically affects the *duration* of the experiment. Higher allocation means faster completion.
    • Reasoning: The calculation determines how many users need to *see* the variation. If only a fraction of your users are exposed daily, it takes longer to reach the target number.
  6. Nature of the Metric (Variance): While the calculator often uses proportions, the underlying variance matters.
    • Effect: Metrics with higher inherent variance (e.g., revenue per user, which can fluctuate widely) often require larger sample sizes than binary metrics (e.g., click/no-click).
    • Reasoning: High variance means individual data points are less predictable, making it harder to discern a consistent effect of the change across the population.
  7. Experiment Duration: Related to traffic allocation but also seasonality or business cycles.
    • Effect: Running experiments for too short a duration (less than a full business cycle, e.g., a week) can lead to inaccurate results due to temporal biases.
    • Reasoning: User behavior can vary significantly based on the day of the week, time of year, or specific promotions. A sufficient duration helps average out these effects.

Frequently Asked Questions (FAQ)

What is the difference between relative and absolute MDE?
Relative MDE is expressed as a percentage change compared to the baseline (e.g., a 10% relative lift on a 5% baseline means the target is 5.5%). Absolute MDE is a direct difference (e.g., reducing abandonment from 40% to 35% is a 5% absolute difference). Most sample size calculators, including this one, are designed for relative MDE on conversion rates.
Can I use this calculator for metrics other than conversion rates?
This specific calculator is optimized for conversion rates (proportions). For metrics like average order value or user engagement time (continuous variables), you would need a calculator designed for comparing means, which uses a different statistical formula involving standard deviation. Statsig itself supports various metric types.
What does it mean if my experiment result is not statistically significant?
It means that the observed difference between your control and variant groups could plausibly be due to random chance alone. You cannot confidently conclude that your change had a real impact. It doesn't necessarily mean the change had *no* effect, just that you didn't gather enough evidence to prove it did.
How long should I run my A/B test?
Run your test until you reach the required sample size calculated by the tool, AND ensure it covers at least one full business cycle (typically a week) to account for daily variations in user behavior. Avoid running tests for too short a period or stopping them prematurely just because you see a seemingly significant result early on.
What happens if I change my feature flag after the experiment?
If you decide to roll out the winning variant, you would typically configure your feature flag in Statsig to serve that variant to the relevant user segment. If you decide against the change, you revert the flag. The calculator helps you make the *decision* based on data before committing to a change.
Can I run multiple experiments at once?
Yes, but be cautious. Running multiple experiments simultaneously can lead to interference if they affect the same user journey or metrics. Ensure experiments are independent or consider statistical methods to account for potential interactions if they overlap significantly. Always check the sample size requirements for each.
What is the "p-value" and how does it relate to significance?
The p-value is the probability of observing a test statistic as extreme as, or more extreme than, the one actually observed, assuming the null hypothesis is true. Statistical significance (e.g., 95%) means your p-value must be less than your alpha level (e.g., p < 0.05) to reject the null hypothesis and conclude there's a statistically significant effect.
Does the calculator account for network latency or server load?
This calculator focuses on the statistical requirements for experiment design. It does not directly model technical performance metrics like latency or server load. While experiment results might indirectly reflect performance impacts (e.g., slower loading leads to lower conversion), you'd need separate performance testing and monitoring tools for those specific aspects.

Related Tools and Internal Resources

© Your Company Name. All rights reserved.
var chartInstance = null; // Global variable to hold the chart instance function getChartZScore(percentage) { var zScores = { 50: 0.00, 60: 0.25, 70: 0.52, 80: 0.84, 90: 1.28, 95: 1.645, 99: 2.326 }; var key = Math.round(percentage); return zScores[key] || 1.96; // Default to 95% confidence Z-score if not found } function calculateStatsig() { var trafficAllocation = parseFloat(document.getElementById("trafficAllocation").value); var baselineConversionRate = parseFloat(document.getElementById("baselineConversionRate").value); var minimumDetectibleEffect = parseFloat(document.getElementById("minimumDetectibleEffect").value); var statisticalSignificance = parseFloat(document.getElementById("statisticalSignificance").value); var statisticalPower = parseFloat(document.getElementById("statisticalPower").value); var errors = false; var errMessages = { trafficAllocationError: "", baselineConversionRateError: "", minimumDetectibleEffectError: "", statisticalSignificanceError: "", statisticalPowerError: "" }; // Validation if (isNaN(trafficAllocation) || trafficAllocation 100) { errMessages.trafficAllocationError = "Please enter a value between 1 and 100."; errors = true; } if (isNaN(baselineConversionRate) || baselineConversionRate = 100) { errMessages.baselineConversionRateError = "Please enter a value between 0 and 99."; errors = true; } if (isNaN(minimumDetectibleEffect) || minimumDetectibleEffect <= 0) { errMessages.minimumDetectibleEffectError = "Minimum Detectible Effect must be positive."; errors = true; } if (isNaN(statisticalSignificance) || statisticalSignificance = 100) { errMessages.statisticalSignificanceError = "Please enter a value between 1 and 99."; errors = true; } if (isNaN(statisticalPower) || statisticalPower = 100) { errMessages.statisticalPowerError = "Please enter a value between 1 and 99."; errors = true; } // Display errors for (var id in errMessages) { var errorElement = document.getElementById(id); if (errMessages[id]) { errorElement.textContent = errMessages[id]; errorElement.style.display = "block"; } else { errorElement.textContent = ""; errorElement.style.display = "none"; } } if (errors) { // Clear previous results if there are errors document.getElementById("primaryResult").textContent = "–"; document.getElementById("sampleSizePerVariant").textContent = "–"; document.getElementById("totalSampleSize").textContent = "–"; document.getElementById("actualMdel").textContent = "–"; document.getElementById("crControl").textContent = "–"; document.getElementById("crVariant").textContent = "–"; document.getElementById("ssControl").textContent = "–"; document.getElementById("ssVariant").textContent = "–"; document.getElementById("convControl").textContent = "–"; document.getElementById("convVariant").textContent = "–"; document.getElementById("observedLift").textContent = "–"; document.getElementById("assumptionTraffic").textContent = "–"; document.getElementById("assumptionBaselineCR").textContent = "–"; document.getElementById("assumptionAlpha").textContent = "–"; document.getElementById("assumptionPower").textContent = "–"; return; } // Convert percentages to proportions var p1 = baselineConversionRate / 100; var mdeRelative = minimumDetectibleEffect / 100; var alpha = (100 – statisticalSignificance) / 100; var beta = (100 – statisticalPower) / 100; var power = 1 – beta; // Z-scores var Z_alpha_half = getChartZScore(statisticalSignificance); // Z-score for significance var Z_beta = getChartZScore(statisticalPower); // Z-score for power // Calculate target conversion rate (p2) var p2 = p1 * (1 + mdeRelative); // Ensure p2 is not greater than 1 or less than 0 if (p2 > 1) p2 = 1; if (p2 1e-9) { // Avoid division by zero sampleSizePerVariant = numerator / denominator; } else { sampleSizePerVariant = Infinity; // If p1 == p2, sample size is infinite } // Calculate total sample size var totalSampleSize = sampleSizePerVariant * (100 / trafficAllocation); sampleSizePerVariant = sampleSizePerVariant * (100 / trafficAllocation); // Adjusted for traffic allocation // Round results and format var roundedSampleSizePerVariant = Math.round(sampleSizePerVariant); var roundedTotalSampleSize = Math.round(totalSampleSize); var formattedActualMDE = (p1 > 0) ? ((p2 – p1) / p1 * 100).toFixed(2) : "N/A"; var formattedP1 = (p1 * 100).toFixed(2); var formattedP2 = (p2 * 100).toFixed(2); // Update results display document.getElementById("primaryResult").textContent = roundedSampleSizePerVariant.toLocaleString(); document.getElementById("sampleSizePerVariant").textContent = roundedSampleSizePerVariant.toLocaleString(); document.getElementById("totalSampleSize").textContent = roundedTotalSampleSize.toLocaleString(); document.getElementById("actualMdel").textContent = formattedActualMDE + "%"; // Update assumptions display document.getElementById("assumptionTraffic").textContent = trafficAllocation.toFixed(0) + "%"; document.getElementById("assumptionBaselineCR").textContent = baselineConversionRate.toFixed(2) + "%"; document.getElementById("assumptionAlpha").textContent = statisticalSignificance.toFixed(0) + "%"; document.getElementById("assumptionPower").textContent = statisticalPower.toFixed(0) + "%"; // Update table document.getElementById("crControl").textContent = formattedP1 + "%"; document.getElementById("crVariant").textContent = formattedP2 + "%"; document.getElementById("ssControl").textContent = roundedSampleSizePerVariant.toLocaleString(); document.getElementById("ssVariant").textContent = roundedSampleSizePerVariant.toLocaleString(); document.getElementById("convControl").textContent = Math.round(p1 * roundedSampleSizePerVariant).toLocaleString(); document.getElementById("convVariant").textContent = Math.round(p2 * roundedSampleSizePerVariant).toLocaleString(); document.getElementById("observedLift").textContent = formattedActualMDE + "%"; updateChart([ { mde: 1, targetCR: p1 * 1.01, sampleSize: calculateSampleSizeForMDE(p1, 1 / 100, Z_alpha_half, Z_beta, alpha, beta, trafficAllocation) }, { mde: 2, targetCR: p1 * 1.02, sampleSize: calculateSampleSizeForMDE(p1, 2 / 100, Z_alpha_half, Z_beta, alpha, beta, trafficAllocation) }, { mde: 5, targetCR: p1 * 1.05, sampleSize: calculateSampleSizeForMDE(p1, 5 / 100, Z_alpha_half, Z_beta, alpha, beta, trafficAllocation) }, { mde: 10, targetCR: p1 * 1.10, sampleSize: calculateSampleSizeForMDE(p1, 10 / 100, Z_alpha_half, Z_beta, alpha, beta, trafficAllocation) }, { mde: 15, targetCR: p1 * 1.15, sampleSize: calculateSampleSizeForMDE(p1, 15 / 100, Z_alpha_half, Z_beta, alpha, beta, trafficAllocation) }, { mde: 20, targetCR: p1 * 1.20, sampleSize: calculateSampleSizeForMDE(p1, 20 / 100, Z_alpha_half, Z_beta, alpha, beta, trafficAllocation) } ]); } // Helper function to calculate sample size for a specific MDE function calculateSampleSizeForMDE(p1, mdeRelative, Z_alpha_half, Z_beta, alpha, beta, trafficAllocation) { var p2 = p1 * (1 + mdeRelative); if (p2 > 1) p2 = 1; if (p2 1e-9) { sampleSizePerVariant = numerator / denominator; } else { sampleSizePerVariant = Infinity; } var adjustedSampleSize = sampleSizePerVariant * (100 / trafficAllocation); return Math.round(adjustedSampleSize); } function updateChart(data) { var ctx = document.getElementById('sampleSizeChart').getContext('2d'); // Destroy previous chart instance if it exists if (chartInstance) { chartInstance.destroy(); } chartInstance = new Chart(ctx, { type: 'line', data: { labels: data.map(item => item.mde + "% MDE"), datasets: [{ label: 'Required Sample Size (per variant)', data: data.map(item => item.sampleSize), borderColor: 'rgb(0, 74, 153)', // Primary color backgroundColor: 'rgba(0, 74, 153, 0.1)', fill: true, tension: 0.1 }] }, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, title: { display: true, text: 'Sample Size (Users)' } }, x: { title: { display: true, text: 'Minimum Detectible Effect (Relative)' } } }, plugins: { tooltip: { callbacks: { label: function(context) { var label = context.dataset.label || "; if (label) { label += ': '; } if (context.parsed.y !== null) { label += context.parsed.y.toLocaleString() + ' users'; } return label; } } } } } }); } function copyResults() { var mainResult = document.getElementById("primaryResult").textContent; var sampleSizePerVariant = document.getElementById("sampleSizePerVariant").textContent; var totalSampleSize = document.getElementById("totalSampleSize").textContent; var actualMDE = document.getElementById("actualMdel").textContent; var assumptionTraffic = document.getElementById("assumptionTraffic").textContent; var assumptionBaselineCR = document.getElementById("assumptionBaselineCR").textContent; var assumptionAlpha = document.getElementById("assumptionAlpha").textContent; var assumptionPower = document.getElementById("assumptionPower").textContent; var tableControlCR = document.getElementById("crControl").textContent; var tableVariantCR = document.getElementById("crVariant").textContent; var tableObservedLift = document.getElementById("observedLift").textContent; var formula = document.querySelector(".formula-explanation strong").textContent + " " + document.querySelector(".formula-explanation").textContent.replace("Formula Used:", "").trim(); var textToCopy = "Statsig Calculator Results:\n\n" + "Primary Result (Sample Size per Variant): " + mainResult + "\n" + "Total Sample Size Needed: " + totalSampleSize + "\n" + "Minimum Detectible Lift: " + actualMDE + "\n\n" + "Key Assumptions:\n" + " Traffic Allocation: " + assumptionTraffic + "\n" + " Baseline Conversion Rate: " + assumptionBaselineCR + "\n" + " Statistical Significance (Alpha): " + assumptionAlpha + "\n" + " Statistical Power (1-Beta): " + assumptionPower + "\n\n" + "Experiment Metrics:\n" + " Control Conversion Rate: " + tableControlCR + "\n" + " Variant Conversion Rate: " + tableVariantCR + "\n" + " Observed Lift: " + tableObservedLift + "\n\n" + "Formula Used:\n" + formula; navigator.clipboard.writeText(textToCopy).then(function() { var notification = document.getElementById("copiedNotification"); notification.style.display = "block"; setTimeout(function() { notification.style.display = "none"; }, 3000); }).catch(function(err) { console.error('Failed to copy: ', err); alert('Failed to copy results. Please copy manually.'); }); } function resetCalculator() { document.getElementById("trafficAllocation").value = "50"; document.getElementById("baselineConversionRate").value = "5"; document.getElementById("minimumDetectibleEffect").value = "10"; document.getElementById("statisticalSignificance").value = "95"; document.getElementById("statisticalPower").value = "80"; // Clear errors document.getElementById("trafficAllocationError").textContent = ""; document.getElementById("trafficAllocationError").style.display = "none"; document.getElementById("baselineConversionRateError").textContent = ""; document.getElementById("baselineConversionRateError").style.display = "none"; document.getElementById("minimumDetectibleEffectError").textContent = ""; document.getElementById("minimumDetectibleEffectError").style.display = "none"; document.getElementById("statisticalSignificanceError").textContent = ""; document.getElementById("statisticalSignificanceError").style.display = "none"; document.getElementById("statisticalPowerError").textContent = ""; document.getElementById("statisticalPowerError").style.display = "none"; calculateStatsig(); // Recalculate with defaults } // Initialize year in footer document.getElementById('currentYear').textContent = new Date().getFullYear(); // Initialize calculator on page load document.addEventListener('DOMContentLoaded', function() { calculateStatsig(); // Add event listeners for real-time updates var inputs = document.querySelectorAll('.loan-calc-container input[type="number"]'); inputs.forEach(function(input) { input.addEventListener('input', calculateStatsig); // Add blur listener for validation feedback input.addEventListener('blur', function() { validateInput(input); }); }); // Initialize chart updateChart([]); }); // Basic inline validation on input change function validateInput(input) { var value = parseFloat(input.value); var id = input.id; var errorElement = document.getElementById(id + "Error"); var isValid = true; var message = ""; if (isNaN(value)) { message = "Please enter a valid number."; isValid = false; } else { if (id === "trafficAllocation" && (value 100)) { message = "Value must be between 1 and 100."; isValid = false; } else if (id === "baselineConversionRate" && (value = 100)) { message = "Value must be between 0 and 99."; isValid = false; } else if (id === "minimumDetectibleEffect" && value <= 0) { message = "Value must be positive."; isValid = false; } else if ((id === "statisticalSignificance" || id === "statisticalPower") && (value = 100)) { message = "Value must be between 1 and 99."; isValid = false; } } if (!isValid) { errorElement.textContent = message; errorElement.style.display = "block"; } else { errorElement.textContent = ""; errorElement.style.display = "none"; } return isValid; } // Need Chart.js for the chart – assuming it's available globally // If not, you'd need to include the Chart.js library via a CDN or local file. // For this example, we'll assume Chart.js is included. // Example CDN: // Make sure the Chart.js script tag is placed BEFORE this script tag.

Leave a Comment