The virial equation is especially useful to describe the causes of non-ideality at a molecular level (very few gases are mono-atomic) as it is derived directly from statistical mechanics:
Where the coefficients in the numerator are known as virial coefficients and are functions of temperature.
The virial coefficients account for interactions between successively larger groups of molecules. For example,  accounts for interactions between pairs,  for interactions between three gas molecules, and so on. Because interactions between large numbers of molecules are rare, the virial equation is usually truncated after the third term.
When this truncation is assumed, the compressibility factor is linked to the intermolecular-force potential φ by:
The Real gas article features more theoretical methods to compute compressibility factors.