Skip to content

Instantly share code, notes, and snippets.

View TonyLadson's full-sized avatar

Tony Ladson TonyLadson

View GitHub Profile
####################################################################
#
# Influence of shape factor in regional flood estimation
# See https://tonyladson.wordpress.com/2016/04/13/shape-factor-in-regional-flood-estimation/
#
####################################################################
# Plot of shape factor distribution
@TonyLadson
TonyLadson / FindP3Params.R
Created April 18, 2016 01:37
Find parameters of the Pearson III distribution given three quantile values
# Find parameters of the Pearson III distribution given three quantile values
# Function for the Pearson III frequency factor
# details at https://tonyladson.wordpress.com/2015/03/10/frequency-factors-2/
Ky_gamma <- function(g, aep){
if(abs(g) < 1e-8) { # Use the Wilson-Hilferty approximation to avoid numerical
# issues near zero
#remove(list = objects())
library(stringr)
library(dplyr)
library(ggplot2)
library(devtools)
library(readr)
library(repmis)
###########################################################################################
#
# Fitting non-linear models in R
# See tonyladson
#
# 5 June 2016
###############################################################################################
#
# Example data come from Figure 5 from Ian Cordery's thesis
# Also Figure 3 from Cordery, 1970
# Confidence intervals for the mean for non-normal data
# See https://tonyladson.wordpress.com/2016/01/11/plotting-water-quality-samples-on-a-hydrograph/
# Modified Cox function for calculating confidence intervals for the mean
# Based on Olsson, 2005
# http://www.amstat.org/publications/jse/v13n1/olsson.html
# x is a set of log-normal data
library(stringr)
library(readr)
library(dplyr)
library(lubridate)
library(ggplot2)
library(scales)
library(treemap)
#__________________________________________________________________________________________
@TonyLadson
TonyLadson / Calc_DOSat.R
Last active August 9, 2016 11:38
Function to calculate 100% saturated dissolved oxygen in mg/L as a function of temperature in degrees Celcius
# Function to calculate 100% saturated dissolved oxygen in mg/L as a function of temperature in degrees Celcius
Calc_DOsat100 = function(temp){
# temp = temperature in degrees C
# relationship between temperature and dissolved oxygen as defined by the APHA
# American Public Health Association (1992)
# Standard methods for the examination of water and wastewater. 18th ed. Washington DC.
# Required constants
@TonyLadson
TonyLadson / Calc_DOsat100.R
Created August 14, 2016 22:01
Function to calculate 100% saturated dissolved oxygen in water in mg/L as a function of temperature in degrees Celcius
# Function to calculate 100% saturated dissolved oxygen in water in mg/L as a function of temperature in degrees Celcius
Calc_DOsat100 = function(temp){
# temp = temperature in degrees C
# relationship between temperature and dissolved oxygen as defined by the APHA
# American Public Health Association (1992)
# Standard methods for the examination of water and wastewater. 18th ed. Washington DC.
# Required constants
@TonyLadson
TonyLadson / Time_convert.R
Created August 18, 2016 04:20
Convert from HH:MM:SS to fractions of a day.
# Convert from 'HH:MM:SS' to fractions of a day
# This also works with HH.HHHH
# and is vectorised
Time_convert <- function(x){
f <- function(x,y){
as.numeric(x)/60 + as.numeric(y)
}
split_time <- str_split(x, ':')
@TonyLadson
TonyLadson / Count_censored.R
Created August 22, 2016 02:35
Function to count the number of censored values in columns of a data frame. Counts the occurrence of '<' and '>'
Count_censored <- function(my.df) {
# number left censored
.Count_leftCensored <- function(x) {
sum(str_detect(x, '[<]'), na.rm = TRUE)
}
.Count_rightCensored <- function(x) {
sum(str_detect(x, '[>]'), na.rm = TRUE)
}