def combine_stats(old_n, new_n, old_mean, new_mean, old_v, new_v):
    """Combine two mean and variance measurements.

    Args:
        old_n, new_n (int): Old and new number of samples.
        old_mean, new_mean (float): Old and new mean.
        old_v, new_v (float): Old and new variance.

    Returns:
        total_n (int): Combined number of samples.
        combined_mean (float): Combined mean.
        combined_v (float): Combined variance.

    """
    total_n = old_n + new_n
    combined_mean = (old_n / total_n) * old_mean + (new_n / total_n) * new_mean
    combined_v = (
        (old_n / total_n) * old_v
        + (new_n / total_n) * new_v
        + (old_n * new_n / (total_n ** 2)) * ((old_mean - new_mean) ** 2)
    )
    return total_n, combined_mean, combined_v