0

I have got an issues with my Mann Kendall R script.

I'm getting wrong P value when I calculate based on the sum(Quantity) but it is give me an accurate P value based on the number of records.

Dataset %>%  mutate(

      MannKendallY = if (length(Total) > 0)
    
      {MK <- MannKendall(TotalQuantity) 
    
      pvalue <- as.numeric(MK$s)} else{
    
        pvalue <- 1}
    
    ) %>% mutate(
    
      TauY = if (length(Total) > 0)
    
      {MK <- MannKendall(Total) 
    
      tau <- as.numeric(MK$tau)} else{
    
        tau <- 0}

    )

Any inputs are appreciated.

Many Thanks.

SamR
  • 8,826
  • 3
  • 11
  • 33
venu sura
  • 11
  • 2
  • Please provide some example data and the expected output as well as the output you get. Please revisit your code, the way it is written at the moment it will not work due to errors like closing brackets without the corresponding starting ones... – kath Jul 11 '19 at 12:09
  • Hi Kath, Sorry , typo error, I have edited my script now. – venu sura Jul 11 '19 at 12:23
  • My data point are (1,1,2,0,2,0,3,50712259,3,1,2,1) and time = July 2018 to June 2019; frequency is 12. – venu sura Jul 11 '19 at 12:25
  • Please edit the question with your data in a reproducible manner and also make sure you format your code to make it readabile. See also https://stackoverflow.com/a/5963610/5892059 . Further, I think you are actually looking for `ifelse` instead of `if ... else ...`. – kath Jul 11 '19 at 12:26
  • Hi Kath, Apologies for the delay.. I have shared( https://drive.google.com/open?id=1rxrWWfazd1mJn2FYDrnCQB1wOm_bj8Td ) the data (book1) and R-script original which is working fine based on number of rows and R-script modified which i have modified to get the mann kendall value based on sum(quantity). Expected P value with modified script is 0.7721 but I'm getting 0.1711. – venu sura Jul 12 '19 at 14:56

0 Answers0