Predict method for functional linear model
Source:R/predict.fregre.gkam.R
, R/predict.fregre.glm.R
, R/predict.fregre.gsam.R
, and 2 more
predict.fregre.lm.Rd
Computes predictions for regression between functional (and non functional) explanatory variables and scalar response.
predict.fregre.lm
, Predict method for functional linear model offregre.lm
fits object using basis or principal component representation.predict.fregre.plm
, Predict method for semi-functional linear regression offregre.plm
fits object using using asymmetric kernel estimation.predict.fregre.glm
, Predict method for functional generalized linear model offregre.glm
fits object using basis or principal component representation.predict.fregre.gsam
, Predict method for functional generalized spectral additive model offregre.gsam
fits object using basis or principal component representation.predict.fregre.gkam
, Predict method for functional generalized kernel additive model offregre.gkam
fits object using backfitting algorithm.
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
orfregre.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 oreffects
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:
predict.lm,predict.glm,predict.gam
: produces a vector of predictions or a matrix of predictions and bounds with column names fit, lwr, and upr if interval is set. If se.fit is TRUE, a list with the following components is returned: fit vector or matrix as above.se.fit
: standard error of predicted means.residual.scale
: residual standard deviations.df
: degrees of freedom for residual.
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
.
Author
Manuel Febrero-Bande, Manuel Oviedo de la Fuente manuel.oviedo@udc.es
Examples
if (FALSE) { # \dontrun{
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)
} # }