fields testing scripts {fields}R Documentation

Testing fields functions


Some of the basic methods in fields can be tested by directly implementing the linear algebra using matrix expressions and other functions can be cross checked within fields. These comparisons are done in the the R source code test files in the tests subdirectory of fields. The function is useful for comparing the tests in a meaninful and documented way.

Usage xtest, xtrue,  tol= 1.0e-8, relative=TRUE, tag=NULL)



Vector of target values


Vector of reference values


Tolerance to judge whether the test passes.


If true a relative error comparison is used. (See details below.)


A text string to be printed out with the test results as a reference


IMPORTANT: If the R object exists with any value ( e.g. <- 1 ) then when the test fails this function will also generate an error in addition to printing a message. This option is added to insure that any test scripts will generate an error when any individual test fails.

An example:

> 1:10, 1:10 + 1e-10, tag="First test")
Testing:  First test
PASSED test at tolerance  1e-08
> 1:10, 1:10 + 1e-10, tag="First test", tol=1e-12)
Testing:  First test
FAILED test value =  1.818182e-10  at tolerance  1e-12
> <- 1
Testing:  First test
FAILED test value =  1.818182e-10  at tolerance  1e-12
Error in, 1:10 + 1e-10, tag = "First test", tol = 1e-12) :

The scripts in the tests subdirectory are


Tests basic parts of the Krig and Tps functions including replicated and weighted observations.

Tests computations of standard errors for the Kriging estimate.

Tests approximate standard errors for the Krig function found by Monte Carlo conditional simulation.


Tests predictions and A matrix when an off diagonal observation weight matrix is used.

Tests standard errors when an off diagonal observation weight matrix is used.


Tests sparse matrix formats and linear algebra.


Tests form for Wendland covariance family and its use of sparse matrix formats.


Tests special (efficient) version of matrix multiply for diagonal matrices.


Tests evaluation of univariate and multivariate polynomial evaluation.


Tests the micro Krig function with and without sparse matrix methods.

To run the tests just attach the fields library and source the testing file. In the fields source code these are in a subdirectory "tests". Compare the output to the "" text file. is used to print out the result for each individual comparison. Failed tests are potentially bad and are reported with a string beginning

"FAILED test value = ... "

If the object exists then an error is also generated when the test fails.

FORM OF COMPARISON: The actual test done is the sum of absolute differnces:

test value = sum( abs(c(xtest) - c( xtrue) ) ) /denom

Where denom is either mean( abs(c(xtrue))) for relative error or 1.0 otherwise.

Note the use of "c" here to stack any structure in xtest and xtrue into a vector.

[Package fields version 8.4-1 Index]