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
# de Finetti diagram | |
library(dplyr) | |
library(ggplot2) | |
library(ggtern) | |
library(magrittr) | |
HWEfrequencies <- data.frame( | |
p = seq(0, 1, 0.01) | |
) %>% | |
mutate(q = 1 - p) %>% |
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
#I first simulate a dataset to use for this example | |
set.seed(123) | |
years <- 2013:2015 | |
n <- 100 | |
df1 <- data.frame(year = rep(years, each = n), | |
eggdate = c(rnorm(n, 40, 4), | |
rnorm(n, 45, 5), | |
rnorm(n, 67, 7))) | |
#Make sure year is coded as a "factor" |
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
#Packages | |
library(ggplot2) | |
#Read in some data for the example | |
#THe data are grade data and acceptance in to grad school. | |
#GRE (Graduate Record Exam scores), GPA (grade point average) | |
mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv") | |
head(mydata) | |
summary(mydata) | |
mylogit <- glm(admit ~ gre + gpa + gre:gpa, data = mydata, family = "binomial") |
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
#offsets | |
#Simulate some data for this example | |
set.seed(12) | |
sig <- matrix(c(1.1,1,1,1.1),2,2) | |
df1<-data.frame(MASS::mvrnorm(n = 100, c(30,30), Sigma = sig )) | |
names(df1) <- c("x","y") | |
#Plot the data, and a 1:1 line | |
plot(df1$x,df1$y) | |
abline(0,1) |
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
#How to subset the matrix database based on the matrices themselves. | |
#This example counts NA values in the F matrix and uses that to subset. | |
nmat <- nrow(compadre$metadata) | |
for(i in 1:nmat){ | |
compadre$metadata$NAinFmat[i] <- sum(is.na(compadre$mat[[i]]$matF)) | |
} | |
table(compadre$metadata$NAinFmat) | |
x <- Rcompadre::subsetDB(compadre,NAinFmat == 0) |
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
#bar heights | |
x<- c(1,2,3,2,4) | |
#standard error values | |
sem <- c(.5,.4,.2,.4,.2) | |
#bar labels | |
lab <- c("A","B","C","D","E") |
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
par(mar=c(1,1,1,1)) | |
plot(x = rep(1:5,5),y = rep(1:5,each=5),pch=1:25,col="black",bg="yellow",axes=F,xlab="",ylab="", | |
cex=2,xlim=c(0,5.5),ylim=c(0,5.5)) | |
text(x = rep(1:5,5),y = rep(1:5,each=5),text=1:25,pos=2,cex=.8) |
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
#How to subset the COMADRE Animal Matrix Database (works with COMPADRE too) | |
#Create a vector of indices to retain | |
subsetID <- which(comadre$metadata$Order %in% c("Monotremata","Didelphimorphia","Paucituberculata","Microbiotheria","Dasyurormorphia","Peramelemorphia","Diprotodontia")) | |
#Subset entire COMADRE object to JUST the above subset | |
#First make a copy | |
subset.comadre <- comadre |
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
palettebuildr <- function(pathToJPEG = "logo.jpg", ncols = 3, dist.method = "euclidian", clust.method = "complete"){ | |
require(jpeg) | |
#Read in the jpeg file | |
img <- readJPEG(pathToJPEG) | |
#Using the whole image is overkill, especially for large files. | |
#Therefore, create a grid from which extract the colors | |
xgrid <- ceiling(seq(1, dim(img)[1], length.out = 50)) | |
ygrid <- ceiling(seq(1, dim(img)[2], length.out = 50)) |
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
#Stochastic geometric population growth rate | |
#Simulation settings | |
pgr = 1.05 | |
var.pgr = 0.1 | |
startPop = 10 | |
nGen = 100 | |
ntrials = 1000 | |
pseudoExtinction = 1 |
NewerOlder