From 8b8a9236b07023c1c4c436870c3939f7254a66fb Mon Sep 17 00:00:00 2001 From: Kristian Hovde Liland Date: Tue, 25 Apr 2023 10:17:01 +0200 Subject: [PATCH] New bugfix in predict.rosa() and coef.rosa() --- NEWS | 2 +- R/rosa_results.R | 8 ++++---- man/rosa_results.Rd | 24 ++++++++++++++++++++++-- src/multiblock.so | Bin 221034 -> 221034 bytes 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index b8d0f5b..63c7c57 100644 --- a/NEWS +++ b/NEWS @@ -7,7 +7,7 @@ Kristian Hovde Liland ##### Version 0.8.6 Date: 25 April 2023 ->> Corrected error in coef.rosa() also affecting predict.rosa() (ncomp did no return all comps up to ncomp). +>> Corrected error in predict.rosa() (wrong intercept when using coefs argument). >> Extended documentation for coef.rosa() and predict.rosa(). ##### Version 0.8.5 diff --git a/R/rosa_results.R b/R/rosa_results.R index e07210f..2922dad 100644 --- a/R/rosa_results.R +++ b/R/rosa_results.R @@ -5,8 +5,8 @@ #' @param object A \code{rosa} object. #' @param x A \code{rosa} object. #' @param newdata Optional new data with the same types of predictor blocks as the ones used for fitting the object. -#' @param ncomp An \code{integer} giving the number of components to use apply (cummulative). -#' @param comps An \code{integer} vector giving the exact components to apply. +#' @param ncomp An \code{integer} giving the number of components to apply (cummulative). +#' @param comps An \code{integer} vector giving the exact components to apply (subset). #' @param type For \code{predict}: A \code{character} indicating if responses or scores should be predicted (default = "response", or "scores") #' @param type For \code{blockexpl}: Character indicating which type of explained variance to compute (default = "train", alternative = "CV"). #' @param na.action Function determining what to do with missing values in \code{newdata}. @@ -110,7 +110,7 @@ predict.rosa <- function(object, newdata, ncomp = 1:object$ncomp, comps, } else { ## Predict with a model containing the components `comps' B <- rowSums(coef(object, comps = comps), dims = 2) - B0 <- object$Ymeans# - object$Xmeans %*% B + B0 <- object$Ymeans - object$Xmeans %*% B pred <- newX %*% B + rep(c(B0), each = nobs) if (missing(newdata) && !is.null(object$na.action)) pred <- napredict(object$na.action, pred) @@ -140,7 +140,7 @@ coef.rosa <- function(object, ncomp = object$ncomp, comps, intercept = FALSE, { if (missing(comps) || is.null(comps)) { ## Cumulative coefficients: - B <- object$coefficients[,,1:ncomp, drop=FALSE] + B <- object$coefficients[,,ncomp, drop=FALSE] if (intercept == TRUE) { # Intercept has only meaning for # cumulative coefficients dB <- dim(B) diff --git a/man/rosa_results.Rd b/man/rosa_results.Rd index 4c37fc8..0ae998c 100644 --- a/man/rosa_results.Rd +++ b/man/rosa_results.Rd @@ -50,11 +50,11 @@ rosa.classify(object, classes, newdata, ncomp, LQ) \item{newdata}{Optional new data with the same types of predictor blocks as the ones used for fitting the object.} -\item{ncomp}{An \code{integer} giving the number of components to use apply.} +\item{ncomp}{An \code{integer} giving the number of components to use apply (cummulative).} \item{comps}{An \code{integer} vector giving the exact components to apply.} -\item{type}{Character indicating which type of explained variance to compute (default = "train", alternative = "CV").} +\item{type}{For \code{blockexpl}: Character indicating which type of explained variance to compute (default = "train", alternative = "CV").} \item{na.action}{Function determining what to do with missing values in \code{newdata}.} @@ -92,6 +92,26 @@ Explained variances are available (block-wise and global) through \code{blockexp Scores and loadings have their own extensions of \code{scores()} and \code{loadings()} throught \code{scores.rosa} and \code{loadings.rosa}. Finally, there is work in progress on classifcation support through \code{rosa.classify}. + +When \code{type} is \code{"response"} (default), predicted response values +are returned. If \code{comps} is missing (or is \code{NULL}), predictions +for \code{length(ncomp)} models with \code{ncomp[1]} components, +\code{ncomp[2]} components, etc., are returned. Otherwise, predictions for +a single model with the exact components in \code{comps} are returned. +(Note that in both cases, the intercept is always included in the +predictions. It can be removed by subtracting the \code{Ymeans} component +of the fitted model.) + +If \code{comps} is missing (or is \code{NULL}), \code{coef()[,,ncomp[i]]} +are the coefficients for models with \code{ncomp[i]} components, for \eqn{i += 1, \ldots, length(ncomp)}. Also, if \code{intercept = TRUE}, the first +dimension is \eqn{nxvar + 1}, with the intercept coefficients as the first +row. + +If \code{comps} is given, however, \code{coef()[,,comps[i]]} are the +coefficients for a model with only the component \code{comps[i]}, i.e., the +contribution of the component \code{comps[i]} on the regression +coefficients. } \examples{ data(potato) diff --git a/src/multiblock.so b/src/multiblock.so index 3f3690415d143002b61f6c10566ddf20563f0d05..cde02211c06bdc72d06bc52d69ad0b1082762c10 100755 GIT binary patch delta 102 zcmV-s0Ga>lz76WW4S<9Jv;v@U0$z)^qHzL#6ar$4w<3lDXxBhQeg{>LJ(@5(L&ra7 z$%Mth?cA=Rzml$dLiA`ZoZtFe(i0vlsHU3_=RZ_2A5foDa2axeu4#Bgj4+DhQ_E+! I%3TAX0Z3FXpa1{> delta 102 zcmV-s0Ga>lz76WW4S<9Jv;v@U0yKTMqHzL#6aqJWw<3lDXxBhc9#YbKp51-@Wrex` zc6$f)3m;?V3Q@*OW7h!8mShcMMOVuXI5w?sLQQ7F`NBcQ$O3hDjb9jW4_cyX5tR71 I%3TAX0nJ7$_W%F@