简体   繁体   中英

How to run Seasonal Mann Kendall on multiple columns

I have a large dataset with many variables for which I would like to find their seasonal trend using the seasonal Mann Kendall trend test in r?

Here is a sample of my data:

structure(list(Year = c(1997, 1999, 2002, 2003, 2004), pH = c(8, 
8.4, 8.28, 8.4, 7.8), Colour = c(16, 23, 4, NA, 4), Turbidity = c(74.3, 
21.6, 7.1266, 0.552, 9.875), Conductivity = c(41.15, 41.7, 25.08, 
41.1, 48.15), TDS = c(275.705, 279.39, 168.036, 275.37, 322.605
), Na = c(23, 31, 13.8, 33, 43), K = c(5.5, 3, 2, 3, 2.5), Ca = c(71.25, 
77.5, 62, 67.5, 76.25), Mg = c(54.1666666666667, 66.6666666666667, 
38.3333333333333, 54.1666666666667, 68.75), SO4 = c(53, 30, 15.6, 
29, 45.5), NO3 = c(NA, NA, 0.7, NA, 0.5), SiO2 = c(7.5, 5, 14.2, 
22, 12), F = c(0.2, 0.5, 0.36, 0.3, 0.3), Cl = c(23, 30, 11.2, 
27, 41), Alcalinity = c(101, 148, 94.8, 132, 133), Fe = c(NA, 
0.05, 0.04, NA, 0.04), Mn = c(16, 23, 4, NA, 4), Cu = c(NA, NA, 
0.026, NA, 0.03), Zn = c(NA, NA, 0.0225, 0.02, 0.02)), row.names = c(NA, 
-5L), class = c("tbl_df", "tbl", "data.frame"))

An option is to use SeasonalMannKendall from Kendall . Within summarise , select the columns of interest within across and apply the function

library(Kendall)
library(dplyr)
out <- df1 %>%
    summarise(across(c(pH, Turbidity, Conductivity, TDS, Na),
           ~ list(SeasonalMannKendall(as.ts(.)))))

-output

out
# A tibble: 1 x 5
#  pH        Turbidity Conductivity TDS       Na       
#  <list>    <list>    <list>       <list>    <list>   
#1 <Kendall> <Kendall> <Kendall>    <Kendall> <Kendall>
out$pH
#[[1]]
#tau = -0.105, 2-sided pvalue =0.80054

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM