Skip to content

Commit

Permalink
- corrected bug with nPoints() method of MDS class, due to slightly…
Browse files Browse the repository at this point in the history
… modified

behaviour of `dist` S3 class in R4.5.
- updated doc of computeMetricMDS (return value)
  • Loading branch information
phauchamps committed Nov 16, 2024
1 parent 06f0c02 commit 17a5ce3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 43 deletions.
12 changes: 9 additions & 3 deletions R/MDS-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 1 addition & 19 deletions R/stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion man/MDS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 1 addition & 20 deletions man/computeMetricMDS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/test-MDS-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit 17a5ce3

Please sign in to comment.