Skip to content

Instantly share code, notes, and snippets.

View padpadpadpad's full-sized avatar
🙃

Daniel Padfield padpadpadpad

🙃
View GitHub Profile
@padpadpadpad
padpadpadpad / ASKHelp5.R
Last active September 5, 2017 15:29
A very simple poisson glm, use of some dplyr, tidyr and ggplot2 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!
@padpadpadpad
padpadpadpad / ASKHelp6.R
Last active March 1, 2017 23:11
Binomial regression on presence_absence data - lots of data wrangling and use of dplyr, tidyr and ggplot2
# 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!
@padpadpadpad
padpadpadpad / ASKHelp7.R
Created March 4, 2017 12:08
Simple linear model and use of dplyr tidyr and ggplot2
# 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!
@padpadpadpad
padpadpadpad / ASKHelp8.R
Last active November 23, 2020 23:49
Random intercept and slope linear mixed effect model with examples of dplyr, tidyr and ggplot2 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!
@padpadpadpad
padpadpadpad / Sarah_Paul_dplyr.R
Created April 8, 2017 22:51
Some dplyr-ing late on a Saturday
# load packages
library(dplyr)
library(tidyr)
# proportion dead of 10
prop = c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1)
# create dummy data
d <- data.frame(tube = 1:10, prop = sample(prop, 10, replace = TRUE))
@padpadpadpad
padpadpadpad / Sam_dplyr_predictions.R
Created May 16, 2017 15:46
Getting predictions on a every level of a grouped dataset
# load in packages
library(nlsLoop)
library(dplyr)
library(tidyr)
# load up Chlorella data
data('Chlorella_TRC')
head(Chlorella_TRC)
@padpadpadpad
padpadpadpad / bootstrap_lm.R
Last active May 22, 2017 10:32
Testing a slope (or any other coefficient) of a linear model to a given value using bootstrapping
# test slope against defined value other than 0
# load packages
library(car)
library(ggplot2)
library(dplyr)
# create made up data
# set up gradient (grad) intercept (intercept) and standard deviation (sigma)
intercept = 10
@padpadpadpad
padpadpadpad / size_comm_example_stan.R
Last active June 1, 2017 09:23
stan model using log_exp_sum()
rm(list = ls())
# Stan message board example
library(tidyverse)
library(magrittr)
library(rstan)
d <- data.frame(ln_rate = c(1,1.5,3,5), temp = c(4, 5, 6, 7), group = c(0,0,1,1))
b <- data.frame(temp = c(4,4,4,5,5,5,5,5,6,6,6, 7,7,7,7,7)) %>%
@padpadpadpad
padpadpadpad / vegan_PCA_ggplot_example.R
Last active July 24, 2024 16:59
Example for plotting prcomp() and betadisper() models in ggplot2
# creating pretty plots from prcomp and vegan in R
# clear workspace
mise::mise(vars = TRUE, pkgs = TRUE, console = TRUE, figs = TRUE)
# can do multiple comparisons of adonis factors
# devtools::install_github('leffj/mctoolsr')
# load in packages
library(vegan)
@padpadpadpad
padpadpadpad / footgolf_scores.R
Last active August 28, 2017 13:04
Some visualisations of our footgolf
# Footgolf scores
# packages
library(dplyr)
library(tidyr)
library(ggplot2)
library(ggjoy)
# Input data
footgolf <- data.frame(player = rep(c('George', 'Colin', 'Paddy', 'Silky'), each = 18), scores = c(4, 6, 4, 4, 5, 4, 2, 3, 5, 4, 4, 6, 3, 7, 5, 5, 5, 4, 3, 5, 5, 3, 3, 3, 3, 3, 6, 2, 4, 5, 3, 5, 4, 3, 5, 5, 4, 4, 5, 3, 3, 5, 4, 3, 4, 4, 5, 4, 3, 3, 4, 3, 7, 4, 4, 5, 5, 3, 2, 3, 4, 4, 6, 3, 4, 5, 3, 1, 5, 4, 3, 5), stringsAsFactors = FALSE)