0

我试图在 Theil-Sen 斜率估计中使用日期作为我的 X 变量,但我在使用 R 包 zyp 时遇到了困难

library(zyp)

myDates <- as.Date(c("2009-11-24","2009-12-03","2010-01-19","2010-02-18","2010-03-04"))
myData <- c(10.17,10.91,11.72,12.5,13.43)
a <- c("a","b","c","d","e")
df = data.frame(a,myData,myDates)
zyp.sen(myDates~myData, df)

然后我收到以下错误:

    Error in `+.Date`(y - slope * x, intercept) : 
      binary + is not defined for "Date" objects

我也在尝试使用zyp.trend.dataframe(df, 1),但我基本上一无所获:

  a lbound trend trendp ubound tau sig nruns autocor valid_frac linear intercept
  1 a     NA    NA     NA     NA  NA  NA    NA      NA         NA     NA        NA
  2 b     NA    NA     NA     NA  NA  NA    NA      NA         NA     NA        NA
  3 c     NA    NA     NA     NA  NA  NA    NA      NA         NA     NA        NA
  4 d     NA    NA     NA     NA  NA  NA    NA      NA         NA     NA        NA
  5 e     NA    NA     NA     NA  NA  NA    NA      NA         NA     NA        NA

我假设我错误地访问了 zyp。有谁知道我做错了什么?

TIA

4

1 回答 1

1

将日期转换为其基础整数值应该成功:

myDates <- as.integer( 
as.Date(c("2009-11-24","2009-12-03","2010-01-19","2010-02-18","2010-03-04")))
myData <- c(10.17,10.91,11.72,12.5,13.43)
a <- c("a","b","c","d","e")
df = data.frame(a,myData,myDates)
 zyp.sen(myDates~myData, df)

Call:
NULL

Coefficients:
Intercept     myData  
 14204.66      36.12  
于 2014-10-03T22:51:21.917 回答