Beginning in England in the 17th century, the European world was stricken by what looks, in today's terms, like an epidemic of depression. The disease attacked both young and old, plunging them into months or years of morbid lethargy and relentless terrors, and seemed - perhaps only because they wrote more and had more written about them - to single out men of accomplishment and genius. The puritan writer John Bunyan, the political leader Oliver Cromwell, the poets Thomas Gray and John Donne, and the playwright and essayist Samuel Johnson are among the earliest and best-known victims. To the medical profession, the illness presented a vexing conundrum, not least because its gravest outcome was suicide. In 1733, Dr George Cheyne speculated that the English climate, combined with sedentary lifestyles and urbanisation, "have brought forth a class of distemper with atrocious and frightful symptoms, scarce known to our ancestors, and never rising to such fatal heights, and afflicting such numbers in any known nation. These nervous disorders being computed to make almost one-third of the complaints of the people of condition in England."

To the English, the disease was "the English malady". But the rainy British Isles were not the only site visited by the disease; all of Europe was afflicted.

The disease grew increasingly prevalent over the course of the 20th century, when relatively sound statistics first became available, and this increase cannot be accounted for by a greater willingness on the part of physicians and patients to report it. Rates of schizophrenia, panic disorders and phobias did not rise at the same time, for example, as they would be expected to if only changes in the reporting of mental illness were at work. According to the World Health Organisation, depression is now the fifth leading cause of death and disability in the world, while ischemic heart disease trails in sixth place. Fatalities occur most dramatically through suicide, but even the mild form of depression - called dysthemia and characterised by an inability to experience pleasure - can kill by increasing a person's vulnerability to serious somatic illnesses such as cancer and heart disease. Far from being an affliction of the famous and successful, we now know that the disease strikes the poor more often than the rich, and women more commonly than men.

Just in the past few years, hundreds of books, articles and television specials have been devoted to depression: its toll on the individual, its relationship to gender, the role of genetic factors, the efficacy of pharmaceutical treatments. But to my knowledge, no one has suggested that the epidemic may have begun in a particular historical time, and started as a result of cultural circumstances that arose at that time and have persisted or intensified since. The failure to consider historical roots may stem, in part, from the emphasis on the celebrity victims of the past, which tends to discourage a statistical, or epidemiological, perspective. But if there was, in fact, a beginning to the epidemic of depression, sometime in the 16th or 17th century, it confronts us with this question: could this apparent decline in the ability to experience pleasure be in any way connected with the decline in opportunities for pleasure, such as carnival and other traditional festivities?

There is reason to think that something like an epidemic of depression in fact began around 1600, or the time when the Anglican minister Robert Burton undertook his "anatomy" of the disease, published as The Anatomy of Melancholy in 1621. Melancholy, as it was called until the 20th century, is of course a very ancient problem, and was described in the fifth century BC by Hippocrates. Chaucer's 14th-century characters were aware of it, and late-medieval churchmen knew it as "acedia". So melancholy, in some form, had always existed - and, regrettably, we have no statistical evidence of a sudden increase in early modern Europe, which had neither a psychiatric profession to do the diagnosing nor a public health establishment to record the numbers of the afflicted. All we know is that in the 1600s and 1700s, medical books about melancholy and literature with melancholic themes were both finding an eager audience, presumably at least in part among people who suffered from melancholy themselves.

Increasing interest in melancholy is not, however, evidence of an increase in the prevalence of actual melancholy. As the historian Roy Porter suggested, the disease may simply have been becoming more stylish, both as a medical diagnosis and as a problem, or pose, affected by the idle rich, and signifying a certain ennui or detachment. No doubt the medical prejudice that it was a disease of the gifted, or at least of the comfortable, would have made it an attractive diagnosis to the upwardly mobile and merely out-of-sorts.

But melancholy did not become a fashionable pose until a full century after Burton took up the subject, and when it did become stylish, we must still wonder: why did this particular stance or attitude become fashionable and not another? An arrogant insouciance might, for example, seem more fitting to an age of imperialism than this wilting, debilitating malady; and enlightenment, another well-known theme of the era, might have been better served by a mood of questing impatience.

Nor can we be content with the claim that the apparent epidemic of melancholy was the cynical invention of the men who profited by writing about it, since some of these were self-identified sufferers themselves. Robert Burton confessed, "I writ of melancholy, by being busy to avoid melancholy." George Cheyne was afflicted, though miraculously cured by a vegetarian diet of his own devising. The Englishman John Brown, who published a bestselling mid-19th-century book on the subject, went on to commit suicide. Something was happening, from about 1600 on, to make melancholy a major concern of the reading public, and the simplest explanation is that there was more melancholy around to be concerned about.

