Texts I like for learning statistics and using R

I’ll be updating this, but first thoughts:

Fitting regression models, GLMs, etc.

Fox, J., & Weisberg, S. (2019). An R companion to applied regression (3rd ed.). London: SAGE Publications Ltd.

See also online material, including free appendices and R code.

Data transformation and visualisation

Healy, K. (2019). Data Visualization: A Practical Introduction. Princeton University Press. (Free online version.)

Wickham, H., & Grolemund, G. (2017). R for Data Science: Import, Tidy, Transform, Visualize, and Model Data. Sebastopol, CA: O’Reilly. (Free online version.)

Chang, W. (2020). R Graphics Cookbook (2nd ed.). Sebastopol, CA: O’Reilly. (Free online version.)

Lüdecke D (2018). ggeffects: Tidy Data Frames of Marginal Effects from Regression ModelsJournal of Open Source Software3(26), 772. doi: 10.21105/joss.00772

This is very handy for getting predictions from models, focusing on the effect of predictors of interest whilst holding covariates at some fixed values like a mean or (for factors) mode.

See also the package website for illustrative examples.

Gelman, A. (2011). Tables as graphs: The Ramanujan principleSignificance, 8, 183.

Missing data imputation

Van Buuren, S. (2018). Flexible Imputation of Missing Data. Second Edition.. Chapman & Hall/CRC. Boca Raton, FL. (Free online version.)

See also the package website.

P-values

Greenland, S., Senn, S. J., Rothman, K. J., Carlin, J. B., Poole, C., Goodman, S. N., & Altman, D. G. (2016). Statistical tests, P values, confidence intervals, and power: a guide to misinterpretations. European Journal of Epidemiology31, 337–350.

“… correct use and interpretation of these statistics requires an attention to detail which seems to tax the patience of working scientists.”

Colquhoun, D. (2014). An investigation of the false discovery rate and the misinterpretation of p-values. Royal Society Open Science, 1, 140216. doi: 10.1098/rsos.140216

This generated lots of debate – I like how it attempts to use Bayes rule to turn p-values into something useful and the explanation in terms of diagnostic test properties. See also this on PPV and NPV.

Rafi, Z., & Greenland, S. (2020). Semantic and cognitive tools to aid statistical science: replace confidence and significance by compatibility and surprise. BMC Medical Research Methodology, 20(1), 244. doi: 10.1186/s12874-020-01105-9

Interesting proposal to use s-values, calculated from p-values as −log₂(p). It’s a simple transformation: p is probability of getting all heads from −log₂(p) fair coin tosses. For example if p = 0.5 then s = 1; toss a coin once then the probability of head is 0.5. If p = 0.03125 then s = 5; toss a coin 5 times then the probability of all heads is 0.03125. But the s-value is supposedly easier to think about. I’m not sure if it really is, but I like the idea!

Politicians do social metaphysics

“There is no such thing as society. There is living tapestry of men and women and people and the beauty of that tapestry and the quality of our lives will depend upon how much each of us is prepared to take responsibility for ourselves and each of us prepared to turn round and help by our own efforts those who are unfortunate.”

—Margaret Thatcher (Sept 23, 1987), then Prime Minister of the UK, Interview for Woman’s Own

“The reality is international law is a set of political constructs which actually countries abide by or depart from in a number of circumstances – including the Euroepan Union itself. For example it didn’t apply WTO rules on Airbus. Arguably that’s a violation of international law but the EU did it because the EU felt it was inappropriate to do that.

“It is not unusual for there to be disputes over international law, it is not unusual in certain limited limited circumstances for countries not to comply with all obligations under international law.”

—Theresa Villiers (Sept 14, 2020), Secretary of State for Environment, Food and Rural Affairs, Sky News (as reported by Jon Stone in the Independent)

WSPR and FT8

I’ve just started experimenting with digital models again on ham radio. Finally, around 11pm, got across the Atlantic on WSPR (technically, MEPT_JT; Manned Experimental Propagation Transmission plus its creator Joe Taylor’s initials) with ~3W and a loop antenna inside a north London flat.

Shortly after, made it across with FT8

… but no transatlantic QSO in this flat yet.

I’m using a Yaesu FT-818, WonderWand Wonder Loop 750, and a SignaLink USB interface to connect the 818 to my laptop running WSJT-X.

Exploring the Russia Report using R

The UK’s Intelligence and Security Committee’s report into Russian activity in the UK was finally released a few days ago.

Here’s my exploration of redactions in the report, using R. Some highlights below.

One of the best predictors of whether a sentence will have a redaction is what organisations are mentioned in the sentence:

 

According to a sentiment analysis, the angriest sentences are on page 11 (PDF page 18):

 

Here’s a word cloud of sentences with a redaction, against the organisations(s) mentioned…

 

