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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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)
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 / 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(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 / boot_reg.md
Last active August 31, 2017 03:12
bootstrapping regressions with `dplyr`.

Bootstrap confidence intervals for linear and nonlinear models

Another version of this gist with figures included is on Rpubs

Recently I was trying to put confidence intervals on a regression line, and I got some excellent advice from @davidjayharris on Twitter, who suggested the below method in an excellent

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:

@aammd
aammd / gist:f566a3eafc6ee293d234b32812f3b2bb
Created March 10, 2017 09:30
plotting with a function factory
rmax <- function(rm, baserate){
force(rm)
force(baserate)
function(x) {
rm * x / (
(rm / baserate) + x
)
}
}