And very likely the phenomena of this early "epidemic of depression" and the suppression of communal rituals and festivities are entangled in various ways. It could be, for example, that, as a result of their illness, depressed individuals lost their taste for communal festivities and even came to view them with revulsion. But there are other possibilities. First, that both the rise of depression and the decline of festivities are symptomatic of some deeper, underlying psychological change, which began about 400 years ago and persists, in some form, in our own time. The second, more intriguing possibility is that the disappearance of traditional festivities was itself a factor contributing to depression.

One approaches the subject of "deeper, underlying psychological change" with some trepidation, but fortunately, in this case, many respected scholars have already visited this difficult terrain. "Historians of European culture are in substantial agreement," Lionel Trilling wrote in 1972, "that in the late 16th and early 17th centuries, something like a mutation in human nature took place." This change has been called the rise of subjectivity or the discovery of the inner self and since it can be assumed that all people, in all historical periods, have some sense of selfhood and capacity for subjective reflection, we are really talking about an intensification, and a fairly drastic one, of the universal human capacity to face the world as an autonomous "I", separate from, and largely distrustful of, "them". The European nobility had already undergone this sort of psychological shift in their transformation from a warrior class to a collection of courtiers, away from directness and spontaneity and toward a new guardedness in relation to others. In the late 16th and 17th centuries, the change becomes far more widespread, affecting even artisans, peasants, and labourers. The new "emphasis on disengagement and selfconsciousness", as Louis Sass puts it, makes the individual potentially more autonomous and critical of existing social arrange-ments, which is all to the good. But it can also transform the individual into a kind of walled fortress, carefully defended from everyone else.

Historians infer this psychological shift from a number of concrete changes occurring in the early modern period, first and most strikingly among the urban bourgeoisie, or upper middle class. Mirrors in which to examine oneself become popular among those who can afford them, along with self-portraits (Rembrandt painted more than 50 of them) and autobiographies in which to revise and elaborate the image that one has projected to others. In bourgeois homes, public spaces that guests may enter are differentiated, for the first time, from the private spaces - bedrooms, for example - in which one may retire to let down one's guard and truly "be oneself". More decorous forms of entertainment - plays and operas requiring people to remain immobilised, each in his or her separate seat - begin to provide an alternative to the promiscuously interactive and physically engaging pleasures of carnival. The very word "self", as Trilling noted, ceases to be a mere reflexive or intensifier and achieves the status of a freestanding noun, referring to some inner core, not readily visible to others.

The notion of a self hidden behind one's appearance and portable from one situation to another is usually attributed to the new possibility of upward mobility. In medieval culture, you were what you appeared to be - a peasant, a man of commerce or an aristocrat - and any attempt to assume another status would have been regarded as rank deception. But in the late 16th century, upward mobility was beginning to be possible or at least imaginable, making "deception" a widespread way of life. You might not be a lord or a lofty burgher, but you could find out how to act like one. Hence the popularity, in 17th-century England, of books instructing the would-be member of the gentry in how to comport himself, write an impressive letter and choose a socially advantageous wife.

Hence, too, the new fascination with the theatre, with its notion of an actor who is different from his or her roles. This is a notion that takes some getting used to; in the early years of the theatre, actors who played the part of villains risked being assaulted by angry playgoers in the streets. Within the theatre, there is a fascination with plots involving further deceptions: Shakespeare's Portia pretends to be a doctor of law; Rosalind disguises herself as a boy; Juliet feigns her own death. Writing a few years after Shakespeare's death, Burton bemoaned the fact that acting was no longer confined to the theatre, for "men like stage-players act [a] variety of parts". It was painful, in his view, "to see a man turn himself into all shapes like a Chameleon ... to act twenty parts & persons at once for his advantage ... having a several face, garb, & character, for every one he meets". The inner self that can change costumes and manners to suit the occasion resembles a skilled craftsperson, too busy and watchful for the pleasures of easygoing conviviality. As for the outer self projected by the inner one into the social world: who would want to "lose oneself" in the communal excitement of carnival when that self has taken so much effort and care to construct?

So highly is the "inner self" honoured within our own culture that its acquisition seems to be an unquestionable mark of progress - a requirement, as Trilling called it, for "the emergence of modern European and American man". It was, no doubt, this sense of individuality and personal autonomy, "of an untrammelled freedom to ask questions and explore", as the historian Yi-Fu Tuan put it, that allowed men such as Martin Luther and Galileo to risk their lives by defying Catholic doctrine. Which is preferable: a courageous, or even merely grasping and competitive, individualism, versus a medieval (or, in the case of non-European cultures, "primitive") personality so deeply mired in community and ritual that it can barely distinguish a "self"? From the perspective of our own time, the choice, so stated, is obvious. We have known nothing else.

