【问题标题】:How to compute Sen's slope on raster stack using R如何使用 R 计算光栅堆栈上的 Sen 斜率
【发布时间】:2017-11-10 12:12:03
【问题描述】:

我有 36 层栅格堆栈(指定区域的年降雨量)。当我尝试使用以下代码计算 Sen 的斜率时:

library(raster)
library(trend)
# example data
s <- stack(system.file("external/rlogo.grd", package="raster")) 
s <- stack(s, s* 2, s*3)

func <- function(x) { unlist(sens.slope(x)) }
sen.slop <- calc(s, fun=func)

返回如下错误

Error in .local(x, values, ...) : 
 values must be numeric, integer or logical.

有没有人可以帮我解决这个问题?

【问题讨论】:

  • 这是设计上缺少" 吗?

标签: r raster r-raster trend


【解决方案1】:

sens.slope 返回一个 htest 类的对象,其中包括数值,但也包括字符值。要制作栅格,您需要选择所需的数值。例如。 :

library(raster)
library(trend)
s <- stack(system.file("external/rlogo.grd", package="raster")) 
s <- stack(s, s* 2, s*3)
func <- function(x) { unlist(sens.slope(x)[1:3]) }
sen.slop <- calc(s, fun=func)

要了解的是,在向calc 提供您自己的函数之前,您应该检查它的行为。例如,比较:

set.seed(9);
v <- runif(100) * 1:100
# original function
func <- function(x) { unlist(sens.slope(x)) }

func(v)
# estimates.Sen's slope            statistic.z                p.value           null.value.z            alternative              data.name                 method            parameter.n 
# "0.40383510858131"      "6.6084411517969" "3.88387866698504e-11"                    "0"            "two.sided"                    "x"          "Sen's slope"                  "100" 

# Yikes! character output. 

... 使用此函数返回的内容

func <- function(x) { unlist(sens.slope(x)[1:3]) }
func(v)
# estimates.Sen's slope           statistic.z               p.value 
#          4.038351e-01          6.608441e+00          3.883879e-11 

 # better!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-06
    • 1970-01-01
    • 2020-08-24
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 2020-10-02
    相关资源
    最近更新 更多