predict.fregre.gkam {fda.usc}R Documentation

Predict method for functional linear model

Description

Computes predictions for regression between functional (and non functional) explanatory variables and scalar response.

These functions use the model fitting function lm, glm or gam properties.
If using functional data derived, is recommended to use a number of bases to represent beta lower than the number of bases used to represent the functional data.
The first item in the data list of newx argument is called "df" and is a data frame with the response and non functional explanatory variables, as lm, glm or gam. Functional variables (fdata and fd class) are introduced in the following items in the data list of newx argument.

Usage

## S3 method for class 'fregre.gkam'
predict(object, newx = NULL, type = "response", ...)

## S3 method for class 'fregre.glm'
predict(object, newx = NULL, type = "response", ...)

## S3 method for class 'fregre.gsam'
predict(object, newx = NULL, type = "response", ...)

## S3 method for class 'fregre.lm'
predict(
  object,
  newx = NULL,
  type = "response",
  se.fit = FALSE,
  scale = NULL,
  df = df,
  interval = "none",
  level = 0.95,
  weights = 1,
  pred.var = res.var/weights,
  ...
)

## S3 method for class 'fregre.plm'
predict(object, newx = NULL, ...)

Arguments

object

fregre.lm, fregre.plm, fregre.glm, fregre.gsam
or fregre.gkam object.

newx

An optional data list in which to look for variables with which to predict. If omitted, the fitted values are used. List of new explanatory data.

type

a character vector, Type of prediction: (response, terms for model terms or effects for model terms where the partial effects are summarized for each functional variable.

...

Further arguments passed to or from other methods.

se.fit

=TRUE (not default) standard error estimates are returned for each prediction.

scale

Scale parameter for std.err. calculation.

df

Degrees of freedom for scale.

interval

Type of interval calculation.

level

Tolerance/confidence level.

weights

variance weights for prediction. This can be a numeric vector or a one-sided model formula. In the latter case, it is interpreted as an expression evaluated in newdata

pred.var

the variance(s) for future observations to be assumed for prediction intervals. See link{predict.lm} for more details.

Value

Return the predicted values and optionally:

Author(s)

Manuel Febrero-Bande, Manuel Oviedo de la Fuente manuel.oviedo@udc.es

References

Febrero-Bande, M., Oviedo de la Fuente, M. (2012). Statistical Computing in Functional Data Analysis: The R Package fda.usc. Journal of Statistical Software, 51(4), 1-28. https://www.jstatsoft.org/v51/i04/

See Also

See Also as: fregre.lm, fregre.plm, fregre.glm, fregre.gsam and fregre.gkam.

Examples

## Not run: 
data(tecator)
ind <- 1:129
x <- tecator$absorp.fdata
x.d2 <- fdata.deriv(x,nderiv=2)
tt <- x[["argvals"]]
dataf <- as.data.frame(tecator$y)
ldat <- ldata("df" = dataf[ind,], "x.d2" = x.d2[ind])
basis.x <- list("x.d2" = create.pc.basis(ldat$x.d2))
res <- fregre.gsam(Fat ~  s(x.d2,k=3),
                   data=ldat, family = gaussian(),
                   basis.x = basis.x)
newldat <- ldata("df" = dataf[-ind,], "x.d2" = x.d2[-ind])
pred <- predict(res, newldat)
plot(pred,tecator$y$Fat[-ind])
res.glm <- fregre.glm(Fat  ~  x.d2, data = ldat,
                  family = gaussian(),basis.x = basis.x)
pred.glm <- predict(res.glm, newldat)
newy <- tecator$y$Fat[-ind]
points(pred.glm,tecator$y$Fat[-ind],col=2)

# Time-consuming 
res.gkam <- fregre.gkam(Fat ~ x.d2, data = ldat)
pred.gkam <- predict(res.gkam, newldat)
points(pred.gkam,tecator$y$Fat[-ind],col = 4)

((1/length(newy)) * sum((drop(newy)-pred)^2)) / var(newy)
((1/length(newy)) * sum((newy-pred.glm)^2)) / var(newy)    
((1/length(newy)) * sum((newy-pred.gkam)^2)) / var(newy)    

## End(Not run)                                                                                                              

[Package fda.usc version 2.1.0 Index]