But there was a price to be paid for the buoyant individualism we associate with the more upbeat aspects of the early modern period, the Renaissance and Enlightenment. As Tuan writes, "the obverse" of the new sense of personal autonomy is "isolation, loneliness, a sense of disengagement, a loss of natural vitality and of innocent pleasure in the givenness of the world, and a feeling of burden because reality has no meaning other than what a person chooses to impart to it". Now if there is one circumstance indisputably involved in the etiology of depression, it is precisely this sense of isolation. As the 19th-century French sociologist Emile Durkheim saw it, "Originally society is everything, the individual nothing ... But gradually things change. As societies become greater in volume and density, individual differences multiply, and the moment approaches when the only remaining bond among the members of a single human group will be that they are all [human]." The flip side of the heroic autonomy that is said to represent one of the great achievements of the early modern and modern eras is radical isolation and, with it, depression and sometimes death.

But the new kind of personality that arose in 16th- and 17th-century Europe was by no means as autonomous and self-defining as claimed. For far from being detached from the immediate human environment, the newly self-centered individual is continually preoccupied with judging the expectations of others and his or her own success in meeting them: "How am I doing?" this supposedly autonomous "self" wants to know. "What kind of an impression am I making?"

It is no coincidence that the concept of society emerges at the same time as the concept of self. What seems most to concern the new and supposedly autonomous self is the opinion of others, who in aggregate compose "society". Mirrors, for example, do not show us our "selves", only what others can see, and autobiographies reveal only what we want those others to know. The crushing weight of other people's judgments - imagined or real - would help explain the frequent onset of depression at the time of a perceived or anticipated failure. In the 19th century, the historian Janet Oppenheim reports, "severely depressed patients frequently revealed totally unwarranted fears of financial ruin or the expectation of professional disgrace". This is not autonomy but dependency: the emerging "self" defines its own worth in terms of the perceived judgments of others.

If depression was one result of the new individualism, the usual concomitant of depression - anxiety - was surely another. It takes effort, as well as a great deal of watchfulness, to second-guess other people's reactions and plot one's words and gestures accordingly. For the scheming courtier, the striving burgher and the ambitious lawyer or cleric of early modern Europe, the "self" they discovered is perhaps best described as an awareness of this ceaseless, internal effort to adjust one's behaviour to the expectations of others. Play in this context comes to have a demanding new meaning, unconnected to pleasure, as in "playing a role". No wonder bourgeois life becomes privatised in the 16th and 17th centuries, with bedrooms and studies to withdraw to, where, for a few hours a day, the effort can be abandoned, the mask set aside.

But we cannot grasp the full psychological impact of this "mutation in human nature" in purely secular terms. Four hundred - even 200 - years ago, most people would have interpreted their feelings of isolation and anxiety through the medium of religion, translating self as "soul"; the ever-watchful judgmental gaze of others as "God"; and melancholy as "the gnawing fear of eternal damnation". Catholicism offered various palliatives to the disturbed and afflicted, in the form of rituals designed to win divine forgiveness or at least diminished disapproval; and even Lutheranism, while rejecting most of the rituals, posited an approachable and ultimately loving God.

Not so with the Calvinist version of Protestantism. Instead of offering relief, Calvinism provided a metaphysical framework for depression: if you felt isolated, persecuted and possibly damned, this was because you actually were.

John Bunyan seems to have been a jolly enough fellow in his youth, much given to dancing and sports in the village green, but with the onset of his religious crisis these pleasures had to be put aside. Dancing was the hardest to relinquish - "I was a full year before I could quite leave it" - but he eventually managed to achieve a fun-free life. In Bunyan's Pilgrim's Progress, carnival is the portal to Hell, just as pleasure in any form - sexual, gustatory, convivial - is the devil's snare. Nothing speaks more clearly of the darkening mood, the declining possibilities for joy, than the fact that, while the medieval peasant created festivities as an escape from work, the Puritan embraced work as an escape from terror.

We do not have to rely on psychological inference to draw a link between Calvinism and depression. There is one clear marker for depression - suicide - and suicide rates have been recorded, with varying degrees of diligence, for centuries. In his classic study, Durkheim found that Protestants in the 19th century - not all of whom, of course, were of the Calvinistic persuasion - were about twice as likely to take their own lives as Catholics. More strikingly, a recent analysis finds a sudden surge of suicide in the Swiss canton of Zurich, beginning in the late 16th century, just as that region became a Calvinist stronghold. Some sort of general breakdown of social mores cannot be invoked as an explanation, since homicides fell as suicides rose.

