Skip to content

Instantly share code, notes, and snippets.

View aammd's full-sized avatar

Andrew MacDonald aammd

  • Université de Sherbrooke
  • Montreal, Canada
View GitHub Profile
@aammd
aammd / prior_on_logit_scale.R
Last active March 10, 2021 15:34
Minimal shiny app to simulate priors on a logit scale
library(shiny)
library(bslib)
library(thematic)
library(ggplot2)
thematic::thematic_shiny(font = "auto")
# take a vector, make a histogram
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) + 
@aammd
aammd / example_data_manipulation.Rmd
Created May 18, 2020 15:33
tidyverse translation of Tim's demo on data manipulation
---
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)
```
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)
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() +
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")
@aammd
aammd / bifurcation.jl
Created November 22, 2018 19:44
drawing a bifurcation diagram in Julia
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
@aammd
aammd / info.R
Created October 9, 2018 02:43
info.R
info <- function(x, a, b) {
a * (exp(a * (x - b))) / (exp(a * b) + exp(a * x)) ^ 2
}
@aammd
aammd / simulate_logistic.R
Created June 28, 2018 11:34
simulate relationships from a logistic curve, about Dragons because why not
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)
@aammd
aammd / simulate_one_cardoso.R
Created May 27, 2018 13:23
simulating a fake dataset
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)