简体   繁体   中英

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. I want to perform a Mann Kendall trend test on each station to see if there is a significant trend for precipitation.

I've tried group_by with summarise to calculate Mann Kendall for each station over the course of 60 years.

Here's a small example where ID is the station and prcp is precipitation.

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

Part of the problem is the the MannKendall function returns 5 values. How can I specify just the p-value when trying to use group_by ?

What I want is a df that just has the p-value:

  ID prcpmk
[1,]  1   0.20
[2,]  2   0.03

Thanks @A.Suliman, you're right.

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. Alternatively, you could specify tau, Kendall Score (S), denominator (D) of variance of S (varS)

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