{{ message }}

Instantly share code, notes, and snippets.

# Andrew MacDonald aammd

• Université de Sherbrooke
Last active Mar 10, 2021
Minimal shiny app to simulate priors on a logit scale
View prior_on_logit_scale.R
 library(shiny) library(bslib) library(thematic) library(ggplot2) thematic::thematic_shiny(font = "auto") # take a vector, make a histogram
Created Nov 28, 2020
Inspired by Peskun 2016 http://arxiv.org/abs/1610.07554
View binomial_vs_beta.md
```library(tidyverse)
#> Warning: package 'tibble' was built under R version 4.0.2
#> Warning: package 'tidyr' was built under R version 4.0.2
#> Warning: package 'dplyr' was built under R version 4.0.2
tibble(x = 0:42,
y1 = pbinom(x, 42, 0.3),
y2 = 1-pbeta(0.3, x+1, 42-x)) %>%
ggplot(aes(x = x, y = y1)) +
geom_point(col = "green", size = 3) + ```
Created May 18, 2020
tidyverse translation of Tim's demo on data manipulation
View example_data_manipulation.Rmd
 --- title: "Exploring observations" author: "Andrew, based on Tim's lecture!" date: "18/05/2020" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk\$set(echo = TRUE) ```
Created May 14, 2020
View curve_species.R
 m <- 0.086 o <- (1-m)/m curve((sqrt(o) - sqrt(o^-1)) / sqrt(x^2 - x + 1), xlim = c(0,50)) abline(h = 1/3)
Created Mar 15, 2020
View function_cv_plot.md
```library(tidyverse)
cv <- 2.5
sigma = seq(0.2,5,by = 0.2)
list(mean = sigma / cv, sd = sigma) %>% transpose %>%
set_names(., nm = map_chr(., lift_dl(paste, sep="_"))) %>%
map(lift_dl(partial, .f = dnorm)) %>%
map_df(~ tibble(x = seq(-2,3.5,0.01),
y = .x(x)), .id = "mean_sd") %>%
ggplot(aes(x = x, ymax = y, ymin = 0, fill = mean_sd)) + geom_ribbon() +```
Last active Feb 20, 2020
View beta_binomial_power.R
 pwr <- function(S, a, mu = 0.086, phi=240){ D <- S * (S - 1) 2 * (D + 1) * (D/(phi + 1) + 1) * mu * ( 1 - mu) + ( a * mu + mu) * (1 - a * mu - mu) * (2.8)^2 / ((D + 1)*a*mu)^2 } pwr(6, 0.10) curve(pwr(x, 0.4), xlim = c(3,30)) curve(pwr(x, 0.2), xlim = c(3,30), log = "y")
Created Nov 22, 2018
drawing a bifurcation diagram in Julia
View bifurcation.jl
 using Plots # a vector of r values Rs=collect(0.1:0.001:3) T = 5000 N=zeros(length(Rs), T) #Set t0 values to 1 N[:,1] .= 1
Created Oct 9, 2018
info.R
View info.R
 info <- function(x, a, b) { a * (exp(a * (x - b))) / (exp(a * b) + exp(a * x)) ^ 2 }
Created Jun 28, 2018
simulate relationships from a logistic curve, about Dragons because why not
View simulate_logistic.R
 library(tidyverse) set.seed(4812) islands <- data_frame(area = # runif(35, min = 0, max = 29) rlnorm(35, meanlog = log(5), sdlog = log(3)) ) dragon_response <- function(b0, b1){ force(b0) force(b1)
Created May 27, 2018
simulating a fake dataset
View simulate_one_cardoso.R
 simulate_one_cardoso <- function(.cardoso_island = cardoso_island){ spp_names <- unique(.cardoso_island\$morphospecies) nspp <- length(spp_names) bromeliad_names <- unique(.cardoso_island\$Bromeliad) nbrom <- length(bromeliad_names) # simulate from the parameters: b_intercept <- rnorm(1, 1, 0.2)