协方差图和相关图作为距离的函数-xyz数据

时间:2019-01-16 16:22:05

标签: r geospatial

我正在寻求帮助的是从xyz数据集获取以下内容的图:

  1. 原始代码的协方差图。
  2. 空间变化(x轴)和距离(y轴)

xyz数据集

x和y是随机采样的坐标,z表示被认为是具有指数协方差函数的高斯现象的基本现象。我有一个没有空间相关性的模拟随机数据集。这样,我知道空间相关性将随着距原点的距离而迅速衰减。

    set.seed(1)
    n <- 20 ## number of values to be generated
    x <- runif(n) ## position
    y <- runif(n) ## position
    z <- rnorm(n, mean = 10, sd = 4) ## value of underlying phenomena

    plot(x, y, cex = z / 5, bty = "l", pch = 19, col = "#FF000070")
    xyz <- data.frame(x, y, z)


    # We then go on to define the model using maximum likelihood and an exponential 
    # covariance model for simplicity's sake. 

    nllmulti <- function(theta){
        mu <- matrix(theta[1], nrow = n)
        S <- diag(rep(exp(theta[2])^2, n)) # Covaraince matrix
        ll <- -1/2 * (log(det(S)) + t(z - mu) %*% solve(S) %*% (z - mu) + n * log(2 * pi))
        nll <- -ll
        return(nll)
    }

    # Using geoR
    library(geoR)
   # Distance matrix
    h <- dist(xyz)
    h.dat <- as.geodata(xyz, coords.col = 1:2, data.col = 3)
    Ref.ML <- likfit(h.dat, coords = h.dat$coords, data = h.dat$data,
            ini.cov.pars = c(.1, .1),
            fix.nugget = TRUE
           ); Ref.ML

    # Plot the results as a variogram

    v1 <- variog(coords =  cbind(x,y), data = z)
    plot(v1)
    lines(Ref.ML)

我不确定下一步该怎么做。

0 个答案:

没有答案