The honest answer is that there is no formula for picking colors... you simply need to develop a sensitivity to it... but there are a few tricks that will get you close.
The majority of the colors in your example share the same tonal value while having different chroma values (or different hues if you prefer).
If you take that image into photoshop and convert it to greyscale you will find that *most* of the colors are converted to the same grey value. So, while they are all different colors, they are all in the same range of light and dark.
Because the different colors have the same tone value, they look like a family.
The easiest way to choose colors like this is to work in HSB (or HSV) mode in your favorite software. HSB stands for Hue, Saturation and Brightness. Unlike RGB and CMYK, HSB allows you to select a specific hue and then define how saturated (read: how much pigment is in it) and how light or dark it is.
Think of it this way: the first slider selects a color like red, and the two other sliders define what KIND of red you want... a flat or saturated red, a pink or dark red, etc.
When it comes to picking color families, HSV simplifies things because you can select the color settings you like and then move the Hue slider around the color spectrum choosing different colors... because all those colors share the same brightness and saturation values, the colors will be close to working as a "family". Some tweaking will be necessary, but it will get you close.