Blog 🎤

A generalised FizzBuzz solution in R ;-)

Just spotted this and wondered if I could come up with a pretty solution in R. Here’s an attempt.

fizzbuzz = function(i, multiples = c(3,5), text = c("Fizz", "Buzz")) {
  words = text[i %% multiples == 0]
  if (length(words) == 0)
    paste(words, collapse = "")

sapply(1:200,function(x) fizzbuzz(x))

This also generalises, e.g., call

sapply(1:200,function(x) fizzbuzz(x, c(3,5,7), c("Fizz","Buzz","Bang")))

“There is much to be said for contentment and painlessness…”

“There is much to be said for contentment and painlessness, for these bearable and submissive days, on which neither pain nor pleasure is audible, but pass by whispering on tip-toe. But the worst of it is that it is just this contentment that I cannot endure. After a short time it fills me with irrepressible hatred and nausea. In desperation I have to escape and throw myself on the road to pleasure, or, if that cannot be, on the road to pain. When I have neither pleasure nor pain and have been breathing for a while the lukewarm insipid air of these so-called good and tolerable days, I feel so bad in my childish soul that I smash my mouldering lyre of thanksgiving in the face of the slumbering god of contentment and would rather feel the very devil burn in me than this warmth of a well-heated room.”

—Hermann Hesse, Steppenwolf (thanks to an Atelopus varius.)

Some elements of some theories of emotion

Some elements of some theories of emotion — bits that moved me.

You might also enjoy this lovely definition. (And this on problems with definitions.)

Basic emotions

(Table from Power & Dalgleish, 2008)

Basic emotion Appraisal
Sadness Loss or failure (actual or possible) of valued role or goal
Happiness Successful move towards or completion of a valued role or goal
Anger Blocking or frustration of a role or goal through perceived agent
Fear Physical or social threat to self or valued role or goal
Disgust A person, object, or idea repulsive to the self, and to valued roles and goals

Where you can read about it

Oatley, K. & Johnson-Laird, P. N. (1987). Towards a cognitive theory of emotions. Cognition & Emotion 1(1), 29–50.

Power, M., & Dalgleish, T. (2008), Cognition and Emotion: From Order to Disorder. Psychology Press.

A 12-Point Circumplex Structure of Core Affect

(A picture from Yik, Russell, & Steiger, 2011)

Where you can read about it

Yik, M., Russell, J. A., & Steiger, J. H. (2011). A 12-point circumplex structure of core affect. Emotion 11(4), 705–731.

Component Process Model

(Individual difference variables affecting appraisals; from Scherer 2009)

Emotion disposition / Trait affect (Emotional disorder) Appraisal tendencies or biases (motivational and cognitive) Potentially facilitating culturally dominant goal, belief, value dimensions
Trait sadness Resignation, dejection, acquiescence (Depression) Mot: Strong attachment to people and propertyCog: Low self esteem, underestimation of control, coping, and adjustment potential; tendency to ruminate; Goa: interdependent goal pursuitsBel: Human nature goodVal: Conservatism, security, embeddedness, benevolence, harmony
Trait anger Irritation, irascibility, choleric (Hostility, psychoticism) Mot: Strong goal orientation, high expectationsCog: High self esteem, external attribution, blaming, overestimation of control, power, coping, and adjustment potential; exaggerated optimism Goa: Independent goal pursuitsBel: Human nature bad, normativityVal: Conservatism, self-enhancement, autonomy, entitlement, mastery
Trait anxiety Worrier, apprehensiveness, neuroticism (general anxiety disorder) Mot: PerfectionismCog: Exaggerated sensitivity for novelty, uncertainty, and urgency (looming); low self esteem, underestimation of control, coping, and adjustment potential; exaggerated pessimism Goa: Independent goal pursuitsBel: Human nature bad, normativityVal: Conservatism, self-enhancement, autonomy, entitlement, mastery
Trait shame/guilt Embarrassment, unworthiness, disconcertment, abashment(clinical shame/guilt syndromes) Mot: High need for self-worth and social recognition; conformity; perfectionismCog: Internal attribution Goa: Interdependent goal pursuitsBel: Human nature goodVal: Conservatism, embeddedness, benevolence, harmony
Trait positive affect Joyfulness, buoyancy, cheerfulness, good spirits(manic euphoria) Mot: Hedonism, realistic aimsCog: Optimism; high self esteem, overestimation of control, coping, and adjustment potential Goa: Independent goal pursuitsBel: Human nature goodVal: Embeddedness, benevolence, harmony, openness for change
Note: Mot: motivational, Cog: cognitive, Goa: goal pursuit, Bel: beliefs about human nature, Val: value dimensions.

Where you can read about it

Scherer, K. R. (2009). The dynamic architecture of emotion: Evidence for the component process model. Cognition and Emotion 23(7), 1307–1351.

What’s left?

I didn’t know much about Nick Cohen before picking up What’s Left? from the Swiss Cottage market book bloke. Here’s what Google told me:

First, Craig Murray:

Let me summarise Nick Cohen’s book for you. ‘If you are against eating Muslim babies, you are a supporter of Islamofascism. If you are perturbed by Guantanamo Bay, you would not have fought in the Spanish Civil War, are probably a fan of Hitler and have no right to call yourself a Liberal. Neo-Conservatism is the New Left.’

There, now you don’t have to read it. Believe me, I have done you a favour.

Or how about  Peter Wilby?

Cohen appears to think this book shows he has put infantile leftism behind him and attained a new maturity. Alas, it shows that he is, and always was, a political innocent.

Johann Hari?

…once Cohen’s blind faith in neoconservatism becomes clear, many of the accusations he makes against the left begin to look like acts of psychological projection rather than serious political arguments.

What’s left?

Here are some examples elaborated in the book which might help you decide whether you want to read it:

  • Companies from West Germany supplied Saddam Hussein with “one of the largest chemical weapons manufacturing industries in the world” (p. 47). East German communists provided Saddam’s forces training.
  • France built a nuclear reactor for Saddam, which was blown up by the Israeli air force before the nuclear fuel arrived.
  • The slow response  of Europe, including the then UK Tory government, to Slobodan Milošević, Butcher of the Balkans — leading to the Srebrenica genocide.
  • Some evidence that Virginia Woolf might have been a “screaming snob” who hated the working class. Here’s an example, to give you a flavour of his argument, of what she said: “What rather appals me… is the terrible conventionality of the workers. That’s why — if you want explanations — I don’t think they will be poets or novelists for another hundred years or so.”
  • A quotation from George Galloway saluting Saddam Hussein: “Sir, I salute your courage, your strength and your indefatigability. And I want you to know that we are with you until victory, until victory until Jerusalem.”
  • Evidence that the reason for war in Iraq was a lie, Cohen writes: “If Blair had levelled with the British people he would have said that he couldn’t be sure if Saddam was armed, and even if he was there was no imminent danger, but here was a chance to remove a disgusting regime… Instead he spun and talked about chemical weapons…”

I don’t agree with everything in the book, but I am deeply suspicious now of those who think leftish people should avoid it.

“The true beginnings of scientific activity…” (Freud, 1915)

“We have often heard the demand that a science be built on clear and precisely defined basic concepts. In reality, no science, not even the most basic, starts out with such definitions. The true beginnings of scientific activity consist, rather, in the description of phenomena, which are then grouped, classified, and brought into relation with each other. Even when simply describing the material, we cannot avoid applying to it certain abstract ideas, acquired from somewhere or other but certainly not just from the new observations alone.”

—Freud (1915), Drives and their Fates

“We rarely recognize how…

“We rarely recognize how wonderful it is that a person can traverse an entire lifetime without making a single really serious mistake — like putting a fork in one’s eye or using a window instead of a door.”

—Marvin Minsky, The Society of Mind (1988)

“We rarely recognize how wonderful it is that a person can traverse an entire lifetime without making a single really serious mistake — like putting a fork in one’s eye or using a window instead of a door.”

—Marvin Minsky, The Society of Mind (1988)

A cup of coffee and a tent

“Can’t they be about… sorry… we… er… eh… no no no no… it’s just so obvious I can’t be bothered…

“You don’t have to want to return to a barter system in the stoneage to complain about the way the financial crisis affected large numbers of people in the world, do you? Even if you’re having a cup of coffee and you’ve got a tent!”

— Ian Hislop responding to Louise Mensch on Have I Got News For You, 23/10/2011

Linking statistics and qualitative methods

You’ll be aware of the gist. Quantitative statistical models are great for generalizing, also data suitable for the stats tends to be quicker to analyze than qualitative data. More qualitative methods, such as interviewing, tend to provide much richer information, but generalization is very tricky and often involves coding up so the data can be fitted using the stats. How else can the two (crudely defined here!) approaches to analysis talk to each other?

I like this a lot:

“In the social sciences we are often criticized by the ethnographers and the anthropologists who say that we do not link in with them sufficiently and that we simply produce a set of statistics which do not represent reality.”

“… by using league tables, we can find examples of places which are perhaps not outliers but where we want to look for the pathways of influence on why they are not outliers. For example, one particular Bangladeshi village would have been expected to have high levels of immunization, whereas it was down in the middle of the table with quite a large confidence interval. This seemed rather strange, but our colleagues were able to attribute this to a fundamentalist imam. […] Another example is a village at the top of the league table, which our colleagues could attribute to a very enthusiastic school-teacher.”

“… by connecting with the qualitative workers, by encouraging the fieldworkers to look further at particular villages and by saying to them that we were surprised that this place was good and that one was bad, we could get people to understand the potential for linking the sophisticated statistical methods with qualitative research.” (Ian Diamond and Fiona Steele, from a comment on a paper by Goldstein and Spiegelhalter, 1996, p. 429)

Also reminds me of a study by Turner and Sobolewska (2009) which split participants on their Systemizing and Empathizing Quotient scores. Participants were asked, “What is inside a mobile phone?” Here’s what someone with high EQ said:

“It flashes the lights, screen flashes, and the buttons lights up, and it vibrates. It comes to life on the inside and it comes to life on the outside, and you talk to the one side and someone is answering on the other side”

And someone with high SQ:

“Many things, circuit boards, chips, transceiver [laughs], battery [pause], a camera in some of them, a media player, buttons, lots of different things. [pause] Well there are lots and lots of different bits and pieces to the phone, there are mainly in … Eh, like inside the chip there are lots of little transistors, which is used, they build up to lots of different types of gates…”

(One possible criticism is that the SQ/EQ just found students of technical versus non-technical subjects… But the general idea is still lovely.)

Would be great to see more quantitative papers with little excerpts of stories. We tried in our paper on spontaneous shifts of interpretation on a probabilistic reasoning task (Fugard, Pfeifer, Mayerhofer & Kleiter, 2011, p. 642), but we only squeezed in a few sentences:

‘Participant 34 (who settled into a conjunction interpretation) said: “I only looked at the shape and the color, and then always out of 6; this was the quickest way.” Participant 37, who shifted from the conjunction to the conditional event, said: “In the beginning [I] always [responded] ‘out of 6,’ but then somewhere in the middle . . . Ah! It clicked and I got it. I was angry with myself that I was so stupid before.” Five participants spontaneously reported when they shifted during the task, for example, saying, “Ah, this is how it works.”’


Fugard, A. J. B., Pfeifer, N., Mayerhofer, B., & Kleiter, G. D. (2011).  How people interpret conditionals: Shifts towards the conditional event.  Journal of Experimental Psychology: Learning, Memory, and Cognition, 37, 635–648.

Goldstein, H. & Spiegelhalter, D. J. (1996). League tables and their limitations: statistical issues in comparisons of institutional performance. Journal of the Royal Statistical Society. Series A (Statistics in Society) 159, 385–443.

Turner, P. & Sobolewska, E. (2009). Mental models, magical thinking, and individual differences. Human Technology 5, 90–113.


“… all authority is quite degrading. It degrades those who exercise it, and degrades those over whom it is exercised. When it is violently, grossly, and cruelly used, it produces a good effect, by creating, or at any rate bringing out, the spirit of revolt and Individualism that is to kill it. When it is used with a certain amount of kindness, and accompanied by prizes and rewards, it is dreadfully demoralising. People, in that case, are less conscious of the horrible pressure that is being put on them, and so go through their lives in a sort of coarse comfort, like petted animals, without ever realising that they are probably thinking other people’s thoughts…”

Oscar Wilde, The Soul of Man under Socialism, 1891