diff --git a/R/MDS-class.R b/R/MDS-class.R index 1fad442..9be510d 100644 --- a/R/MDS-class.R +++ b/R/MDS-class.R @@ -45,12 +45,18 @@ #' #' @slot GoF `numeric`, vector of goodness of fit indicators, #' as a function of number of dimensions. -#' `GoF[nDim]` is the global goodness of fit. +#' `GoF[nDim]` is the global goodness of fit. +#' +#' Note pseudo R square and goodness of fit indicators are essentially the +#' same indicator, only the definition of total sum of squares differ: +#' - for pseudo RSq: TSS is calculated using the mean pairwise distance +#' as minimum +#' - for goodness of fit: TSS is calculated using 0 as minimum #' #' @slot smacofRes an object of class 'smacofB' containing the algorithmic #' optimization results, for example stress and stress per point, #' as returned by `smacof::smacofSym()` method. -#' +#' #' @exportClass MDS #' #' @return nothing @@ -168,7 +174,7 @@ nDim <- function(x) { #' @export nPoints <- function(x) { stopifnot(inherits(x, "MDS")) - return(dim(x@pwDist)[1]) + return(attr(x@pwDist, "Size")) } #' @rdname MDS diff --git a/R/stats.R b/R/stats.R index 7609d49..96fa2c3 100644 --- a/R/stats.R +++ b/R/stats.R @@ -1487,25 +1487,7 @@ channelSummaryStats <- function( #' @param maxDim in case `nDim` is found iteratively, #' maximum number of dimensions the search procedure is allowed to explore #' @param ... additional parameters passed to SMACOF algorithm -#' -#' @return a list with six elements: -#' - `$pwDist` the initial pair-wise distance (same as input) -#' - `$proj` the final configuration, i.e. the projected data matrix -#' (`nSamples` rows, `nDim` columns) in `nDim` dimensions -#' - `$projDist` the distance matrix of projected data -#' - `stress` the global stress loss function final value -#' obtained from the SMACOF algorithm -#' - `spp` the stress per point obtained from the SMACOF algorithm, i.e. -#' the contribution of each point to the stress loss function -#' - `$RSq` R squares, for each d, from 1 to `nDim`: -#' the (pseudo) R square when taking all dims from 1 to d. -#' - `$GoF` Goodness of fit, for each d, from 1 to `nDim`: -#' the goodness of fit indicator (b/w 0 and 1) when taking all dims from 1 to d. -#' Note pseudo R square and goodness of fit indicators are essentially the -#' same indicator, only the definition of total sum of squares differ: -#' - for pseudo RSq: TSS is calculated using the mean pairwise distance -#' as minimum -#' - for goodness of fit: TSS is calculated using 0 as minimum +#' @return an object of S4 class `MDS` #' #' @importFrom stats as.dist dist #' @export diff --git a/man/MDS.Rd b/man/MDS.Rd index 3120299..bc894cd 100644 --- a/man/MDS.Rd +++ b/man/MDS.Rd @@ -93,7 +93,15 @@ as a function of number of dimensions. \item{\code{GoF}}{\code{numeric}, vector of goodness of fit indicators, as a function of number of dimensions. -\code{GoF[nDim]} is the global goodness of fit.} +\code{GoF[nDim]} is the global goodness of fit. + +Note pseudo R square and goodness of fit indicators are essentially the +same indicator, only the definition of total sum of squares differ: +\itemize{ +\item for pseudo RSq: TSS is calculated using the mean pairwise distance +as minimum +\item for goodness of fit: TSS is calculated using 0 as minimum +}} \item{\code{smacofRes}}{an object of class 'smacofB' containing the algorithmic optimization results, for example stress and stress per point, diff --git a/man/computeMetricMDS.Rd b/man/computeMetricMDS.Rd index caed754..71be403 100644 --- a/man/computeMetricMDS.Rd +++ b/man/computeMetricMDS.Rd @@ -33,26 +33,7 @@ maximum number of dimensions the search procedure is allowed to explore} \item{...}{additional parameters passed to SMACOF algorithm} } \value{ -a list with six elements: -\itemize{ -\item \verb{$pwDist} the initial pair-wise distance (same as input) -\item \verb{$proj} the final configuration, i.e. the projected data matrix -(\code{nSamples} rows, \code{nDim} columns) in \code{nDim} dimensions -\item \verb{$projDist} the distance matrix of projected data -\item \code{stress} the global stress loss function final value -obtained from the SMACOF algorithm -\item \code{spp} the stress per point obtained from the SMACOF algorithm, i.e. -the contribution of each point to the stress loss function -\item \verb{$RSq} R squares, for each d, from 1 to \code{nDim}: -the (pseudo) R square when taking all dims from 1 to d. -\item \verb{$GoF} Goodness of fit, for each d, from 1 to \code{nDim}: -the goodness of fit indicator (b/w 0 and 1) when taking all dims from 1 to d. -Note pseudo R square and goodness of fit indicators are essentially the -same indicator, only the definition of total sum of squares differ: -\item for pseudo RSq: TSS is calculated using the mean pairwise distance -as minimum -\item for goodness of fit: TSS is calculated using 0 as minimum -} +an object of S4 class \code{MDS} } \description{ Multi-dimensional scaling projection of samples, diff --git a/tests/testthat/test-MDS-class.R b/tests/testthat/test-MDS-class.R index 78551d1..7b7caad 100644 --- a/tests/testthat/test-MDS-class.R +++ b/tests/testthat/test-MDS-class.R @@ -76,3 +76,12 @@ test_that("basic MDS class works", { smacofRes <- smacofRes(mdsObj) expect_equal(class(smacofRes), c("smacofB", "smacof")) }) + +test_that("MDS object export and reimport works", { + outputFile <- base::tempfile() + saveRDS(object = mdsObj, file = outputFile) + mdsObj2 <- readRDS(file = outputFile) + ret <- validObject(mdsObj2) + expect_true(ret) +}) + \ No newline at end of file