[英]How to perform mann kendall trend test on multiple levels
I am working with station precipitation data. 我正在处理气象站的降水量数据。 Each station has precipitation data for 60 years and there are 30 stations. 每个站都有60年的降水数据,有30个站。 I want to perform a Mann Kendall trend test on each station to see if there is a significant trend for precipitation. 我想在每个站上进行Mann Kendall趋势测试,以查看是否有明显的降水趋势。
I've tried group_by
with summarise
to calculate Mann Kendall for each station over the course of 60 years. 我试过group_by
与summarise
来计算曼肯德尔每个站了60年的历程。
Here's a small example where ID is the station and prcp is precipitation. 这是一个小示例,其中ID是气象站,而prcp是降水。
ID<-c(1,1,1,1,1,2,2,2,2,2)
prcp<-c(2,0,1,4,5,0,2,3,5,6)
df<-cbind(ID,prcp)
mk<-df %>%
as.data.frame() %>%
group_by(ID) %>%
summarise(prcpmk=MannKendall(prcp))
Every time I do this I get the following error: Column prcpmk must be length 1 (a summary value), not 5
每次执行此操作时,都会出现以下错误: Column prcpmk must be length 1 (a summary value), not 5
Part of the problem is the the MannKendall function returns 5 values. 问题的一部分是MannKendall函数返回5个值。 How can I specify just the p-value when trying to use group_by
? 尝试使用group_by
时如何仅指定p值?
What I want is a df that just has the p-value: 我想要的是仅具有p值的df:
ID prcpmk
[1,] 1 0.20
[2,] 2 0.03
Thanks @A.Suliman, you're right. 谢谢@ A.Suliman,您是对的。
This seems to work: 这似乎可行:
ID<-c(1,1,1,1,1,2,2,2,2,2)
prcp<-c(2,0,1,4,5,0,2,3,5,6)
df<-cbind(ID,prcp)
mk<-df %>%
as.data.frame() %>%
group_by(ID) %>%
summarise(prcpmk=MannKendall(prcp)$sl)
Adding the $sl
after MannKendall() specifies the p value. 在MannKendall()之后添加$sl
指定p值。 Alternatively, you could specify tau, Kendall Score (S), denominator (D) of variance of S (varS) 或者,您可以指定tau,Kendall分数(S),S方差的分母(D)(varS)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.