## Simple models on a square, regularly sampled surface
# Construct and plot a 10 by 10 grid
xygrid <- expand.grid(1:10, 1:10)
plot(xygrid)
# Centring
xygrid.c <- scale(xygrid, scale = FALSE)
# Create and plot some first, second and third-degree functions
# of X and Y
X <- xygrid.c[ ,1]
Y <- xygrid.c[ ,2]
XY <- X + Y
XY2 <- X^2 + Y^2
XY3 <- X^2 - X * Y - Y^2
XY4 <- X + Y + X^2 + X * Y + Y^2
XY5 <- X^3 + Y^3
XY6 <- X^3 + X^2 * Y + X * Y^2 + Y^3
XY7 <- X + Y + X^2 + X * Y + Y^2 + X^3 + X^2 * Y + X * Y^2 + Y^3
xy3deg <- cbind(X, Y, XY, XY2, XY3, XY4, XY5, XY6, XY7)
s.value(xygrid, xy3deg, symbol = "circle")
Try other combinations, for instance with minus signs or with coefficients not
equal to 1.
# Computation of a raw (non-orthogonal) third-degree polynomial
# function on the previously centred X-Y coordinates
mite.poly <- poly(as.matrix(mite.xy.c), degree = 3, raw = TRUE)
colnames(mite.poly)
Function poly produces the polynomial terms in the following sequence: X,
X^2, X^3, Y, XY, X^2Y, Y^2, XY^2, Y^3). The original column
names give the degree for the two variables. For instance, "1.2" means X^1*Y^2.
Here raw polynomials have been computed. For orthogonal polynomials, which is
the default, raw = FALSE.
7.3 Multivariate Trend-Surface Analysis
311
# Construct and plot a 10 by 10 grid
xygrid <- expand.grid(1:10, 1:10)
plot(xygrid)
# Centring
xygrid.c <- scale(xygrid, scale = FALSE)
# Create and plot some first, second and third-degree functions
# of X and Y
X <- xygrid.c[ ,1]
Y <- xygrid.c[ ,2]
XY <- X + Y
XY2 <- X^2 + Y^2
XY3 <- X^2 - X * Y - Y^2
XY4 <- X + Y + X^2 + X * Y + Y^2
XY5 <- X^3 + Y^3
XY6 <- X^3 + X^2 * Y + X * Y^2 + Y^3
XY7 <- X + Y + X^2 + X * Y + Y^2 + X^3 + X^2 * Y + X * Y^2 + Y^3
xy3deg <- cbind(X, Y, XY, XY2, XY3, XY4, XY5, XY6, XY7)
s.value(xygrid, xy3deg, symbol = "circle")
Try other combinations, for instance with minus signs or with coefficients not
equal to 1.
# Computation of a raw (non-orthogonal) third-degree polynomial
# function on the previously centred X-Y coordinates
mite.poly <- poly(as.matrix(mite.xy.c), degree = 3, raw = TRUE)
colnames(mite.poly)
X^2, X^3, Y, XY, X^2Y, Y^2, XY^2, Y^3). The original column
names give the degree for the two variables. For instance, "1.2" means X^1*Y^2.
Here raw polynomials have been computed. For orthogonal polynomials, which is
the default, raw = FALSE.
7.3 Multivariate Trend-Surface Analysis
311
