去除零或NA值后的R中的斜率计算

时间:2016-12-19 07:42:38

标签: r time-series regression linear

我正在计算时间序列栅格与时间数据的趋势,但由于NA和零值,我得不到正确的结果..

在下面的示例中,给出了像素的值。由于零值,我得到斜率值为-23.275而不是3.897

time Value
1     289
2     289
3     353
4     305
5     0
6     0
7     385
8     0
9     0
10    305
11    0
12    0
13    0
14    0
15    0

correct form should be like this

Time Value
1     289
2     289
3     353
4     305
7     385
10    305

我的示例代码是

library(raster)

setwd("F:\\PHD_work\\Paper_work\\EOS\\New folder")
eos = stack(list.files(pattern='*.img'))
time = 1:nlayers(eos)
f_slope=function(x) { if (is.na(x[1])){ NA } else { m = lm(x ~ time); summary(m)$coefficients[2] }}
z = calc(eos, f_slope)
y = writeRaster(z, filename = "slope", format = "HFA")

1 个答案:

答案 0 :(得分:0)

数据位于curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "Cache-Control: no-cache" -H "Postman-Token: 655d9932-4681-f23d-6caf-5fcf63c10b82" -d 'grant_type=client_credentials&client_id=name/a+@b.com&client_secret=XXX!' "https ://example.com/admin/v100/api/oauth/token" ,使用S4更改z中的值

@



但由于问题中没有说明,我还会保持正常过滤

使用z@data@values <- z@data@values[z@data@values > 0]

dplyr

eos <- eos %>% na.omit() %>% filter(Value>0)

base