Skip to content

Instantly share code, notes, and snippets.

View padpadpadpad's full-sized avatar
🙃

Daniel Padfield padpadpadpad

🙃
View GitHub Profile
# load packages
library(nlsLoop)
library(tidyverse) # just need dplyr
# load in data
data(Chlorella_TRC)
# fit nlsLoop object
fits <- nlsLoop(ln.rate ~ schoolfield.high(ln.c, Ea, Eh, Th, temp = K, Tc = 20),
data = Chlorella_TRC,
@padpadpadpad
padpadpadpad / toy_community_TPC.R
Created January 5, 2017 21:37
Looking at how community temperature dependence emerges from simulated species thermal performance curves
# Test hypothesis that activation energy of community is determined from activation energies of its determinants
n = 3
community <- data.frame(expand.grid(temp = seq(275, 305,0.5), curve = c(1:3)))
params <- data.frame(ln.c = c(1.5, 1, 0.5),
Ea = c(0.7, 0.5, 0.3),
Eh = rep(rnorm(n, 3, sd = 0.5)),
Th = c(rnorm(n, 300, sd = 2)),
curve = c(1,2,3))
@padpadpadpad
padpadpadpad / confint_nlsLoop.R
Created January 5, 2017 21:42
Calculate confidence intervals around parameters of an nlsLoop model fit
# function to get confidence intervals
confint_nlsLoop <- function(x, params, data, id_col, formula, ...){
dat <- data[data[,id_col] == x,]
params2 <- params[params[,id_col] == x,]
fit = NULL
try(fit <- minpack.lm::nlsLM(formula,
data = dat,
start = params2[colnames(params2) %in% all.vars(formula[[3]])]), silent = TRUE)
if(!is.null(fit)){
confint <- nlstools::confint2(fit)
structure(list(lat = c(50.16996, 50.16887, 50.16943, 50.17204,
50.17247, 50.17227, 50.17302, 50.17354, 50.17365, 50.17249, 50.17205,
50.17442, 50.17689, 50.1767, 50.17634, 50.17601, 50.17592, 50.17549,
50.17402, 50.17379, 50.17314, 50.17323, 50.17566, 50.17714, 50.17919,
50.18199, 50.18284, 50.1838, 50.18447, 50.18505, 50.1849, 50.18843,
50.1909, 50.19203, 50.19184, 50.19247, 50.19406, 50.19381, 50.19416,
50.1958, 50.19621, 50.19623, 50.19792, 50.19717, 50.1982, 50.19857,
50.19901, 50.19888, 50.19992, 50.20095, 50.19956, 50.19857, 50.1974,
50.19619, 50.19529, 50.19273, 50.19154, 50.1862, 50.18248, 50.18177,
50.17728, 50.17513, 50.17383, 50.17108, 50.17116, 50.17228, 50.17224,
library(dplyr)
library(tidyr)
# create dummy data
Class <- rep(seq(1,3,1),2)
Count <- runif(length(Class),50,100)
Quad_ID <- c(rep("A",3),rep("B",3))
x <- data.frame(Class,Count,Quad_ID)
# load package
library(nlsLoop)
library(nlme)
library(ggplot2)
library(dplyr)
# create dummy data
example <- data.frame(expand.grid(K = 280:330, rep = 1:3))
# create dummy params
@padpadpadpad
padpadpadpad / AskHelp1.R
Last active February 2, 2017 17:39
Example of using R to add columns, filter and create means for groups of data and plot output
# good coding practice ####
# 1. #hashtag your code so you know what it does
# 2. clear workspace and load packages at the top to keep track of what you have loaded
# 3. make sure your working directory is in the right place
# 4. space things out in a way that makes your code readable to you
# 5. google things you do not understand. The answers are out there, go find them
# 6. do not get scared/angry when you get errors. It does get easier.... eventually
# clear workspace #### Good code practice to do first
rm(list = ls())
@padpadpadpad
padpadpadpad / ASKHelp2.R
Last active February 2, 2017 22:01
A simple example of a binomial regression, plotting data and predictions with dplyr and ggplot2
# example of a VERY simple binomial regression ####
# good coding practice (in my opinion anyway!) ####
# 1. #hashtag your code so you know what it does
# 2. clear workspace and load packages at the top to keep track of what you have loaded
# 3. make sure your working directory is in the right place
# 4. space things out in a way that makes your code readable to you
# 5. google things you do not understand. The answers are out there, go find them
# 6. do not get scared/angry when you get errors. It does get easier.... eventually
@padpadpadpad
padpadpadpad / ASKHelp3.R
Last active February 4, 2017 16:19
Some prawns and some colours and some stats
# good coding practice ####
# 1. #hashtag your code so you know what it does
# 2. clear workspace and load packages at the top to keep track of what you have loaded
# 3. make sure your working directory is in the right place
# 4. space things out in a way that makes your code readable to you
# 5. google things you do not understand. The answers are out there, go find them
# 6. do not get scared/angry when you get errors. It does get easier.... eventually
# clear workspace #### Good code practice to do first
rm(list = ls())
@padpadpadpad
padpadpadpad / ASKHelp4.R
Last active February 28, 2021 09:48
Intro to plotting a time series in R and simple tidyverse functions
# good coding practice ####
# 1. #hashtag your code so you know what it does
# 2. clear workspace and load packages at the top to keep track of what you have loaded
# 3. make sure your working directory is in the right place
# 4. space things out in a way that makes your code readable to you
# 5. google things you do not understand. The answers are out there, go find them
# 6. do not get scared/angry when you get errors. It does get easier.... eventually
# clear workspace #### Good code practice to do first
# need to install mise first!