“Please don’t’ listen to the Brexiteers’ madness,” Airbus chief executive Tom Enders said on Thursday, while warning there was no guarantee the company would retain its base in Britain after March 29.

That the Brexit debate has been irrational is also a common theme in the Foreign press. “Isle of Madness”, trumpeted Der Spiegel in November. A few weeks earlier Canada's Globe and Mail had declared: “A self-destructive madness grips the UK".

And it is not just Brexiteers who stand accused. Remainers and campaigners for a People’s Vote or a second referendum have been branded deluded and dangerous enemies of the people.

But if we have all taken leave of our senses, there may be a psychological explanation. And while research carried out in Scotland and published this week gives fresh insight into this collective act of self-harm, the original theories date back to the work of a Scottish journalist, poet and songwriter born 200 years ago and raised in an orphanage for Scots children in London.

Charles Mackay is best remembered for his 1841 book Extraordinary Popular Delusions and the Madness of Crowds, which is still cited today as one of the earliest studies of how large numbers of people can participate in very bad decisions.

So what is the Madness of Crowds?

Mackay’s three-volume work highlighted examples of mass hysteria, from economic booms and subsequent busts such as the South Sea Bubble to witch hunts and the popular expectation that alchemists might one day turn base metals into gold. It looked to explain why large populations or communities sometimes embrace irrational beliefs and ideas, often in defiance of a blindingly obvious reality.

“We find that whole communities suddenly fix their minds upon one object and go mad in its pursuit,” Mackay wrote. “Millions of people become simultaneously impressed with one delusion and run after it, till their attention is caught by some new folly more captivating than the first.”

The theory has been much studied, including in a more recent work part inspired by Mackay, US journalist James Surowiecki’s 2004 book The Wisdom of Crowds, Why the Many are Smarter than the Few. Surowiecki argued that through sharing information, groups can make better collective decisions than any individual within them could.

But they can’t both be right?

The problem is there are good examples to support both theories, but we don’t know how or why "collective wisdom” sometimes works and sometimes goes badly wrong.

That is why new research carried out at St Andrews University is so timely. It explains not only how collective madness can grip a population, leading to bad decisions, but also why the more complex the task, the more likely humans will act like animals, resorting to mimicry and "groupthink".

According to lead author Wataru Toyokawa, postdoctoral research fellow at St Andrews University, the natural world can help explain a puzzle which has long troubled social scientists. "Many people have studied how individuals become more stupid when they behave collectively,” he says. “Seeking the opinion of others is normally beneficial, if information gathering is good. We rely on that for the democratic process," he says. "But it is a double-edged sword. Copying can be healthy but if all the people are copying each other the system collapses."

Along with Professor Kevin Laland of St Andrews' School of Biology and PhD student Andrew Whalen, Toyokawa used an online experiment and population dynamics to explore the point at which the benefits of sharing information and collaborating to find solutions can tip over into a phenomenon known to psychologists as "maladaptive herding".

Participants were given a variety of tasks and researchers discovered that the larger and more complex the task, the more likely people were to copy those around them, leading to poor decisions.

"With Brexit the task is very difficult because each individual has different preferences, making it hard to reach consensus. In such a political situation, the danger is bad ideas can flourish," Toyokawa says.

What’s happening to decision-making?

Over the years, research into Mackay's ideas has consolidated around an understanding that conformity has a big influence on decision making. So if enough people believe leaving the EU will lead to a £350m dividend for the NHS, or reduce overall migration rather than just the numbers coming from EU countries, others are likely to embrace the same ideas more readily, even if they are irrational. This applies especially if the suspect ideas chime with their own views or prejudices.

Science writer Philip Ball is author of Critical Mass, which considers whether physics and chemistry can tell us as much about crowd behaviour as psychology and social science. This applies to physical crowds and traffic which can move about in ways which are similar to those of atoms in a confined space, he suggests, but can also apply to opinion formation.

"There is a large body of work highlighting the way that crowds can collectively make a good decision but can also reach a horrendously wrong one," he says.

A good example is a "guess the weight of the cake" competition at a country fair. If people know what others have guessed there will often be a conformity effect, with people clustering their guesses close to one of those made earlier. But that earlier guess may be entirely wrong, distorting the outcome. Meanwhile, studies have found that if people guess "blind" in such a contest, averaging out their guesses usually provides a remarkably accurate estimate of the true answer. That is the wisdom of crowds.

"What this tells us is that once you start introducing interaction between people you are much more likely to find 'herding' behaviour, reducing the chance of a 'good' guess," Ball says.

Social media and sophisticated online manipulation feed into the problem

The rise of the internet and social media has exacerbated the dangers, and polarised debate. This was perhaps seen most markedly in October 2016 when the Supreme Court ruled against the UK Government, saying parliament should have a say over the triggering of Article 50.

