diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2016-02-10 15:27:35 -0500 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2016-02-10 15:27:35 -0500 |
| commit | 904e559845f48f38c7eb928d65876e3a064a17c7 (patch) | |
| tree | 1d4153ad46cfe94bda2bd5dc3105acf67b2dc994 /R/preprocess.R | |
| parent | redefine gamma to correspond to theory (diff) | |
| download | sparsestep-904e559845f48f38c7eb928d65876e3a064a17c7.tar.gz sparsestep-904e559845f48f38c7eb928d65876e3a064a17c7.zip | |
add documentation, unify implementations of path and fit
Diffstat (limited to 'R/preprocess.R')
| -rw-r--r-- | R/preprocess.R | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/R/preprocess.R b/R/preprocess.R new file mode 100644 index 0000000..253394e --- /dev/null +++ b/R/preprocess.R @@ -0,0 +1,38 @@ +preprocess <- function(x, y, normalize, intercept, XX, Xy, use.XX, use.Xy) +{ + nm <- dim(x) + nobs <- nm[1] + nvars <- nm[2] + one <- rep(1, nobs) + + if (intercept) { + meanx <- drop(one %*% x)/nobs + x <- scale(x, meanx, FALSE) + a0 <- mean(y) + y <- drop(y - a0) + } else { + meanx <- rep(0, nvars) + a0 <- 0 + y <- drop(y) + } + + if (normalize) { + normx <- sqrt(drop(one %*% (x^2))) + names(normx) <- NULL + x <- scale(x, FALSE, normx) + cat("Normalizing in sparsestep\n") + } else { + normx <- rep(1, nvars) + } + + if (use.XX & is.null(XX)) { + XX <- t(x) %*% x + } + if (use.Xy & is.null(Xy)) { + Xy <- t(x) %*% y + } + + out <- list(nvars = nvars, normx = normx, a0 = a0, + XX = XX, Xy = Xy, meanx = meanx) + return(out) +} |
