Articles by mrtnj

Simulating shared segments between relatives

February 6, 2022 | mrtnj

A few months ago I saw this nice figure from Amy Williams of the number of DNA segments that are expected to be shared between relatives. I thought it would be fun to simulate segment sharing with AlphaSimR. Because DNA comes in chromosomes that don’t break up and recombine ...
[Read more...]

Using R: plyr to purrr, part 1

August 8, 2021 | mrtnj

This is the second post about my journey towards writing more modern Tidyverse-style R code; here is the previous one. We will look at the common case of taking subset of data out of a data frame, making some complex R object from them, and then extracting summaries from those ...
[Read more...]

A plot of genes on chromosomes

July 25, 2021 | mrtnj

Marta Cifuentes and Wayne Crismani asked on Twitter if there is a web tool similar to the Arabidopsis Chromosome Map Tool that makes figures of genes on chromosomes for humans. This will not really be an answer to the question — not a web tool, not conveniently packaged — but I thought ...
[Read more...]

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...]
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)