在R中的泰勒图中增加偏差

时间:2014-02-21 13:43:19

标签: r plotrix

我正在使用taylor.diagram包中的plotrix函数,例如

obs = runif(100,1,100)
mod1 = runif(100,1,100)
mod2 = runif(100,1,100) 
mod3 = runif(100,1,100) 
taylor.diagram(obs,mod1)
taylor.diagram(obs,mod2,add=TRUE)
taylor.diagram(obs,mod3,add=TRUE)

enter image description here

在传统的泰勒图中没有偏见,但在他的论文中(Taylor,2001,K.E。在单个图表Taylor JGR,106,7183-7192中总结模型性能的多个方面)泰勒说

"Although the diagram has been designed to convey information about centered pattern differences it is also possible to indicate differences in overall means (i.e., the bias). This can be done on the diagram by attaching to each plotted point a line segment drawn at a right angle to the straight line defined by the point and the reference point. If the length of the attached line segment is equal to the bias, then the distance from the reference point to the end of the line segment will be equal to the total (uncentered) RMS error"

我承认我不知道从哪里开始尝试这样做。有没有人成功地在情节中添加这些信息?

1 个答案:

答案 0 :(得分:5)

如果我理解正确,偏差是模型向量和观察向量之间的平均差异。然后,问题是,(a)找到观察点和模型点之间的线,(b)找到一条垂直于此线的线,(c )在垂直线上找到一个点,距模型点的距离等于偏差。

一种可能的解决方案是:

taylor.bias <- function(ref, model, normalize = FALSE){
    R <- cor(model, ref, use = "pairwise")
    sd.f <- sd(model)
    sd.r <- sd(ref)
    m.f <- mean(model)
    m.r <- mean(ref)

    ## normalize if requested
    if (normalize) {
        m.f <- m.f/sd.r
        m.r <- m.r/sd.r
        sd.f <- sd.f/sd.r
        sd.r <- 1
        }

    ## calculate bias
    bias <- m.f - m.r

    ## coordinates for model and observations
    dd <- rbind(mp = c(sd.f * R, sd.f * sin(acos(R))), rp = c(sd.r, 0))

    ## find equation of line passing through pts
    v1 <- solve(cbind(1, dd[,1])) %*% dd[,2]    

    ## find perpendicular line
    v2 <- c(dd[1,2] + dd[1,1]/v1[2], -1/v1[2])

    ## find point defined by bias
    nm <- dd[1,] - c(0, v2[1])
    nm <- nm / sqrt(sum(nm^2))
    bp <- dd[1,] + bias*nm

    ## plot lines
    arrows(x0 = dd[1,1], x1 = bp[1], y0 = dd[1,2], y1 = bp[2], col = "red", length = 0.05, lwd = 1.5)
    lines(rbind(dd[2,], bp), col = "red", lty = 3)
    lines(dd, col = "red", lty = 3)
    }

然后,

library(plotrix)
obs = runif(100,1,100)
mod1 = runif(100,1,100)
taylor.diagram(obs,mod1)
taylor.bias(obs,mod1)

其中红色矢量的长度表示偏差,并且将矢量尖端连接到参考点的虚线长度是RMS误差。红色矢量的方向表示偏差的符号 - 在下图中,为负偏差。

enter image description here