Skip to content

Instantly share code, notes, and snippets.

View padpadpadpad's full-sized avatar
🙃

Daniel Padfield padpadpadpad

🙃
View GitHub Profile
@padpadpadpad
padpadpadpad / weighted_bootstrap_many_curves.R
Last active July 13, 2023 06:53
Runs an example of doing weighted bootstrap regression on many curves using rTPC
# try weighted bootstrapping of many curves
# combines approach from weighted bootstrapping and bootstrapping many curves
# https://padpadpadpad.github.io/rTPC/articles/bootstrapping_many_curves.html
# https://padpadpadpad.github.io/rTPC/articles/weighted_bootstrapping.html
# load in packages
librarian::shelf(tidyverse, rTPC, nls.multstart, broom, minpack.lm, car)
# load in data
data("chlorella_tpc")
@padpadpadpad
padpadpadpad / patchwork_legend_example.R
Last active April 20, 2023 07:57
An example of aligning plots using patchwork and having better control of the legend position.
# example of using cowplot and patchwork to make a plot with legends in the bottom right of a four panel plot
# load in packages
librarian::shelf(tidyverse, patchwork, cowplot)
# make a random plot with colour
p1 <- ggplot(mpg, aes(hwy, cty, col = class)) +
geom_point()
# make other plot with colour on
@padpadpadpad
padpadpadpad / map2_example.R
Created March 22, 2023 11:04
Example of using map2 to pass arguments to a model.
# random modelling example for Stephen
# load in packages
librarian::shelf(rTPC,tidyverse, nls.multstart)
# create data
d <- chlorella_tpc %>%
filter(curve_id < 4) %>%
nest(data = c(everything(), -curve_id))
# compare Gompertz model to Logistical growth model
# load packages
library(tidyverse) #install.packages(tidyverse)
library(zoo) #install.packages(zoo)
library(broom) #install.packages(broom)
library(growthcurver) # install.packages(growthcurver)
library(nls.multstart) # install.packages(nls.multstart)
# remotes::install_github('padpadpadpad/MicrobioUoE)
# muhisse example
# from https://speciationextinction.info/articles/MuHiSSE-vignette.html
# load packages
library(hisse)
library(diversitree)
# simulate simple four state model
pars <- c(.1, .15, .2, .1, # lambda 1, 2, 3, 4
.03, .045, .06, 0.03, # mu 1, 2, 3, 4
# example of map2
# load packages
library(nls.multstart)
library(rTPC)
library(tidyverse)
# load data and keep only 2 curves
data("chlorella_tpc")
d <- chlorella_tpc %>%
# quick and dirty example of not italicising the whole label.
# Italicise certain words only in facet labels in ggplot2
library(tidyverse)
# create random data frame
species <- c('Chlorella sp.', 'Buteo buteo')
d <- tibble(species = species) %>%
group_by(species) %>%
# try and recreate famous Ed Hawkins climate change spiral graphic in R and ggplot2
# load packages
library(tidyverse)
library(MetBrewer)
library(gganimate)
# load in dataset from NASA
d <- read.csv('https://data.giss.nasa.gov/gistemp/tabledata_v4/GLB.Ts+dSST.csv', skip = 1)
head(d)
# nls.multstart example calculating rsquared and RMSE
# load packages
library(nls.multstart)
library(soilphysics)
library(modelr)
# load in data
data("Chlorella_TRC")
@padpadpadpad
padpadpadpad / growthcurver_example.R
Created February 8, 2022 08:58
Keep all the fits from growthcurver on a plate
# load in packages
library(growthcurver)
library(tidyverse)
# load in example data
d <- growthdata # load some sample, simulated data
gc_fit <- SummarizeGrowthByPlate(d) # do the analysis
plot(gc_fit) # plot your data and the best fit
gc_fit$model %>% broom::augment()