Choropleths in R – example using the 2020 Russian constitutional referendum

Choropleth maps use shading to represent quantities and are common in the press. I gave them a go in R, using the rvest package to scrape the results of the 2020 Russian constitutional referendum and the raster package piped through tidyverse tools to map them.

The code is on my GitHub repo.

Some of the fun I encountered along the way (details in the repo):

  • The CRAN version of raster didn’t work, but the latest on GitHub was fine and it’s easy to install this directly from R.
  • The Russian regions names in the raster map of Russia didn’t always match those on the Wikipedia article. I tried fuzzy matching by edit distance, which did a pretty good job but I still had to match some manually (e.g., “Sakha” and “Yakutia” are different names for the same place and a long edit distance from each other). I suspect it would have been easier just to sort both lists alphabetically and match manually from the start!
  • This warning is a worry: “support for gpclib will be withdrawn from maptools at the next major release” – I hope something comes along to replace it.
  • Lots of the examples of maps online are for the US and one basic problem is what projection to use. The mapproj package is fab for this.

A Little Fable (Kleine Fabel) – Franz Kafka

“Alas”, said the mouse, “the whole world is growing smaller every day. At the beginning it was so big that I was afraid, I kept running and running, and I was glad when I saw walls far away to the right and left, but these long walls have narrowed so quickly that I am in the last chamber already, and there in the corner stands the trap that I am running into.”

“You only need to change your direction,” said the cat, and ate it up.

—Franz Kafka, a short story written some time between 1917 and 1923

WTF is psychosocial studies?

Psychosocial studies is at the intersection of arts, psychology, psychoanalysis, cultural studies, social work, sociology – and a huge number of related fields.  Actually maybe it’s the set union of those fields (and more) too. I think this diagram illustrates the spirit of the relationships (Figure 8 from Simonetto and Auber’s paper on undrawable Euler diagrams):

A very complex Euler diagram of 8 overlapping shapes in multiple colours

Efforts to write manifestos of psychosocial studies as an inter/transdiscipline have accelerated since the 1990s. A common theme is that psychological life (conscious and unconscious) is interwoven with social life. For such a broad programme, there are inevitably rows about what exactly psychosocial studies “is” and at times the debates seem to reflect academic power struggles more than substance (not unlike the qual versus quant rows).

Diet or full fat psychosocial?

Sasha Roseneil (2014) took a helpful empirical approach, developing a taxonomy of broad genres of ESRC-funded projects which used the term “psychosocial”.  What did the researchers on these projects seem to mean?

Psychosocial “lite” research uses “psychosocial” as an adjective to describe linking social and psychological variables, like social stressors and individual wellbeing. This seems to fit the study by Barr et al. (2016) which explored the effect of welfare policy changes on mental ill-health (though the researchers didn’t use the term “psychosocial” and the lead author was in a Department of Public Health and Policy).

The “middle ground” of psychosocial research consists of work that takes this a step further to explore (p. 130)

“emotions or emotional life, or had a more expansive sociological/societal understanding of the social than ‘psychosocial lite’ research”

I’m not entirely sure I’d be able to distinguish “lite” from “middle ground” – maybe “thick description” or Verstehen are beginning to creep in? In any case, both stay within or combine ideas from existing disciplines like psychology and sociology.

The “strong” programme differs from these two in that research (p. 130)

“articulated either an implicit or explicit challenge to the disciplinary divisions between psychology and sociology, were concerned with the mutual constitution of the psychic and the social and saw the theoretical/methodological approach that they were taking to the research as ‘psychosocial’ (rather than using the word to qualify other concepts).”

Pledging allegiance to the new discipline is necessary, according to this “strong” account, alongside the need to foreground the “mutual constitution” of psy and social, rather than explaining one in terms of the other. So no explaining social life through Big Five personality scores or IQ.

Inside/outside

This “strong” definition reminds me of work by philosophers Andy Clark and David Chalmers (1998) on the extended mind. They begin by arguing that our concept of self “outstrips the boundaries of consciousness”. This is easy to see since, for example, we are only consciously aware of a small number of our beliefs at any given time. We still have those beliefs somewhere, somehow, and they pop into consciousness again when triggered by context. We also scribble in notebooks (and these days tap at apps) so that we don’t forget stuff. Again these memories exist outside consciousness, not unlike dormant beliefs, but additionally the scribbles and app algorithms are “beyond the skin”. These external aids are an important part of us and how we think and act. Hence, Clark and Chalmers argue, selves are “best regarded as an extended system, a coupling of biological organism and external resources”.

Sounds psychosocial to me, though developed outside a formal psychosocial studies frame. (Maybe it’s more biopsychomaterial studies?)

Another example comes from Kusch (1999, p. 359), writing in a Science and Technology Studies (STS) tradition. He sketches a familiar story of how social processes shape brains and change how we respond to the world, arguing that therefore

