Modeling society with statistical mechanics: an application to cultural contact and immigration