We present a statistical comparison of the mass ratio distribution of companions, as observed in different multiplicity surveys, to the most recent estimate of the single-object mass function. The main goal of our analysis is to test whether or not the observed companion mass ratio distribution (CMRD) as a function of primary star mass and star formation environment is consistent with having been drawn from the field star initial mass function (IMF). We consider samples of companions for M dwarfs, solar-type stars, and intermediate-mass stars, both in the field as well as clusters or associations, and compare them with populations of binaries generated by random pairing from the assumed IMF for a fixed primary mass. With regard to the field we can reject the hypothesis that the CMRD was drawn from the IMF for different primary mass ranges: the observed CMRDs show a larger number of equal-mass systems than predicted by the IMF. This is in agreement with fragmentation theories of binary formation. For the open clusters α Persei and the Pleiades we also reject the IMF random-pairing hypothesis. Concerning young star-forming regions, currently we can rule out a connection between the CMRD and the field IMF in Taurus but not in Chamaeleon I. Larger and different samples are needed to better constrain the result as a function of the environment. We also consider other companion mass functions and we compare them with observations. Moreover the CMRD both in the field and clusters or associations appears to be independent of separation in the range covered by the observations. Combining therefore the CMRDs of M (1-2400 AU) and G (28-1590 AU) primaries in the field and intermediate-mass primary binaries in Sco OB2 (29-1612 AU) for mass ratios, q = M 2 /M 1 , from 0.2 to 1, we find that the best chi-square fit follows a power law dN/dq ∝ q β , with β = −0.50 ± 0.29, consistent with previous results. Finally, we note that the Kolmogorov-Smirnov test gives a ∼1% probability of the observed CMRD in the Pleiades and Taurus being consistent with that observed for solar-type primaries in the field over comparable primary mass range. This highlights the value of using CMRDs to understand which star formation events contribute most to the field.