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

Keybase proof

I hereby claim:

  • I am aammd on github.
  • I am aammd (https://keybase.io/aammd) on keybase.
  • I have a public key ASAjkSpXgWkiID1aVIJksW_plP1S60NKHq3lnNrdFeLD8wo

To claim this, I am signing this object:

library(pageviews)
require(lubridate)
today <- pageview_timestamps()
earlysept <- pageview_timestamps(lubridate::ymd("2017-09-01"))
korsmit <- pageviews::article_pageviews("en.wikipedia", "Roy_Kortsmit", start = earlysept, end = today)
korsmit %>%
ggplot(aes(x = date, y = views)) + theme_minimal() + geom_line() + geom_point() +
labs(title = "Roy Kortsmit wikipedia pageviews", subtitle = "Before and after he made 4 saves in 5s.")
@aammd
aammd / mkrproj.sh
Created January 3, 2018 14:59 — forked from bearloga/mkrproj.sh
A bash shell script that can be used to turn the current directory into an RStudio project, opening the project in RStudio after creating it.
#!/bin/bash
# Usage: mkproj [projectname]
# projectname defaults to name of current directory
template="Version: 1.0\nRestoreWorkspace: Default\nSaveWorkspace: Default\nAlwaysSaveHistory: Default\n\nEnableCodeIndexing: Yes\nUseSpacesForTab: Yes\nNumSpacesForTab: 4\nEncoding: UTF-8\n\nRnwWeave: knitr\nLaTeX: pdfLaTeX"
wd=$(basename `pwd`)
if [ -z $1 ]; then
library(brms)
library(tidyverse)
# we're going to have 5 animals
nspp <- 5
# in 100 sites
nsites <- 100
#abilities are between -1 and 1, from a normal distribution:
thetas <- rnorm(nspp, 0, 1.2)
@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)
@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 / 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 / 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
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")
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() +