/usr/share/doc/r-cran-fields/tests/Krig.se.W.R is in r-cran-fields 8.10-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | # fields, Tools for spatial data
# Copyright 2004-2011, Institute for Mathematics Applied Geosciences
# University Corporation for Atmospheric Research
# Licensed under the GPL -- www.gpl.org/licenses/gpl.html
library( fields)
# tests of predictSE using
# off diag weight matrix for obs (W)
options( echo=FALSE)
test.for.zero.flag<- 1
# a nasty example with off diagonal weights.
set.seed(123)
N<- 50
x<- matrix( runif( N*2), N,2)
y<- rnorm( N)*.2 + 2*x[,1]**2 + x[,2]**2
weights<- runif(N)*10
x0<- cbind( c(.1,.2,.6,.65,.8), c(.05,.5,.73,.9,.95))
temp.wght<- function(x, alpha=.3){
Exp.cov( x, theta=.1) }
Krig( x,y, cov.function=Exp.cov,weights=weights,
wght.function= "temp.wght")-> out
Krig( x,y, cov.function=Exp.cov,weights=weights,W= out$W)-> out2
# direct calculation test for A matrix
#
Krig.Amatrix( out, x=x0)-> A
test.for.zero( A%*%y, predict( out, x0),tag="Amatrix vs. predict")
# now find se.
W2<-out$W2
W<- out$W
Sigma<- out$rhohat*Exp.cov( out$x,out$x)
temp0<- out$rhohat*(Exp.cov( x0, x0))
S1<- out$rhohat*Exp.cov( out$x, x0)
#yhat= Ay
#var( f0 - yhat)= var( f0) - 2 cov( f0,yhat)+ cov( yhat)
Sigma.obs<- Krig.make.Wi( out)$Wi
Sigma.obs <- Sigma.obs* (out$shat.MLE**2)
temp1<- A%*%S1
temp2<- A%*% ( Sigma.obs+ Sigma)%*% t(A)
look<- temp0 - t(temp1) - temp1 + temp2
#compare to
# diagonal elements
test<- predictSE( out, x= x0)
test.for.zero( sqrt(diag( look)), test,tag="Marginal predictSE")
test<- predictSE( out, x= x0, cov=TRUE)
test2<- predictSE( out2, x= x0, cov=TRUE)
test.for.zero( look, test,tag="Full covariance predictSE")
test.for.zero( look, test2,tag="Full covariance predictSE explicit W")
cat( "all done", fill=TRUE)
options( echo=TRUE)
|