Learn R Programming

geofd (version 2.0)

okfd: Function for doing Ordinary Kriging for function-value Data

Description

This function allows to carry out prediction by Ordinary Kriging for function-value data by considering a Fourier or B-splines basis for smoothing the observed data set

Usage

okfd(new.coords, coords, data, smooth.type=NULL, nbasis=max(50,dim(data)[1]),
    argvals=seq(0, 1, len = dim(data)[1]), lambda=0, cov.model=NULL,
    fix.nugget=FALSE, nugget=0, fix.kappa=TRUE,
    kappa=0.5, max.dist.variogram=NULL)

Arguments

new.coords

an n x 2 matrix containing the coordinates of the new n sites where functional Kriging has to be done

coords

an s x 2 matrix containing the coordinates of the n sites where functional data are observed

data

an m x s matrix with values for the observed functions

smooth.type

a string with the name of smoothing method to be applied to data. Available choices are: "bsplines" and "fourier".

nbasis

a numeric value defining the number of basis functions used to smooth the discrete data set recorded at each site

argvals

a vector of argument values corresponding to the observations in matrix data

lambda

optional. Penalization parameter for smoothing the observed functions.

cov.model

a string with the name of the correlation function. Default is NULL, see DETAILS below.

fix.nugget

logical, indicating whether the nugget parameter should be estimated or not.

nugget

value for the nugget parameter.

fix.kappa

logical, indicating whether the kappa parameter should be estimated or not.

kappa

value of the smoothness parameter.

max.dist.variogram

a numerical value defining the maximum distance considered when fitting the variogram.

Value

A list with the following components:

coords

a matrix containing the coordinates of the sites where functional data are observed.

data

a matrix with values for the observed functions.

argvals

a vector of argument values corresponding to the observations in matrix data

nbasis

a numeric value defining the number of basis functions used to smooth the discrete data set recorded at each site.

lambda

penalization parameter for smoothing the observed functions.

new.coords

matrix containing the coordinates of the new sites where functional Kriging has to be done.

emp.trace.vari

empirical trace-variogram.

trace.vari

choosed theoretical variogram model

new.Eu.d

distance matrix among sampling and new sites.

functional.Kriging.weights

functional Kriging weights.

krig.new.data

predicted values for the new sites.

pred.var

prediction variance.

trace.vari.array

vector of all fitted variogram models.

datafd

a functional data object containing a smooth of the data.

Details

This function is a common sequence of the proposed process for doing Ordinary Kriging in the functional scenario, covers from the preparation of the original data and variogram estimation, unto data prediction.

Functional data object

This is an object of the class fd it can be created using some functions like Data2fd or smooth.basis, take in count if a penalization parameter is going to be used.

Penalization parameter

The penalization parameter lambda is used in both smoothing methods. When the selected smooth method is:

  1. bsplines, the function which uses it is fdPar

  2. fourier, the function which uses it is Data2fd

Functional data object

The function which creates the functional data object is determined based on the selected smooth method:

  • When it is bsplines, the functional data object must be created using two different functions, fdPar and smooth.basis in order to include the penalization parameter lambda.

  • When it is fourier, the functional data object is directly returned by Data2fd because it includes the penalization parameter, the basis object, the argument values and the data, all at the same time.

References

Giraldo, R. (2009) Geostatistical Analysis of Functional Data. Ph.D. thesis. Universitat Politecnica de Catalunya.

Giraldo, R., Delicado, P. and Mateu, J. (2012) geofd: An R package for function-valued geostatistical prediction. Revista Colombiana de Estadistica. 35, 385-407.

See Also

l2.norm for calculating L2 norm among functions, trace.variog for functional empirical trace variogram calculation, fit.tracevariog for fitting a variogram model in the funcional scenario.

Examples

Run this code
# NOT RUN {
# First example: one site prediction using B-splines for smoothing

data(maritimes.avg)
data(maritimes.coords)
data(maritimes.data)

coord.cero <- matrix(c(-64.06, 45.79),nrow=1,ncol=2)

n<-dim(maritimes.data)[1]

argvals<-seq(1,n, by=1)

# Prediction by okfd

okfd.res<-okfd(new.coords=coord.cero, coords=maritimes.coords,
              data=maritimes.data, nbasis=65, argvals=argvals,
              fix.nugget=TRUE, kappa=0.7)

# Smoothed and predicted curves, and predicted site average values are plotted

plot(okfd.res$datafd, lty=1, col=8,
    main="Smoothed", xlab="Day", ylab="Temperature (Degrees C)")

lines(okfd.res$argvals, okfd.res$krig.new.data,
      col=1, lwd=2, type="l", lty=1,
      main="Predictions", xlab="Day", ylab="Temperature (Degrees C)")

lines(maritimes.avg,  type="p", pch=20,cex=0.5, col=2, lwd=1)

# Second example: multiple sites prediction using Fourier basis functions for smoothing

data(maritimes)

n<-dim(maritimes.data)[1]

argvals<-seq(1,n, by=1)

col1<-sample( (min(maritimes.coords[,1])*100):(max(maritimes.coords[,1])*100),
              10, replace=TRUE)/100

col2<-sample( (min(maritimes.coords[,2])*100):(max(maritimes.coords[,2])*100),
              10, replace=TRUE)/100

new.coords <- cbind(col1,col2)

# Prediction by okfd

okfd.res<-okfd(new.coords=new.coords, coords=maritimes.coords,
              data=maritimes.data, smooth.type="fourier",
              nbasis=65, argvals=argvals)

# The smoothed and predicted curves are plotted

par(mfrow=c(1,2))

plot(okfd.res$datafd, lty=1, col=8,
    main="Smoothed", xlab="Day", ylab="Temperature (Degrees C)")

matplot(okfd.res$argvals, okfd.res$krig.new.data, col=1, lwd=1, type="l", lty=1,
        main="Predictions", xlab="Day", ylab="Temperature (Degrees C)")

# }

Run the code above in your browser using DataLab