Adding bias in Taylor diagram in R

不羁岁月 提交于 2019-12-06 13:42:41

If I understand correctly the bias is the difference in means between the model vector and the observation vector. Then, the problem is to, (a) find the line between the observation and model points, (b) find a line perpendicular to this line, (c) find a point along the perpendicular line, at a distance from the model point equal to the bias.

One possible solution is:

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)
    }

Then,

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

Where the length of the red vector indicates the bias and the length of dotted line joining the vector's tip to the reference point is the RMS error. The direction of the red vector indicates the sign of the bias -- in the picture below, negative bias.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!