R/updateBeta.R

Defines functions updateBeta

Documented in updateBeta

updateBeta <- function(B, X, y, k, intercept = TRUE, doff = FALSE)
  {
    XB <- X%*%B
    expXB <- exp(XB)
    p <- expXB/(1+expXB)
    p[is.infinite(expXB)] <- 1
    W <- diag(as.numeric((p*(1-p))),length(y),length(y))
    WZ <- p*(1-p)*XB+(y-p)    
    kI <- diag(2*k,dim(X)[2],dim(X)[2])
    if(intercept)
      kI[1,1] <- 0 ##Intercept
    updatedBeta <- (solve(t(X)%*%W%*%X+kI))%*%t(X)%*%WZ
    if(doff)
      {
        res = list(updatedBeta = updatedBeta, kI = kI, W = W)
      } else {
        res = updatedBeta
      }
    return(res)
  }

Try the ridge package in your browser

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

ridge documentation built on April 11, 2022, 5:05 p.m.