compute_P1_moment <- function(Wbar, Zmat, meanSigmaU) {

  n <- nrow(Wbar)
  p <- ncol(Wbar)
  q <- ncol(Zmat)
  P_zero <- matrix(0, nrow = q, ncol = p)

  # Univariate case
  if (is.null(dim(meanSigmaU))) {

    # β–γ
    P_bg <- -sqrt(n) * crossprod(Wbar, Zmat) / n
    # γ–β
    P_gb <- -sqrt(n) * crossprod(Zmat, Wbar) / n
    # γ–γ
    P_gg <- -sqrt(n) * crossprod(Zmat) / n

    # β–β
    if (is.na(meanSigmaU)) {

      return(cbind(P_zero, P_gg))
    } else {
      P_bb <- sqrt(n) * (
        -crossprod(Wbar) / n + matrix(meanSigmaU, 1, 1)
      )
    }

  } else {

    if (any(is.na(meanSigmaU))) {
      # no replicate information
      # # β–β
      # P_bb <- sqrt(n) * ( -crossprod(Wbar) / n )
      # # β–γ
      # P_bg <- -sqrt(n) * crossprod(Wbar, Zmat) / n
      # # γ–β
      # P_gb <- -sqrt(n) * crossprod(Zmat, Wbar) / n
      # γ–γ
      P_gg <- -sqrt(n) * crossprod(Zmat) / n
      return(cbind(P_zero, P_gg))

    } else {
      # β–β
      P_bb <- sqrt(n) * ( -crossprod(Wbar) / n + meanSigmaU )
      # β–γ
      P_bg <- -sqrt(n) * crossprod(Wbar, Zmat) / n
      # γ–β
      P_gb <- -sqrt(n) * crossprod(Zmat, Wbar) / n
      # γ–γ
      P_gg <- -sqrt(n) * crossprod(Zmat) / n
    }

  }

  rbind(
    cbind(P_bb, P_bg),
    cbind(P_gb, P_gg)
  )
}