So if we are looking for a common source of depression on the one hand, and the suppression of festivities on the other, it is not hard to find. Urbanisation and the rise of a competitive, market-based economy favoured a more anxious and isolated sort of person - potentially both prone to depression and distrustful of communal pleasures. Calvinism provided a transcendent rationale for this shift, intensifying the isolation and practically institutionalising depression as a stage in the quest for salvation. At the level of "deep, underlying psychological change", both depression and the destruction of festivities could be described as seemingly inevitable consequences of the broad process known as modernisation. But could there also be a more straightforward link, a way in which the death of carnival contributed directly to the epidemic of depression?

It may be that in abandoning their traditional festivities, people lost a potentially effective cure for it. Burton suggested many cures for melancholy - study and exercise, for example - but he returned again and again to the same prescription: "Let them use hunting, sports, plays, jests, merry company ... a cup of good drink now and then, hear musick, and have such companions with whom they are especially delighted; merry tales or toys, drinking, singing, dancing, and whatsoever else may procure mirth." He acknowledged the ongoing attack on "Dancing, Singing, Masking, Mumming, Stage-plays" by "some severe Gatos," referring to the Calvinists, but heartily endorsed the traditional forms of festivity: "Let them freely feast, sing and dance, have their Puppet-plays, Hobby-horses, Tabers, Crowds, Bagpipes, &c, play at Ball, and Barley-breaks, and what sports and recreations they like best." In his ideal world, "none shall be over-tired, but have their set times of recreations and holidays, to indulge their humour, feasts and merry meetings ..." His views accorded with treatments of melancholy already in use in the 16th century. While the disruptively "mad" were confined and cruelly treated, melancholics were, at least in theory, to be "refreshed & comforted" and "gladded with instruments of musick".

A little over a century after Burton wrote The Anatomy of Melancholy, another English writer, Richard Browne, echoed his prescription, backing it up with a scientific (for the time) view of the workings of the human "machine". Singing and dancing could cure melancholy, he proposed, by stirring up the "secretions". And a century later, even Adam Smith, the great prophet of capitalism, was advocating festivities and art as a means of relieving melancholy.

Burton, Browne and Smith were not the only ones to propose festivity as a cure for melancholy, and there is reason to believe that whether through guesswork, nostalgia, or personal experience, they were on to something important. I know of no attempts in our own time to use festive behaviour as treatment for depression, if such an experiment is even thinkable in a modern clinical setting. There is, however, an abundance of evidence that communal pleasures have served, in a variety of cultures, as a way of alleviating and even curing depression.

The 19th-century historian JFC Hecker reports an example from 19th-century Abyssinia, or what is now Ethiopia. An individual, usually a woman, would fall into a kind of wasting illness, until her relatives agreed to "hire, for a certain sum of money, a band of trumpeters, drummers, and fifers, and buy a quantity of liquor; then all the young men and women of the place assemble at the patient's house," where they dance and generally party for days, invariably effecting a cure. Similarly, in 20th-century Somalia, a married woman afflicted by what we would call depression would call for a female shaman, who might diagnose possession by a "sar" spirit. Musicians would be hired, other women summoned, and the sufferer cured through a long bout of ecstatic dancing with the all-female group.

We cannot be absolutely sure in any of these cases - from 17th-century England to 20th-century Somalia - that festivities and danced rituals actually cured the disease we know as depression. But there are reasons to think that they might have. First, because such rituals serve to break down the sufferer's sense of isolation and reconnect him or her with the human community. Second, because they encourage the experience of self-loss - that is, a release, however temporary, from the prison of the self, or at least from the anxious business of evaluating how one stands in the group or in the eyes of an ever-critical God. Friedrich Nietzsche, as lonely and tormented an individual as the 19th century produced, understood the therapeutics of ecstasy perhaps better than anyone else. At a time of almost universal celebration of the "self", he alone dared speak of the "horror of individual existence", and glimpsed relief in the ancient Dionysian rituals that he knew of only from reading classics - rituals in which, he imagined, "each individual becomes not only reconciled to his fellow but actually at one with him".

The immense tragedy for Europeans, and most acutely for the northern Protestants among them, was that the same social forces that disposed them to depression also swept away a traditional cure. They could congratulate themselves for brilliant achievements in the areas of science, exploration and industry, and even convince themselves that they had not, like Faust, had to sell their souls to the devil in exchange for these accomplishments. But with the suppression of festivities that accompanied modern European "progress", they had done something perhaps far more damaging: they had completed the demonisation of Dionysus begun by Christians centuries ago, and thereby rejected one of the most ancient sources of help - the mind-preserving, life-saving techniques of ecstasy.

· This is an edited extract from Dancing in the Streets: A History of Collective Joy by Barbara Ehrenreich, published by Granta at £16.99. To buy a copy from the Guardian bookshop for £15.99 with free p&p contact 0870 836 0875 or email support@guardianbookshop.co.uk. Barbara Ehrenreich will be speaking with Geoff Dyer at London's ICA tonight (www.ica.org.uk)