predict.cv.FuncompCGL {Compack}R Documentation

Make predictions based on a "cv.FuncompCGL" object.

Description

This function makes prediction based on a cv.FuncompCGL object, using the stored "FuncompCGL.fit" object and the optimal values of the regularization parameter lam and the degrees of freedom k.

Usage

## S3 method for class 'cv.FuncompCGL'
predict(object, Znew, Zcnew = NULL,
        s = c("lam.1se", "lam.min"), k = NULL, trim = FALSE, ...)

Arguments

object

fitted cv.FuncompCGL object.

Znew

data frame or matrix X as in FuncompCGL with new functional compositional data at which prediction is to be made.

Zcnew

matrix Zc as in FuncompCGL with new values of time-invariate covariates at which prediction is to be made. Default is NULL.

s

value(s) of the penalty parameter lam at which coefficients are requested.

  • s="lam.min"(default), grid value of lam and k stored in the "cv.FuncompCGL" object such that the minimum cross-validation error is achieved.

  • s="lam.1se", grid value of lam and k stored on the "cv.FuncompCGL" object such that the 1 standard error above the miminum cross-validation error is achieved.

  • If s is numeric, it is taken as the value(s) of lam to be used. In this case, k must be provided.

  • If s = NULL, the whole sequence of lam stored in the cv.FuncompCGL object is used.

k

value(s) of the degrees of freedom of the basis function at which coefficents are requested. k can be NULL (default) or integer(s).

  • k = NULL, s must be either "lam.min" or "lam.1se".

  • if k is an integer(s), it is taken as the value of k to be used and it must be one(s) of these in the "cv.FuncompCGL" object.

trim

logical; whether to use the trimmed result. Default is FALSE.

...

Other arguments passed to predict.FuncompCGL

Details

s is the vector at which predictions are requested. If s is not in the lam sequence used for fitting the model, the predict function uses linear interpolation.
If the data frame X is provided in FuncompCGL mode, the integral for new data newx is taken the same as that in the fitted FuncompCGL model. This means that the parameters degree, basis_fun, insert, method, inteval, Trange, and K are exactly the same as these in the provided object. If insert="X" or "basis", sseq is the sorted sequence of all the observed time points in fitting FuncompCGL model and all the observed time points in newx. Then interpolation is conducted on sseq. If matrix X after integral is provided in the FuncompCGL object, these parameters are required.

Value

The prediction values at the requested value(s) for s and k. If k is a vector, a list of prediction matrix is returned, otherwise a prediction matrix is returned.

Author(s)

Zhe Sun and Kun Chen

References

Sun, Z., Xu, W., Cong, X., Li G. and Chen K. (2020) Log-contrast regression with functional compositional predictors: linking preterm infant's gut microbiome trajectories to neurobehavioral outcome, https://arxiv.org/abs/1808.02403 Annals of Applied Statistics

See Also

cv.FuncompCGL and FuncompCGL, and coef and plot methods for "cv.FuncompCGL" object.

Examples


df_beta = 5
p = 30
beta_C_true = matrix(0, nrow = p, ncol = df_beta)
beta_C_true[1, ] <- c(-0.5, -0.5, -0.5 , -1, -1)
beta_C_true[2, ] <- c(0.8, 0.8,  0.7,  0.6,  0.6)
beta_C_true[3, ] <- c(-0.8, -0.8 , 0.4 , 1 , 1)
beta_C_true[4, ] <- c(0.5, 0.5, -0.6  ,-0.6, -0.6)
n_train = 50
n_test = 30
Data <- Fcomp_Model(n = n_train, p = p, m = 0, intercept = TRUE,
                    SNR = 4, sigma = 3, rho_X = 0, rho_T = 0.6, df_beta = df_beta,
                    n_T = 20, obs_spar = 1, theta.add = FALSE,
                    beta_C = as.vector(t(beta_C_true)))
arg_list <- as.list(Data$call)[-1]
arg_list$n <- n_test
Test <- do.call(Fcomp_Model, arg_list)
k_list = c(4,5)
cv_m1 <-  cv.FuncompCGL(y = Data$data$y, X = Data$data$Comp,
                        Zc = Data$data$Zc, intercept = Data$data$intercept,
                        k = k_list, nfolds = 5)
y_hat = predict(cv_m1, Znew = Test$data$Comp, Zcnew = Test$data$Zc)
predict(cv_m1, Znew = Test$data$Comp, Zcnew = Test$data$Zc, s = "lam.1se")
predict(cv_m1, Znew = Test$data$Comp, Zcnew = Test$data$Zc, s = c(0.5, 0.1, 0.05), k = k_list)
plot(Test$data$y, y_hat, xlab = "Observed Response", ylab = "Predicted Response")



[Package Compack version 0.1.0 Index]