My first question is, what is the most preferable formation density for infantry in a typical battle scenario in the game?
My thoughts are that if the formation is too tight it can be easily surrounded, especially if it is in a square. Also, it cannot provide as much area denial or defense for your skirmishers. For example if your infantry line is shorter than your skirmisher line, enemies (notably cavalry) will pour into them and they will therefore be left rather vulnerable if a formation is too tight. Furthermore, a tight formation for many factions whose infantry are equipped with precursors may also be a disadvantage because it gives less soldiers a line of sight to throw their missiles at the enemy. Also, a tight formation makes it easier for missile units to score hits on them.
However for greek factions, a tight formation is very advantageous because it allows hoplites to support each other and they do not need to worry about throwing missiles into the enemy ranks. Also, for phalngites a tight formation could also be to their advantage because it stops enemies from being able to manifest themselves into your formation and easily kill long spear wielding troops, however one may argue that a tighter formation of phalangites would disable their ability of being able to support each other with spears because the reach is too great, so everyone will be too close to the enemy. Here is an image that displays this theory:
In addition, a very dense formation will soften a cavalry charge and make it almost impossible for them to kill anyone with a head-on charge.
Perhaps this question is too vague because it will really vary between different factions and the circumstances of a battle, for example if one is fighting and they seem to have a skirmishing force which outweighs their infantry, it may be more effective to spread your troops out to protect the skirmishers. For hoplites, a tight formation is probably more effective than a looser one because it allows troops to assist one another. As a Roman, again, there are positives and negatives to either deployment; a tight formation disables the use of pila being used by a portion of soldiers but with their shorter weapons, a denser deployment will let troops to use their weapons more effectively because everyone is closer to the front line.