predict.MRFA {MRFA}R Documentation

Prediction of Multi-Resolution Functional ANOVA (MRFA) Model

Description

The function computes the predicted responses.

Usage

## S3 method for class 'MRFA'
predict(object, xnew, lambda = object$lambda, parallel = FALSE, ...)

Arguments

object

a class MRFA object estimated by MRFA_fit.

xnew

a testing matrix with dimension n_new by d in which each row corresponds to a predictive location.

lambda

a value, or vector of values, indexing the path. The default is object$lambda.

parallel

logical. If TRUE, apply function in parallel in ldply using parallel backend provided by foreach.

...

for compatibility with generic method predict.

Value

lambda

as above.

coefficients

coefficients with respect to the basis function value.

y_hat

a matrix with dimension n_new by length(lambda) displaying predicted responses at locations xnew.

Author(s)

Chih-Li Sung <iamdfchile@gmail.com>

See Also

MRFA_fit for fitting a multiresolution functional ANOVA model.

Examples

## Not run: 

#####             Testing function: OTL circuit function                     #####
#####  Thanks to Sonja Surjanovic and Derek Bingham, Simon Fraser University #####
otlcircuit <- function(xx)
{
  Rb1  <- 50   + xx[1] * 100
  Rb2  <- 25   + xx[2] * 45
  Rf   <- 0.5  + xx[3] * 2.5
  Rc1  <- 1.2  + xx[4] * 1.3
  Rc2  <- 0.25 + xx[5] * 0.95
  beta <- 50   + xx[6] * 250

  Vb1 <- 12*Rb2 / (Rb1+Rb2)
  term1a <- (Vb1+0.74) * beta * (Rc2+9)
  term1b <- beta*(Rc2+9) + Rf
  term1 <- term1a / term1b

  term2a <- 11.35 * Rf
  term2b <- beta*(Rc2+9) + Rf
  term2 <- term2a / term2b

  term3a <- 0.74 * Rf * beta * (Rc2+9)
  term3b <- (beta*(Rc2+9)+Rf) * Rc1
  term3 <- term3a / term3b

  Vm <- term1 + term2 + term3
  return(Vm)
}

library(MRFA)
#####   Training data and testing data   #####
set.seed(2)
n <- 1000; n_new <- 100; d <- 6
X.train <- matrix(runif(d*n), ncol = d)
Y.train <- apply(X.train, 1, otlcircuit)
X.test <- matrix(runif(d*n_new), ncol = d)
Y.test <- apply(X.test, 1, otlcircuit)

#####   Fitting    #####
MRFA_model <- MRFA_fit(X.train, Y.train, verbose = TRUE)

#####   Prediction   ######
Y.pred <- predict(MRFA_model, X.test, lambda = min(MRFA_model$lambda))$y_hat
print(sqrt(mean((Y.test - Y.pred)^2)))

## End(Not run)

[Package MRFA version 0.6 Index]