How to calculate the sum of two normal distributions


I have a value type that represents a gaussian distribution:

struct Gauss {
    double mean;
    double variance;

I would like to perform an integral over a series of these values:

Gauss eulerIntegrate(double dt, Gauss iv, Gauss[] values) {
    Gauss r = iv;
    foreach (Gauss v in values) {
        r += v*dt;
    return r;

My question is how to implement addition for these normal distributions.

The multiplication by a scalar (dt) seemed simple enough. But it wasn't simple! Thanks FOOSHNICK for the help:

public static Gauss operator * (Gauss g, double d) {
    return new Gauss(g.mean * d, g.variance * d * d);

However, addition eludes me. I assume I can just add the means; it's the variance that's causing me trouble. Either of these definitions seems "logical" to me.

public static Gauss operator + (Gauss a, Gauss b) {
    double mean = a.mean + b.mean;
    // Is it this? (Yes, it is!)
    return new Gauss(mean, a.variance + b.variance);        
    // Or this? (nope)
    //return new Gauss(mean, Math.Max(a.variance, b.variance));
    // Or how about this? (nope)
    //return new Gauss(mean, (a.variance + b.variance)/2);

Can anyone help define a statistically correct – or at least "reasonable" – version of the + operator?

I suppose I could switch the code to use interval arithmetic instead, but I was hoping to stay in the world of prob and stats.

Best Answer

The sum of two normal distributions is itself a normal distribution:

N(mean1, variance1) + N(mean2, variance2) ~ N(mean1 + mean2, variance1 + variance2)

This is all on wikipedia page.

Be careful that these really are variances and not standard deviations.

// X + Y
public static Gauss operator + (Gauss a, Gauss b) {
    //NOTE: this is valid if X,Y are independent normal random variables
    return new Gauss(a.mean + b.mean, a.variance + b.variance);

// X*b
public static Gauss operator * (Gauss a, double b) {
    return new Gauss(a.mean*b, a.variance*b*b);