The manager
packages provides functions for reading external data.
Example data sets for groundwater in Indiana and Ohio are provided with the package
Prediction Intervals
data("gw_data")
wells <- c("MW-1", "MW-2", "MW-3", "MW-4")
params <- c("Sulfate, total",
"Arsenic, dissolved",
"Boron, dissolved")
background <- lubridate::ymd(c("2007-12-20", "2012-01-01"), tz = "UTC")
# first group data by location, param, and background
# estimate percent less than
background_data <- gw_data %>%
filter(location_id %in% wells, param_name %in% params,
sample_date >= background[1] & sample_date <= background[2]) %>%
group_by(location_id, param_name, default_unit) %>%
percent_lt() %>%
est_dist(., keep_data_object = TRUE) %>%
arrange(location_id, param_name)
pred_int <- background_data %>%
mutate(pred_int = case_when(
distribution == "Normal" ~ map(.x = data,
~EnvStats::predIntNorm(x = .x$analysis_result)),
distribution == "Lognormal" ~ map(.x = data,
~EnvStats::predIntLnorm(x = .x$analysis_result)),
distribution == "Nonparametric" ~ map(.x = data,
~EnvStats::predIntNpar(x = .x$analysis_result))
)
)
pred_int_table <- pred_int %>%
mutate(distribution = distribution,
sample_size = map(.x = pred_int, ~ .x$sample.size),
lpl = map(.x = pred_int, ~ .x$interval$limits["LPL"]),
upl = map(.x = pred_int, ~ .x$interval$limits["UPL"]),
conf_level = map(.x = pred_int, ~ .x$interval$conf.level)) %>%
select(-data, -pred_int) %>%
unnest()
## Warning: `cols` is now required.
## Please use `cols = c(sample_size, lpl, upl, conf_level)`
MW-1 |
ug/L |
Arsenic, dissolved |
Nonparametric |
14 |
1.1000000 |
10.0000000 |
0.8666667 |
MW-1 |
mg/L |
Boron, dissolved |
Nonparametric |
14 |
0.0800000 |
1.3700000 |
0.8666667 |
MW-1 |
mg/L |
Sulfate, total |
Nonparametric |
14 |
15.0000000 |
117.0000000 |
0.8666667 |
MW-2 |
ug/L |
Arsenic, dissolved |
Nonparametric |
14 |
1.0000000 |
10.0000000 |
0.8666667 |
MW-2 |
mg/L |
Boron, dissolved |
Lognormal |
14 |
1.7298714 |
2.5721482 |
0.9500000 |
MW-2 |
mg/L |
Sulfate, total |
Nonparametric |
14 |
158.0000000 |
200.0000000 |
0.8666667 |
MW-3 |
ug/L |
Arsenic, dissolved |
Nonparametric |
14 |
0.4000000 |
10.0000000 |
0.8666667 |
MW-3 |
mg/L |
Boron, dissolved |
Lognormal |
14 |
1.0454563 |
1.8718412 |
0.9500000 |
MW-3 |
mg/L |
Sulfate, total |
Lognormal |
14 |
109.0915641 |
163.9923875 |
0.9500000 |
MW-4 |
ug/L |
Arsenic, dissolved |
Normal |
14 |
-0.0334501 |
12.8334501 |
0.9500000 |
MW-4 |
mg/L |
Boron, dissolved |
Normal |
14 |
-0.0616289 |
0.8947718 |
0.9500000 |
MW-4 |
mg/L |
Sulfate, total |
Nonparametric |
14 |
22.1000000 |
120.0000000 |
0.8666667 |
Confidence Intervals
conf_int <- background_data %>%
mutate(conf_int = case_when(
distribution == "Normal" ~ map(.x=data,
~EnvStats::enorm(x = .x$analysis_result,
ci = TRUE, ci.type = "lower",
conf.level = 0.99,
ci.param = "mean")),
distribution == "Lognormal" ~ map(.x = data,
~EnvStats::elnormAlt(x = .x$analysis_result,
ci = TRUE, ci.type = "lower",
ci.method = "land",
conf.level = 0.99)),
distribution == "Nonparametric" ~ map(.x = data,
~EnvStats::eqnpar(x = .x$analysis_result,
ci = TRUE, ci.type = "lower",
ci.method = "interpolate",
approx.conf.level = 0.99))
)
)
conf_int_table <- conf_int %>%
mutate(distribution = distribution,
sample_size = map(.x = conf_int, ~ .x$sample.size),
lcl = map(.x = conf_int, ~ round(.x$interval$limits["LCL"], 3)),
ucl = map(.x = conf_int, ~ .x$interval$limits["UCL"]),
conf_level = map(.x = conf_int, ~ .x$interval$conf.level)) %>%
select(-data, -conf_int) %>%
unnest()
## Warning: `cols` is now required.
## Please use `cols = c(sample_size, lcl, ucl, conf_level)`
MW-1 |
ug/L |
Arsenic, dissolved |
Nonparametric |
14 |
1.500 |
Inf |
0.99 |
MW-1 |
mg/L |
Boron, dissolved |
Nonparametric |
14 |
0.265 |
Inf |
0.99 |
MW-1 |
mg/L |
Sulfate, total |
Nonparametric |
14 |
50.409 |
Inf |
0.99 |
MW-2 |
ug/L |
Arsenic, dissolved |
Nonparametric |
14 |
1.382 |
Inf |
0.99 |
MW-2 |
mg/L |
Boron, dissolved |
Lognormal |
14 |
1.993 |
Inf |
0.99 |
MW-2 |
mg/L |
Sulfate, total |
Nonparametric |
14 |
162.818 |
Inf |
0.99 |
MW-3 |
ug/L |
Arsenic, dissolved |
Nonparametric |
14 |
0.600 |
Inf |
0.99 |
MW-3 |
mg/L |
Boron, dissolved |
Lognormal |
14 |
1.292 |
Inf |
0.99 |
MW-3 |
mg/L |
Sulfate, total |
Lognormal |
14 |
126.169 |
Inf |
0.99 |
MW-4 |
ug/L |
Arsenic, dissolved |
Normal |
14 |
4.362 |
Inf |
0.99 |
MW-4 |
mg/L |
Boron, dissolved |
Normal |
14 |
0.265 |
Inf |
0.99 |
MW-4 |
mg/L |
Sulfate, total |
Nonparametric |
14 |
78.510 |
Inf |
0.99 |
The manager pacakges simplifies the above steps.
manager_pred_int <- background_data %>% pred_int(.)
## Warning: `cols` is now required.
## Please use `cols = c(sample_size, lpl, upl, conf_level)`
MW-1 |
ug/L |
Arsenic, dissolved |
Nonparametric |
14 |
-Inf |
10.0000000 |
0.9333333 |
MW-1 |
mg/L |
Boron, dissolved |
Nonparametric |
14 |
-Inf |
1.3700000 |
0.9333333 |
MW-1 |
mg/L |
Sulfate, total |
Nonparametric |
14 |
-Inf |
117.0000000 |
0.9333333 |
MW-2 |
ug/L |
Arsenic, dissolved |
Nonparametric |
14 |
-Inf |
10.0000000 |
0.9333333 |
MW-2 |
mg/L |
Boron, dissolved |
Lognormal |
14 |
0 |
2.4818064 |
0.9500000 |
MW-2 |
mg/L |
Sulfate, total |
Nonparametric |
14 |
-Inf |
200.0000000 |
0.9333333 |
MW-3 |
ug/L |
Arsenic, dissolved |
Nonparametric |
14 |
-Inf |
10.0000000 |
0.9333333 |
MW-3 |
mg/L |
Boron, dissolved |
Lognormal |
14 |
0 |
1.7761065 |
0.9500000 |
MW-3 |
mg/L |
Sulfate, total |
Lognormal |
14 |
0 |
158.0765513 |
0.9500000 |
MW-4 |
ug/L |
Arsenic, dissolved |
Normal |
14 |
-Inf |
11.6737350 |
0.9500000 |
MW-4 |
mg/L |
Boron, dissolved |
Normal |
14 |
-Inf |
0.8085698 |
0.9500000 |
MW-4 |
mg/L |
Sulfate, total |
Nonparametric |
14 |
-Inf |
120.0000000 |
0.9333333 |
manager_conf_int <- background_data %>%
conf_int(., ci_type = "lower", conf_level = 0.99)
## Warning: `cols` is now required.
## Please use `cols = c(sample_size, lcl, ucl, conf_level)`
MW-1 |
ug/L |
Arsenic, dissolved |
Nonparametric |
14 |
1.500 |
Inf |
0.99 |
MW-1 |
mg/L |
Boron, dissolved |
Nonparametric |
14 |
0.265 |
Inf |
0.99 |
MW-1 |
mg/L |
Sulfate, total |
Nonparametric |
14 |
50.409 |
Inf |
0.99 |
MW-2 |
ug/L |
Arsenic, dissolved |
Nonparametric |
14 |
1.382 |
Inf |
0.99 |
MW-2 |
mg/L |
Boron, dissolved |
Lognormal |
14 |
1.993 |
Inf |
0.99 |
MW-2 |
mg/L |
Sulfate, total |
Nonparametric |
14 |
162.818 |
Inf |
0.99 |
MW-3 |
ug/L |
Arsenic, dissolved |
Nonparametric |
14 |
0.600 |
Inf |
0.99 |
MW-3 |
mg/L |
Boron, dissolved |
Lognormal |
14 |
1.292 |
Inf |
0.99 |
MW-3 |
mg/L |
Sulfate, total |
Lognormal |
14 |
126.169 |
Inf |
0.99 |
MW-4 |
ug/L |
Arsenic, dissolved |
Normal |
14 |
4.362 |
Inf |
0.99 |
MW-4 |
mg/L |
Boron, dissolved |
Normal |
14 |
0.265 |
Inf |
0.99 |
MW-4 |
mg/L |
Sulfate, total |
Nonparametric |
14 |
78.510 |
Inf |
0.99 |