knitr::opts_chunk$set(echo = TRUE)

ecostattoolkit

An R package to implement and test the ECOSTAT toolkit for estimating nutrient boundaries.

Implements and tests the ECOSTAT toolkit for estimating nutrient boundaries. R functions have been created that replicate the original scripts by Geoff Phillips.

Installation

ecostattoolkit can be installed directly from GitHub using the install_github function in package devtools

# install.packages("devtools")
devtools::install_github("andrewdolman/ecostattoolkit")

Usage

Required packages

library(ecostattoolkit)
library(dplyr)
library(tidyr)

Read in and prepare data

filename <- system.file("extdata", "DataTemplate_Example1.csv", package = "ecostattoolkit")
dat <- read.csv(filename)

status_boundaries <- c("HG" = 0.8, "GM" = 0.6, "MP" = 0.4)

# min and max nutrient value used for model
nut.min <- 1    
nut.max <- 138  

dat$status <- cut(dat$EQR,
                  breaks = rev(c(Inf, status_boundaries, -Inf)),
                  labels = rev(c("High", "Good", "Moderate", "Poor")))

dat$x.u <- log10(dat$P)
dat$y.u <- dat$EQR

knitr::kable(head(dat))

Estimate boundaries with all methods

dat_sub <- filter(dat, Exclude_P == 0,
                  P <= nut.max,
                  P >= nut.min)

boundaries <- boundaries_all(dat_sub)


boundaries <- dplyr::mutate_if(boundaries, is.numeric, dplyr::funs(round(10^., 0))) %>% 
  select(-MP) 

knitr::kable(boundaries)

Compare with results from scripts in TKit_20170208_CORRECTED

Run script

source(system.file("extdata",
                   "TKit_20170208_CORRECTED/TKit_fit_lin_mod1.R",
                   package = "ecostattoolkit"))
# Collect results
script.res <- data.frame(
  Method = c(rep("OLS1_YonX", 2), rep("OLS2_XonY", 2),
             rep("RMA", 2)),

  Boundary = c("GM", "HG", "GM", "HG",
               "GM", "HG"),

  Value = c(GM.mod1, HG.mod1, GM.mod2, HG.mod2,
            GM.mod4, HG.mod4),
  stringsAsFactors = TRUE)

script.res %>% 
  tidyr::spread(Boundary, Value) %>% 
  dplyr::select(Method, HG, GM) %>% 
  arrange(Method) %>% 
  knitr::kable(.)


andrewdolman/ecostattoolkit documentation built on May 10, 2019, 10:30 a.m.