── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.0 ✔ tibble 3.2.1
✔ lubridate 1.9.2 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggfortify)library(patchwork)
% classified function
In [2]:
classify <-function(data, model, by ="site", type ="percent") {if(type =="count") x <-table(as.data.frame(data)[,"site"], model$class)if(type =="percent") x <-diag(prop.table(table(as.data.frame(data)[,"site"], model$class), 1)) *100 x}
Load in data
In [3]:
geo_results <-read.csv(here::here("./notebooks/Geochemistry analysis - Copy 2.csv")) %>%pivot_longer(cols = Ag:Zr, names_to ="Fingerprint", values_to ="value") %>%filter(Fingerprint %in%c("Ag", "Al", "As","B","Ba","Be","Bi","Ca","Cd","Ce","Co", "Cr", "Cs", "Cu", "Fe", "Ga", "Hf", "Hg", "In", "K", "La", "Li", "Mg", "Mn", "Mo", "Nb", "Ni", "P", "Pb", "Rb", "S", "Sb", "Sc", "Se", "Sn", "Sr", "Te", "Th", "Tl", "U", "V", "Y", "Zn", "Zr")) %>%# excludes fingerprints that are below level of detection dplyr::select(-X) %>%# don't need this columnfilter(sample_design %in%c("Grid", "Transect", "Likely to erode")) col_results <-read.csv(here::here("./notebooks/final results revised.csv")) %>%pivot_longer(cols = X:B, names_to ="Fingerprint", values_to ="value") %>% dplyr::select(-X.1) %>%# don't need this columnfilter(sample_design %in%c("Grid", "Transect", "Likely to erode")) %>%mutate(Fingerprint =paste0(Fingerprint, "_col")) # appended _col as some of the colour coefficients have the same id eg Boron = B and Blue also = B# Bind data setsresults <- geo_results %>%bind_rows(col_results)
Virtual mixtures
In [4]:
proportions <-seq(0, 1, 0.05)mixtures <- results %>%filter(sample_design %in%c("Grid", "Likely to erode")) %>%# excluded transects as the transects are contained with in the grid this gives us all unique samples group_by(Fingerprint, site) %>%summarise(avg =mean(value)) %>%pivot_wider(names_from = site, values_from = avg) %>%mutate(mix_ag =map(Agriculture, ~.x * (1- proportions)),mix_forest =map(Forest, ~.x * proportions)) %>%group_by(Fingerprint, Agriculture, Forest) %>%summarize(mix =map2(mix_ag, mix_forest, ~data.frame(mix = .x + .y, prop_forest = proportions))) %>%unnest(mix) %>%pivot_wider(id_cols =c("Fingerprint", "Agriculture", "Forest"), names_from = prop_forest, values_from = mix)
`summarise()` has grouped output by 'Fingerprint'. You can override using the
`.groups` argument.
`summarise()` has grouped output by 'Fingerprint', 'Agriculture'. You can
override using the `.groups` argument.
Range test
In [5]:
range <- results %>%group_by(site, sample_design, Fingerprint) %>%summarise(upper_lim =quantile(value, 0.75),lower_lim =quantile(value, 0.25)) %>%group_by(Fingerprint, sample_design) %>%summarise(lower_lim =min(lower_lim),upper_lim =max(upper_lim)) %>%ungroup() %>%left_join(mixtures) %>%#dplyr::select(-c(Agriculture, Forest)) %>%group_by(Fingerprint, sample_design) %>%mutate(pass =all(round(`0`:`1`, 5) >=round(lower_lim, 5)) &all(round(`0`:`1`, 5) <=round(upper_lim, 5))) ## rounding as differences as small as 10^-18 were being removed otherwise
`summarise()` has grouped output by 'site', 'sample_design'. You can override
using the `.groups` argument.
`summarise()` has grouped output by 'Fingerprint'. You can override using the
`.groups` argument.
Joining with `by = join_by(Fingerprint)`
# A tibble: 16 × 3
params c$Agriculture wilks
<chr> <dbl> <dbl>
1 Li 100 0.0620
2 Li + a_col 100 0.0441
3 Li + a_col + Fe 100 0.0276
4 Li + a_col + Fe + Co 100 0.0233
5 Li + a_col + Fe + Co + Hg 100 0.0217
6 Li + a_col + Fe + Co + Hg + x_col 100 0.0188
7 Li + a_col + Fe + Co + Hg + x_col + Cs 100 0.0178
8 Li + a_col + Fe + Co + Hg + x_col + Cs + La 100 0.0145
9 Li + a_col + Fe + Co + Hg + x_col + Cs + La + Ni 100 0.0134
10 Li + a_col + Fe + Co + Hg + x_col + Cs + La + Ni + Nb 100 0.0128
11 Li + a_col + Fe + Co + Hg + x_col + Cs + La + Ni + Nb … 100 0.0123
12 Li + a_col + Fe + Co + Hg + x_col + Cs + La + Ni + Nb … 100 0.0114
13 Li + a_col + Fe + Co + Hg + x_col + Cs + La + Ni + Nb … 100 0.0110
14 Li + a_col + Fe + Co + Hg + x_col + Cs + La + Ni + Nb … 100 0.00970
15 Li + a_col + Fe + Co + Hg + x_col + Cs + La + Ni + Nb … 100 0.00925
16 Li + a_col + Fe + Co + Hg + x_col + Cs + La + Ni + Nb … 100 0.00886
# ℹ 1 more variable: c$Forest <dbl>