Created
June 30, 2021 18:04
-
-
Save FlukeAndFeather/04b2b18438a5aa97e038933599021659 to your computer and use it in GitHub Desktop.
How unlikely was it to randomly generate 24/25 points in mussels in a quadrat photo?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggrepel) | |
library(tidyverse) | |
# These were my measurements for mussel area and quadrat area respectively | |
musselfrac <- 0.043 / 0.097 | |
# dbinom() is the probability of n successes out of x trials with probability p | |
# So dbinom(0:25, 25, musselfrac) is the chance of: [0 points in mussels, 1 | |
# point in mussels, 2 points in mussels, ..., 25 points in mussels] | |
musselprobs <- tibble(n = 0:25, | |
p = dbinom(0:25, 25, musselfrac)) | |
# This is the probability of 24/25 points in mussels | |
outlier <- tibble(n = 24, | |
p = dbinom(24, 25, musselfrac), | |
# sprintf() is a function for formatting text | |
l = sprintf("p(24) = %0.2e", p)) | |
# This creates a plot of the probabilities of the number of points in mussels | |
ggplot(musselprobs, aes(x = n, y = p)) + | |
# Vertical segments | |
geom_segment(aes(xend = n, yend = 0)) + | |
# Hollow red points | |
geom_point(color = "red", shape = 21) + | |
# Label the outlier (notice the label aesthetic and outlier data) | |
geom_text_repel(aes(label = l), data = outlier, | |
# Nudge up a little bit for clarity | |
nudge_y = 0.03) + | |
# Axis labels | |
labs(x = "Number of points in mussels", | |
y = "Probability") + | |
# A cleaner theme than the default | |
theme_bw() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment