R/02_sof_pc.R
predict_sof_pc.Rd
Predict new observations of the scalar response variable and calculate the corresponding prediction error, with prediction interval limits, given new observations of functional covariates and a fitted scalar-on-function linear regression model
predict_sof_pc(
object,
y_new = NULL,
mfdobj_x_new = NULL,
alpha = 0.05,
newdata
)
A list obtained as output from sof_pc
,
i.e. a fitted scalar-on-function linear regression model.
A numeric vector containing the new observations of the scalar response variable to be predicted.
An object of class mfd
containing
new observations of the functional covariates.
If NULL, it is set as the functional covariates data used for model fitting.
A numeric value indicating the Type I error
for the regression control chart
and such that this function returns the 1-alpha
prediction interval on the response.
Default is 0.05.
Deprecated, use mfdobj_x_new
argument.
A data.frame
with as many rows as the
number of functional replications in newdata
,
with the following columns:
* fit
: the predictions of the response variable
corresponding to new_data
,
* lwr
:
lower limit of the 1-alpha
prediction interval
on the response, based on the assumption that it is normally distributed.
* upr
:
upper limit of the 1-alpha
prediction interval
on the response, based on the assumption that it is normally distributed.
* res
:
the residuals obtained as the values of y_new
minus their
fitted values. If the scalar-on-function model has been fitted with
type_residual == "studentized"
, then the studentized residuals
are calculated.
library(funcharts)
data("air")
air <- lapply(air, function(x) x[1:10, , drop = FALSE])
fun_covariates <- c("CO", "temperature")
mfdobj_x <- get_mfd_list(air[fun_covariates], lambda = 1e-2)
y <- rowMeans(air$NO2)
mod <- sof_pc(y, mfdobj_x)
predict_sof_pc(mod)
#> fit lwr upr pred_err y
#> 1 7.328329 7.238309 7.418348 -0.0183013627 7.310027
#> 2 7.363446 7.270688 7.456204 0.0120441880 7.375490
#> 3 7.388644 7.305105 7.472182 -0.0204670518 7.368177
#> 4 7.359027 7.263627 7.454426 0.0143399689 7.373367
#> 5 7.519710 7.427195 7.612224 0.0052219043 7.524931
#> 6 7.453269 7.375114 7.531425 -0.0099885559 7.443281
#> 7 7.442536 7.358799 7.526274 -0.0005674598 7.441969
#> 8 7.446190 7.370298 7.522082 -0.0194755345 7.426714
#> 9 7.404424 7.326028 7.482819 0.0447843608 7.449208
#> 10 7.384681 7.304250 7.465112 -0.0075904572 7.377091