R/lm.parboot.R

Defines functions lm.parboot

Documented in lm.parboot

#[export]
lm.parboot <- function(x, y, R = 1000) {
   x <- model.matrix( y~., data.frame(x) )
   xx <- tcrossprod( Rfast::spdinv( crossprod(x) ), x ) 
   be <- xx %*% y
   dm <- dim(x)
   n <- dm[1]   ;    p <- dm[2]
   est <- as.vector( x %*% be ) 
   s <- Rfast::Var(y - est) * (n - 1)/(n - p)
   z <- Rfast::matrnorm(n, R)
   booty <- sqrt(s) * z + est
   xx %*% booty
}    


#[export]
lm.nonparboot <- function (x, y, R = 1000) {
    x <- model.matrix(y ~ ., data.frame(x))
    xx <- tcrossprod(Rfast::spdinv(crossprod(x)), x)
    be <- xx %*% y
    dm <- dim(x)
    n <- dm[1]
    p <- dm[2]
    est <- as.vector(x %*% be)
    res <- y - est
    s <- Rfast::Var(res) * (n - 1)/(n - p)
    z <- Rfast::rep_col(res, R)
    z <- Rfast::colShuffle(z)
    booty <- sqrt(s) * z + est
    xx %*% booty
}

Try the Rfast2 package in your browser

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

Rfast2 documentation built on May 29, 2024, 8:45 a.m.