簡體   English   中英

如何在多個列上運行季節性 Mann Kendall

[英]How to run Seasonal Mann Kendall on multiple columns

我有一個包含許多變量的大型數據集,我想使用 r 中的季節性 Mann Kendall 趨勢測試來找到它們的季節性趨勢?

這是我的數據示例:

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"))

一種選擇是使用KendallSeasonalMannKendall summarise中,select 中感興趣的列across並應用 function

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

-輸出

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM