R/RcppExports.R

Defines functions cov_robust wt_mean wls_est arma_reshape ssr_est

Documented in arma_reshape cov_robust ssr_est wls_est wt_mean

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Estimate residual sum of squares
#' @description calculate SSR where
#' \eqn{SSR(\beta) = u'D'Du.}
#' @param r residuals
#' @param s weighting matrix
#' @param w vector of weights
#' @export
ssr_est <- function(r, s, w) {
    .Call(`_nlsur_ssr_est`, r, s, w)
}

#' Reshape matrix for blockwise WLS estimation
#' @param mm a matrix
#' @param sizetheta integer of length(theta) to shrink mm into
#' @description reshape mm for blockwise multiplication in wls_est
#' @examples
#' mm <- matrix(c(11,21,31,41,
#'  12,22,32,42,
#'  13,23,33,43,
#'  14,24,34,44),
#'  ncol = 4)
#'
#' mm_a <- arma_reshape(mm, 2)
#'
#' mm_m <- matrix(t(mm), nrow = 2, byrow = TRUE)
#' @export
arma_reshape <- function(mm, sizetheta) {
    .Call(`_nlsur_arma_reshape`, mm, sizetheta)
}

#' Blockwise WLS estimation
#' @description
#' Blockwise WLS estimation. Usually for \eqn{(X'X)^{-1} W^{-1} X'Y} X and Y
#' X, W and Y are of similar dimensions. In nlsur W is a cov-matrix of size
#' \eqn{k \times k} and usually way smaller than X. To avoid blowing all
#' matrices up for the estimation, a blockwise approach is used. X is shrunken
#' to match size k. W is D'D so XDX is calculated. XDy is only calculated if
#' wanted for a full WLS. For the cov-matrix only XDX is required.
#' @param x matrix of derivatives
#' @param r residual matrix
#' @param qS weighting matrix of sizetheta x sizetheta
#' @param w vector of weights
#' @param sizetheta integer defining the amount of coefficients
#' @param fullreg bool defining if WLS or Cov is calculated
#' @param tol tolerance used for qr()
#' @details as reference see:
#' http://www.navipedia.net/index.php/Block-Wise_Weighted_Least_Square
#' @export
wls_est <- function(x, r, qS, w, sizetheta, fullreg, tol) {
    .Call(`_nlsur_wls_est`, x, r, qS, w, sizetheta, fullreg, tol)
}

#' Calculate a weighted mean
#' @param x matrix of derivatives
#' @param w vector of weights
#' @export
wt_mean <- function(x, w) {
    .Call(`_nlsur_wt_mean`, x, w)
}

#' Calculate a robust covariance matrix
#'
#' @param x matrix of derivatives
#' @param u u
#' @param qS weighting matrix
#' @param w vector of weights
#' @param sizetheta sizetheta
#' @description As discussed in Wooldridge (2002, 160)
#' @export
cov_robust <- function(x, u, qS, w, sizetheta) {
    .Call(`_nlsur_cov_robust`, x, u, qS, w, sizetheta)
}
JanMarvin/nlsur documentation built on June 24, 2024, 2:58 a.m.