# Sum of random variables?

Is it possible to observe the sum of a set of random variables, and if so, how would it be done? I know I can use `tt.sum` in a variable’s properties, like this for example:

``````pm.Normal('Output_{0}_{1}_'.format(i,k),mu=tt.sum(list(compress(factor_mu,weights))),sd=tt.sum(list(compress(factor_sigma,weights))))
``````

But let’s say I have a population and I observe the mean, instead of actual individual measures. I know I can read the mean out of a trace as follows:

``````pm.Deterministic(output_mu_name,tt.sum(list(compress(factor_mu,weights))))
``````

But how could I add an observation of the value of mu? I know I can’t observe an arbitrary `Deterministic` RV, but it seems like I should be able to observe a sum?

Oh, yes, if it helps, I would be observing both the mean and the standard deviation of these populations.

There is not easy way to do it. If all the elements are in exponential family there might be a close form solution, otherwise usually the likelihood of the sum of some random variables could not be trivially derived.
In your case I guess you can model each component mean with a gaussian, and their sum would also be a gaussian. Check Wikipedia of sum of gaussian should give you some direction.

Yes, I think that would work for the component means, which I’m modeling as Gaussian, as you suggest. I’m less sure about the component sigmas, since they are all modeled as Gammas, and I think the gamma summation is more complex. I’ll do some research and post back here, in case anyone else is interested.

1 Like