swh:1:snp:3a44eb759780145deea094ac2a25c5049546a085
Tip revision: 3f1e499ee5781c8bb48a137218bd7b9d01642fae authored by Han Lin Shang on 14 September 2011, 06:20:57 UTC
version 2.7
version 2.7
Tip revision: 3f1e499
unitsimpls.R
unitsimpls = function(Xtrain, Ytrain, Xtest = NULL, ncomp = NULL, weight = FALSE, beta)
{
pls.out <- simpls(Xtrain = Xtrain, Ytrain = Ytrain, Xtest = Xtest, ncomp, weight = weight, beta = beta)
euclidian.norm <- function(xvec) {
return(sqrt(sum(xvec * xvec)))
}
R.norm <- apply(pls.out$R, 2, euclidian.norm)
if (length(R.norm) == 1) {
M <- matrix(R.norm, 1, 1)
Mi <- matrix(1/R.norm, 1, 1)
}
else {
M <- diag(R.norm)
Mi <- diag(1/R.norm)
}
Rnew <- pls.out$R %*% Mi
Tnew <- pls.out$T %*% Mi
Qnew <- pls.out$Q %*% M
Pnew <- pls.out$P %*% M
if (!is.null(Xtest))
if (weight == TRUE){
list(B = pls.out$B, Ypred = pls.out$Ypred, P = Pnew,
Q = Qnew, T = Tnew, R = Rnew, meanX = pls.out$meanX, weight = pls.out$weight)
}
else {
list(B = pls.out$B, Ypred = pls.out$Ypred, P = Pnew,
Q = Qnew, T = Tnew, R = Rnew, meanX = pls.out$meanX)
}
else
if (weight == TRUE){
list(B = pls.out$B, P = Pnew, Q = Qnew, T = Tnew, R = Rnew,
meanX = pls.out$meanX, meanY = pls.out$meanY, weight = weight)
}
else {
list(B = pls.out$B, P = Pnew, Q = Qnew, T = Tnew, R = Rnew,
meanX = pls.out$meanX, meanY = pls.out$meanY)
}
}