Mermin’s (1981) variant of Bell’s theorem – in R

Entanglement is the weirdest feature of quantum mechanics. David Mermin (1981) provides an accessible introduction to experiments showing that local determinism doesn’t hold in the quantum world, simplifying Bell’s theorem and tests thereof. This knitted Markdown file shows the sums in R. It’s probably only going to make sense if you have been here before, but hadn’t got around to doing the sums yourself (that was me, before writing this today!).

Hypothesis testing for categorical predictors

Interesting update to {ggeffects}, by Daniel Lüdecke:

A reason to compute adjusted predictions (or estimated marginal means) is to help understanding the relationship between predictors and outcome of a regression model. In particular for more complex models, for example, complex interaction terms, it is often easier to understand the associations when looking at adjusted predictions instead of the raw table of regression coefficients.

The next step, which often follows this, is to see if there are statistically significant differences. These could be, for example, differences between groups, i.e. between the levels of categorical predictors or whether trends differ significantly from each other.

The ggeffects package provides a function, hypothesis_test(), which does exactly this: testing differences of adjusted predictions for statistical significance. This is usually called contrasts or (pairwise) comparisons. This vignette shows some examples how to use the hypothesis_test() function and how to test whether differences in predictions are statistically significant.

Read more.

Associations between gender and sexuality in the England and Wales 2021 Census

ONS recently released data about sexual orientation and gender identity from Census 2021 in England and Wales.

I’d like to know whether your gender predicts your sexuality. ONS hasn’t released the relevant crosstabs yet, so here’s an approximation using variation in population counts across (lower-tier) local authorities.

Beware the ecological fallacy, e.g., this might show that areas with more people of a particular gender also have more people of a particular sexuality, but not necessarily that they are the same people.

Knitted R markdown over there. If you improve it, let me know please.

A picture:

Green denotes a positive association and red a negative association. The width of the line denotes the association strength.

  • Het = Straight or Heterosexual
  • GL = Gay or Lesbian
  • Bi = Bisexual
  • Pan = Pansexual
  • Ace = Asexual
  • Q = Queer
  • Cis = Gender identity the same as sex registered at birth
  • TM = Trans man
  • TW = Trans woman
  • NBi = Non-binary

This Be The Worse

Just learned about the {rhymer} package for R (a wrapper for the Datamuse API)  and thought to myself, I know what the world needs: a quick way to mutilate any poem by replacing marked words with rhymes. Here’s an example output:

This Be The Worse

They duck you up, your bum and dyad.
They may not mean to, but they do.
They fill you with the schmaltz they had
And add some extra, just for two.

But they were construct up in their turn
By fools in old-style cats and anecdotes,
Who half the time were soppy sunburn
And half at one another’s quotes.

Man hands on misery to man.
It deepens like a coastal elf.
Get out as early as you can,
And don’t have any eyelids yourself.

(The metre isn’t ideal.)

Code over there.

Mastodon and R

Encoding binary data in hashtags

Problem: you want to encode arbitrary binary data as a hashtag on Mastodon or another social media platform.

A solution: transform to a hex string and shift the \(0, 1, 2 \ldots, f\) up to \(a, b, c \ldots, p\) so all the bytes are lowercase Latin characters.

Example: #gihehehahddkcpcphhhhhhcohjgphfhehfgcgfcogdgpgncphhgbhegdgidphgdngefbhhdehhdjfhghfigdfb

Repo here

Accessing the Mastodon API via {rtoots}

I was curious to know if there’s a positive correlation between the total number of users on a server and how many followers I have from that server. {rtoots} to the rescue…

Repo here