R/valpredict.R

#' Prediction for the model
#'
#' @title Prediction for the model
#' @param model the object of 'val' generated by val function
#' @param newx new predictors, a vector
#' @param newz new assist variable, a vector
#' @export

valpredict <- function(model,newx,newz){
  if(class(model)!="val")
    stop("the model must be varying-coffecient!")
  n <- length(newx)
  p <- model$degree
  nknots <- model$nknots
  df <- p+nknots
  Psi <- bs(newz,df=df,degree = p)
  Psi <- as.matrix(Psi[1:n,1:df])
  theta <- Psi %*% model$coef
  predict <- diag(newx) %*% theta
  predict
}
elara7/VCM documentation built on May 16, 2019, 2:58 a.m.