R/estimate_beta.R

#' Unbiased estimator of fixed effects
#'
#' See (3) and (4) of Perry 2015.
#'
#' @param xz_svd_list A list of compact singular vector decomposition objects.
#' @param eta_list A list of numeric vectors encoding fixed and random effects.
#' @param w_list A list of positive definite matrices.
#' @return An unbiased estimate of the fixed effects.
estimate_beta <- function(xz_svd_list, eta_list, w_list) {
    V1_list <- Map(getElement, xz_svd_list, "V1")
	omega <- map_reduce_mean(function(V1, W) V1 %*% W %*% t(V1),
	                         V1_list, w_list)
	scaled_eta_sum <- map_reduce_mean(function(V1, W, eta) V1 %*% W %*% eta,
	                                  V1_list, w_list, eta_list)

	as.vector(solve(omega, scaled_eta_sum))
}
kschmaus/gammmbest documentation built on May 7, 2019, 9 p.m.