leppott / XC95

Extirpation analysis (XC95) for benthic macroinvertebrates and fish for environmental variables.
https://leppott.github.io/XC95/
0 stars 2 forks source link

HC05 calc #11

Closed leppott closed 4 years ago

leppott commented 4 years ago

Is your feature request related to a problem? Please describe. Not a separate function. Basic calculation.

The HC05 is the 5th percentile hazardous concentration of a set of related 95th percentile extirpation concentration values (XC95). The HC05 is the estimated value of the stressor at which 5% of species will be extirpated.

Describe the solution you'd like Pulled from BC paper code, March 2017 and some other files from June 2016.

Describe alternatives you've considered Add as an example

Additional context Run example for fish.wt.cdf to get XC95 values.

# data
data(dta.do)
data(ss.sites)
# run function (~20 seconds)
dftv.do <- fish.wt.cdf(datafile = dta.do, ss = ss.sites, plot = T, dogam = T
                      , SampleID = "Station_Date", tag = "wt", sortvect = NULL
                      , np = 61, nt = 25, addtrend = T
                      , wd = getwd(), groups = c("BigHUC","ECOREGL3","WS_AREA")
                      , xvar = "cond")
View(dftv.do)
knitr::kable(head(dftv.do))
GENUS XC95.cdf trend XC95.gam total.n total.N HUC eco3 wtshed
26 Etheostoma baileyi 322 = 501 38 1729 500 70_69_68 1.8_353
78 Noturus insignis 351 = 347 208 3259 204_205_207_208_301_500_601 67_69 19.597_8336.5394
22 Erimyzon oblongus 382 = 443 26 3232 204_205_207_208_500 70_67_69 4.3934_493.1524
25 Esox niger 467 ~ 672 63 1503 204_205_207_208 67_69 3.4644_742.9773
98 Salvelinus fontinalis 508 = 639 1361 3215 204_205_207_500 67_69_70 1.4111_395.4895
16 Cottus girardi 518 ~ 672 31 1085 205_207 67 2.0236_594.457

Then calculate the 5th quantile.

hc05_cdf <- quantile(dftv.do$XC95.cdf, probs = 0.05, na.rm = TRUE, type = 6)
hc05_gam <- quantile(dftv.do$XC95.gam, probs = 0.05, na.rm = TRUE, type = 6)
# both at once
hc05_both <- apply(dftv.do[, c("XC95.cdf", "XC95.gam")], 2
    , quantile, probs=0.05, na.rm=TRUE, type=6)

image

leppott commented 4 years ago

https://github.com/leppott/XC95/commit/8b0e51418f036b341904f8d83bc2a2ebec0c624f

v0.0.2.9003