Learn R Programming

fields (version 6.8)

predict.surface: Evaluates a fitted function or its standard errors as a surface object

Description

Evaluates a a fitted model on a 2-D grid keeping any other variables constant. The resulting object is suitable for use with functions for viewing 3-d surfaces.

Usage

## S3 method for class 'surface':
predict(object,...)

## S3 method for class 'default': predict.surface(object, grid.list = NA, extrap = FALSE, chull.mask = NA, nx = 80, ny = 80, xy = c(1, 2), order.variables="xy", verbose=FALSE,...)

## S3 method for class 'surface.se': predict(object,...)

## S3 method for class 'default': predict.surface.se(object, grid.list = NA, extrap = FALSE, chull.mask = NA, nx = 80, ny = 80, xy = c(1, 2), order.variables="xy",verbose=FALSE, ...)

## S3 method for class 'surface.derivative': predict(object,...)

## S3 method for class 'default': predict.surface.derivative(object, grid.list = NULL, nx = 80, ny = 80, ...)

Arguments

Value

The usual list components for making contour and perspective plots (x,y,z) along with labels for the x and y variables. For predict.surface.derivative the component z is a three dimensional array with nx, ny, 2.

Details

This function creates the right grid using the grid.list information or the attribute in xg, calls the predict function for the object with these points and also adding any extra arguments passed in the ... section, and then reforms the results as a surface object (as.surface). To determine the what parts of the prediction grid are in the convex hull of the data the function in.poly is used. The argument inflation in this function is used to include a small margin around the outside of the polygon so that point on convex hull are included. This potentially confusing modification is to prevent excluding grid points that fall exactly on the ranges of the data. Also note that as written there is no computational savings for evaluting only the convex subset compared to the full grid.

The derivative function has much fewer arguments and is written to have more clarity in the coding. For example, it assumes a 2-d surface with "x" and "y" in the order that they appear in the fitted object. To mask out the convex hull of the derivatives one could use predict.surface to get the convex hull and use this for the masking of the deriviative.

See Also

Tps, Krig, predict, grid.list, make.surface.grid, as.surface, surface, in.poly

Examples

Run this code
fit<- Tps( BD[,1:4], BD$lnya)  # fit surface to data 

# evaluate fitted surface for  first two 
# variables holding other two fixed at median values

out.p<- predict.surface(fit)
surface(out.p, type="C") 

#
# plot surface for second and fourth variables 
# on specific grid. 

glist<- list( KCL=29.77, MgCl2= seq(3,7,,25), KPO4=32.13, 
                     dNTP=seq( 250,1500,,25))

out.p<- predict.surface(fit, glist)
surface(out.p, type="C")

out.p<- predict.surface.se(fit, glist)
surface(out.p, type="C")

# the unbiquitous ozone data set day 16
  data( ozone2)

  obj<- Tps(ozone2$lon.lat,ozone2$y[16,], m=3)
  lookd<- predict.surface.derivative( obj)
  set.panel( 2,1) 
  image.plot( lookd$z[,,1])
  image.plot( lookd$z[,,2])

Run the code above in your browser using DataLab