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)