Articles by mrtnj

Convincing myself about the Monty Hall problem

May 17, 2021 | mrtnj

Like many others, I’ve never felt that the solution to the Monty Hall problem was intuitive, despite the fact that explanations of the correct solution are everywhere. I am not alone. Famously, columnist Marilyn vos Savant got droves of mail from people trying to school her after she had ...
[Read more...]

Showing a difference in mean between two groups, take 2

May 9, 2021 | mrtnj

A couple of years ago, I wrote about the paradoxical difficulty of visualising a difference in means between two groups, while showing both the data and some uncertainty interval. I still feel like many ills in science come from our inability to interpret as simple comparison of means. Anything with ...
[Read more...]

A genetic mapping animation in R

April 11, 2021 | mrtnj

Cullen Roth posted a beautiful animation of quantitative trait locus mapping on Twitter. It is pretty amazing. I wanted to try to make something similar in R with gganimate. It’s not going to be as beautiful as Roth’s animation, but it will use the same main idea of ...
[Read more...]

A model of polygenic adaptation in an infinite population

January 24, 2021 | mrtnj

How do allele frequencies change in response to selection? Answers to that question include ”it depends”, ”we don’t know”, ”sometimes a lot, sometimes a little”, and ”according to a nonlinear differential equation that actually doesn’t look too horrendous if you squint a little”. Let’s look at a ...
[Read more...]

Twin lambs with different fathers

July 12, 2020 | mrtnj

I just learned that in sheep, lambs from the same litter pretty often have different fathers, if the ewe has mated with different males. Berry et al. (2020) looked at sheep flocks on Irland that used more than one ram, and: Of the 539 pairs of twins included in the analysis, 160 (i....
[Read more...]

Using R: setting a colour scheme in ggplot2

May 17, 2020 | mrtnj

Note to self: How to quickly set a colour scheme in ggplot2. Imagine we have a series of plots that all need a uniform colour scale. The same category needs to have the same colour in all graphics, made possibly with different packages and by different people. Instead of hard-coding ...
[Read more...]

Using R: simple Gantt chart with ggplot2

March 7, 2020 | mrtnj

Jeremy Yoder’s code for a simple Gantt chart on the Molecular Ecologist blog uses geom_line and gather to prepare the data structure. I like using geom_linerange and a coord_flip, which lets you use start and end columns directly without pivoting. Here is a very serious data ...
[Read more...]

Using R: 10 years with R

March 1, 2020 | mrtnj

Yesterday, 29 Feburary 2020, was the 20th anniversary of the release R 1.0.0. Jozef Hajnala’s blog has a cute anniversary post with some trivia. I realised that it is also (not to the day, but to the year) my R anniversary. Today is the 20th anniversary of the release of R 1.0.0. pic.... [Read more...]

Using R: from plyr to purrr, part 0 out of however many

February 11, 2020 | mrtnj

This post is me thinking out loud about applying functions to vectors or lists and getting data frames back. Using R is an ongoing process of finding nice ways to throw data frames, lists and model objects around. While tidyr has arrived at a comfortable way to reshape dataframes with ... [Read more...]

Using R: Installing GenABEL and RepeatABEL

November 24, 2019 | mrtnj

GenABEL is an R package for performing genome-wide association with linear mixed models and a genomic relationship matrix. RepeatABEL is a package for such genome-wide association studies that also need repeated measures. Unfortunately, since 2018, GenABEL is not available on CRAN anymore, because of failed checks that were not fixed. (Checks ... [Read more...]

Using R: From gather to pivot

November 17, 2019 | mrtnj

Since version 1.0.0, released in September, the tidyr package has a new replacement for the gather/spread pair of functions, called pivot_longer/pivot_wider. (See the blog post about the release. It can do a lot of cool things.) Just what we needed, another pair of names for melt/cast, ... [Read more...]

#TidyTuesday: horror films, squirrels and commuters

November 10, 2019 | mrtnj

Tidy Tuesday is a fun weekly activity where a lot of R enthusiasts make different visualisations, and possibly modelling, of the same dataset. You can read more about it at their Github page. I participated for three weeks, and here is a recap. I will show excerpts of the code, ...
[Read more...]

Exploratory analysis of a banana

November 3, 2019 | mrtnj

This post is just me amusing myself by exploring a tiny data set I have lying around. The dataset and the code is on Github. In 2014 (I think), I was teaching the introductory cell biology labs (pictures in the linked post) in Linköping. We were doing a series of ...
[Read more...]

Using R: Animal model with simulated data

October 13, 2019 | mrtnj

Last week’s post just happened to use MCMCglmm as an example of an R package that can get confused by tibble-style data frames. To make that example, I simulated some pedigree and trait data. Just for fun, let’s look at the simulation code, and use MCMCglmm and AnimalINLA ...
[Read more...]

What single step does with relationship

May 28, 2019 | mrtnj

We had a journal club about the single step GBLUP method for genomic evaluation a few weeks ago. In this post, we’ll make a few graphs of how the single step method models relatedness between individuals. Imagine you want to use genomic selection in a breeding program that already ...
[Read more...]

Using R: plotting the genome on a line

March 31, 2019 | mrtnj

Imagine you want to make a Manhattan-style plot or anything else where you want a series of intervals laid out on one axis after one another. If it’s actually a Manhattan plot you may have a friendly R package that does it for you, but here is how to ...
[Read more...]

Showing a difference in means between two groups

January 13, 2019 | mrtnj

Visualising a difference in mean between two groups isn’t as straightforward as it should. After all, it’s probably the most common quantitative analysis in science. There are two obvious options: we can either plot the data from the two groups separately, or we can show the estimate of ...
[Read more...]
1 2 3 4

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)