“at least some states of the brain might well be called social states. They are social because they are real artefacts of our culture, and social also because they predispose us to differ in the intensity, quality, and duration of some of our sensations” (emphasis original).

Yet another expression of the interwoven nature of psy and social comes from Erich Fromm (originally published 1932):

“The thesis that psychology only deals with the individual while sociology only deals with ‘society’ is false. For just as psychology always deals with a socialized individual, so sociology always deals with a group of individuals whose psychic structure and mechanisms must be taken into account.”

Though perhaps this particular statement isn’t interwoven enough for “strong” psychosocial.

Critical

An idea that recurs in psychosocial studies is that researchers should develop critical theories. Taking Nancy Fraser’s (1985) conceptualisation (from outside psychosocial studies), there is no empirical difference between a critical and a non-critical theory. There is a clear political difference: a critical theory clarifies processes oppressing a social group and suggests action. It takes as obvious that doing so is important. Jenkins’ (2018) development of a norm-relevancy account of gender is a good example of this genre of critical theorising. Jenkins begins with a statement of the aims of trans rights movements, but does not attempt to justify those aims (Jenkins, 2018, p. 716):

“Although I am fully convinced of the appropriateness of the aims of the trans rights movements, I make no claim to have justified those aims here. I merely seek to establish the concept of gender identity that is required to advance those aims.”

This is critical theory-infused analytical philosophy – outside psychosocial studies.

So WTF is psychosocial studies?

Psychosocial studies is undefinable, in my view. Any attempt will include a huge number of other disciplines (or at least researchers in those disciplines) using psy and social concepts simultaneously. I don’t think it matters; people seem to be able to do their psychosocial research (or philosophy, sociology, art, etc.) without pledging allegiance to the psychosocial, hand on any of the major manifestos. But researchers who want to, say, reduce all societies’ problems to individuals’ characteristics are more likely to be found elsewhere, so the “interwoven” criterion of psy and social does help eliminate some research from the hyperdimensional Euler diagrams.

Keeping an eye on London

Broadcast media tends to be slow at reporting on events, so while you wait you can find clues for what may be going on via:

  • ADSBexchange.com, “the worlds largest co-op of ADS-B/Mode S/MLAT feeders, and the world’s largest public source of unfiltered flight data”
  • Advisory Circular London, “Bot that tweets about aircraft flying in circles over the London area”
  • Webcams of London, e.g., Westminster Bridge and the view from the Shard (looking west and east) – including archived footage
  • TfL JamCam – shows traffic cams from across London, also including archives
  • Twitter search for London

PHQ-9 “over-diagnosis” paper shows that arithmetic works

A recent paper by Levis et al. (2020) systematically reviews studies looking at depression prevalence in two ways: one using a structured assessment completed by a professional (SCID) and the other using a questionnaire completed by study participants (PHQ-9). The authors conclude that “PHQ-9 ≥10 substantially overestimates depression prevalence.” But this was entirely predictable.

Mean SCID-prevalence was 12.1%.

Mean PHQ-9 prevalence (using a score of 10 or above to decide that someone has depression) was 24.6%.

This is almost exactly what arithmetic predicts; my back-of-envelope estimate of what PHQ-9 would say (see below) gives 23.8%, using estimates of PHQ’s sensitivity and sensitivity from a meta-analysis (88% and 85%, respectively) and the SCID-prevalence found in the review (12.1%).

So the paper’s results are unsurprising.

PHQ-9 (and any other screening questionnaire) gives better predictions in groups with higher rates of depression, such as people who have asked for a GP appointment because they are worried about their mental health.

No clinical decisions – such as whether to accept someone for treatment – should be made on the basis of nine tick-box answers alone. Questionnaires can also miss people who need treatment.

Screening questionnaires are often designed to over-diagnose rather than risk missing people who need treatment, under the assumption that a proper follow-up assessment will be carried out.

When reporting condition prevalence, the psychometric properties of measures should be provided, including what “gold standard” they have been validated against, and the chosen clinical threshold.

Explore Positive/Negative Predictive Values (PPV and NPV) using this app.

 

Back of envelope

P(SCID) = .121
P(PHQ | SCID) = .88
P(not-PHQ | not-SCID) = .85
P(PHQ | not-SCID) = 1 – P(not-PHQ | not-SCID) = .15

P(PHQ & SCID) = P(PHQ | SCID) * P(SCID)
= .88 * .121
= .10648

P(PHQ & not-SCID) = P(PHQ | not-SCID) * P(not-SCID)
= (1 – .85) * (1 – .121)
= .13185

P(PHQ) = P(PHQ & SCID) + P(PHQ & not-SCID)
= .10648 + .13185
= 0.23833

 

Thanks Chris, for pointing out the typo!