Frank J. Iannarilli, Jr.
2004-Sep-02 21:06 UTC
[R] Fixes for pls.pcr 0.2.2 plot.mvr("prediction")
Hi, I just sent the following bugfixes to author Ron Wehrens, but thought I should also make them available here. This fixes the prediction plots, which are currently erroneous. ====================== I found some bugs in the the plot.mvr() function, in the plottype="prediction" section: 1. Needs to set nscreens <- 1 for condition where length(which) = 1 AND length(nlv) = 1. Otherwise, for such condition, the function exits with message "Error: Object nscreens not found". Here is your code snippet, and my suggested addition is indicated by ========>>>>>>>>>>: if (length(which) > 1) { if (length(nlv) > 3) { par(ask = TRUE) par(mfrow = c(3, 2)) nScreens <- ceiling(length(nlv)/3) } else { nScreens <- 1 par(mfrow = c(length(nlv), 2)) } } else { if (length(nlv) > 1) { nrow <- floor(sqrt(length(nlv))) mfrow <- c(nrow, ceiling(length(nlv)/nrow)) par(mfrow = mfrow) nScreens <- 1 } ======>>>>>nScreens <- 1 } 2. The prediction plots are being drawn based on incorrect indexing of the Ypred matrix -- this can be quite misleading :-) Here is your code snippet: Basically, need to replace all occurrences of mvrmodel$training$Ypred[, i, j] or mvrmodel$validat$Ypred[, i, j] WITH mvrmodel$training$Ypred[, i, nlv[j]] or mvrmodel$validat$Ypred[, i, nlv[j]] for (j in indices) { if (show[1]) { plot(mvrmodel$Y[, i], mvrmodel$training$Ypred[, i, j], xlab = "Measured", ylab = "Predicted", type = "n", xlim = range(mvrmodel$Y[, i], mvrmodel$training$Ypred[, i, j]), ylim = range(mvrmodel$Y[, i], mvrmodel$training$Ypred[, i, j]), main = paste("Training data\n", nlv[j], "latent variables")) if (npred > 1) mtext(ynames[i]) abline(0, 1, col = "blue") points(mvrmodel$Y[, i], mvrmodel$training$Ypred[, i, j]) } if (show[2]) { plot(mvrmodel$Y[, i], mvrmodel$validat$Ypred[, i, j], xlab = "Measured", ylab = "Predicted", type = "n", xlim = range(mvrmodel$Y[, i], mvrmodel$validat$Ypred[, i, j]), ylim = range(mvrmodel$Y[, i], mvrmodel$validat$Ypred[, i, j]), main = paste("Cross-validation data\n", nlv[j], "latent variables")) if (npred > 1) mtext(ynames[i]) abline(0, 1, col = "blue") points(mvrmodel$Y[, i], mvrmodel$validat$Ypred[, i, j]) Regards, Frank J. Iannarilli, Jr. frankeye at cox.net www.aerodyne.com/cosr/cosr.html