R/get_poly_hatmatrix.R

Defines functions get_poly_hatmatrix

#' @noRd
#' @importFrom stats lm coef
#' @noRd
get_poly_hatmatrix <- function(df_treatment_A1, params_grid, mse, ...) {
  # this function calculates the hat matrix of the treatment model for A1
  # using a polynomial basis expansion.
  params <- unlist(params_grid)
  A <- matrix(1, nrow = NROW(df_treatment_A1))
  for (j in seq_len(length(params))) {
    A <- cbind(A, poly(df_treatment_A1[, j + 1], degree = params[j]))
  }
  poly_hatmatrix <- A %*% chol2inv(chol(t(A) %*% A)) %*% t(A)

  return(list(
    weight = poly_hatmatrix,
    mse = mse
  ))
}

Try the TSCI package in your browser

Any scripts or data that you put into this service are public.

TSCI documentation built on Oct. 10, 2023, 1:06 a.m.