Newspapers suggested this was a clash between the courts and the populace, with the Daily Mail picturing the three judges who made the ruling, lined up like criminals mugshots, under the headline "Enemies of the people".

This was the birth of the now widely-discussed view that any deviation from Brexit will be a betrayal of voters in the referendum. It was ridiculed by others as an extraordinary over-reaction to an entirely legitimate ruling from the English courts – which is where Brexiteers apparently want legal decisions to be made in future.

Ball says. "The questions now are about how these opinion dynamics play out when an overall bias in society can tilt things so markedly in one direction or another.

"Advertising does that but with social media you see it even more strongly. The echo chamber effect is huge, with people getting feedback from like-minded people. People repost ideas that tally with their own perceptions and fake news can spread like wildfire. Little things can set in train an avalanche effect.

"This is why we have representative democracy rather than plebiscites. If you don't have a robust system referenda are vulnerable because it only takes a small nudge to send people herding in a certain way."

But it raises questions about how long democracy can continue to function, he says, especially in light of the fact that many politicians have been slow to realise the game is changing.

"It isn't just huge billboards, it is the fact that a Cambridge Analytica can understand and predict the effects of targeting certain people, but they also know how to predict and manipulate them.

Are we ants? Or bees?

In the insect world, the models for the wisdom of the crowd are creatures like ants and bees, both generally regarded as shining examples of collective decision-making. But bees have the edge, Toyokawa explains, and ants are more vulnerable to moments of "madness".

"Ants normally do very well. They copy and make very accurate decisions – for example when finding good food and a site for a nest. But sometimes a stupid ant can find a mediocre place. He or she may start advertising this option as good, and other ants react to that and follow.

"So the ants do really well when an environment is stable, but find it different to switch to a new environment. The honey bee generates collective intelligence very well, even in a changing environment.

"When the task is easy, humans behave more like a honey bee. When the group size increases and the task is difficult, we behave more like ants."

Drifting to the right

This week Neil Basu, assistant commissioner of the Metropolitan Police, warned Brexit could lead to another surge in far-right extremist groups, views and actions. The Brexit vote itself was followed by a surge in racist attacks, he pointed out, claiming that leaving the EU with no deal would be very bad for policing.

"We saw a spike in hate crime after the referendum – that's never really receded. So there's always a possibility people are being radicalised by the kind of febrile atmosphere we've got at the moment," he explained.

Toyokawa says group dynamics can explain how people on both sides are draw into face-offs in the street, or the heckling and harassment of politicians and journalists, when they would not otherwise be.

"Shouting in the street may affect other people's decision-making – we don't know the answer to that. But the idea of maladaptive herding could certainly apply to demonstrations," the researcher says. "People who might not usually get involved can end up copying the behaviour of others, just because they have seen there is a demo going on."

This may be more a case of people being emboldened in their original views and prejudices, Ball says, as opposed to flocking mistakenly to bad ideas. "There are ideas in some quarters such as the far right which are being played on and manipulated.

"Just as Donald Trump has to a degree legitimised racism in America, if people see their views endorsed they can be emboldened.

"If people at the top say it's OK to send out vans with messages on the side, there is the opportunity for people on the far right to manipulate the same sentiments. I'm not sure you need a lot of psychology to explain that."

And he warns that we can no longer ignore the increasing prevalence of such collective irrationality.

"We need to recognise these kind of dynamics in order to figure out what a democracy means and how it can operate in this networked age. Does it still have the same meaning?"

The Madness of Crowds - three lessons from history

The South Sea Bubble: Thousands of people invested in no-hope and sometimes fraudulent companies, in many cases losing their life savings.

While encouraging people to invest in firms which promised profits from overseas trade which had little prospect of taking place, traders also engaged insider trading, while divisions of the South Sea Company took money from those caught up in the speculation for wild projects ranging from paving the streets of London, digging for lead in Derbyshire and "trading in hair".

The Dot Com Bubble: In the mid-1990s, investor fascination with the phenomenon known as the "internet" reached new peaks. The introduction of web browsers made online work, trade and communication more widely accessible and computers were beginning to change from a luxury to a household essential.

But as companies which had never even made a profit achieved huge valuations, many failed during a two-year crash from 2000-2002

Tulipomania: Tulips, first introduced to Europe, rapidly grew in popularity – vividly colourful and glossy, they were unlike any native flower.

But in the mid 17th century the lucrative tulip trade saw an extraordinary demand for rare bulbs, which at one stage were changing hands for 10 times the average manual worker’s salary, and an individual bulb could change hands many times in a day. A kind of futures market in bulbs not yet grown developed.

Eventually buyers could not be found and speculators were left ruined, most without even flowers to show for their folly.

A film, Tulip Fever, based on the (somewhat exaggerated) story was released last year, but it too crashed, with a box office of only $8m against a $25m budget.