Learn R Programming

ctmva (version 1.6.0)

mds.ct: Continuous-time multidimensional scaling

Description

A continuous-time version of classical multidimensional scaling.

Usage

mds.ct(
  d,
  argvals = NULL,
  weights = "equal",
  nbasis = 10,
  norder = 4,
  breaks = NULL,
  k = 2,
  smooth = "sandwich",
  lambda = exp(-10:20),
  gcvplot = TRUE,
  Im.tol = 1e-15,
  recenter = TRUE
)

Value

An object of class "mds.ct", which is a list with components

funcs

an object of class "fd" giving the \(k\) principal coordinate functions

evals

eigenvalues

argvals

the given time points

GOF

a \(k \times 2\) matrix giving the proportion of dissimilarity explained, according to the two definitions used by the GOF component of the output from cmdscale

sandwich

output of s3, if smooth=="sandwich"

recenter

value of the argument recenter

Arguments

d

matrix of dissimilarities

argvals

time points

weights

quadrature weights for the time points: either "equal" (default) or "trap" (trapezoidal, recommended for unequally spaced times)

nbasis

number of B-spline basis functions

norder

order of B-splines (degree plus 1); default is 4 (cubic splines)

breaks

knots, including the endpoints of the time range

k

number of principal coordinates

smooth

bivariate smoothing method: "sandwich" (default) for the sandwich smoother, "one-step" for a more traditional but slower tensor product smoother

lambda

smoothing parameter

gcvplot

logical: Should a plot of log lambda versus the GCV criterion be produced?

Im.tol

tolerance for imaginary component of eigenvalues: imaginary components with magnitude below this is set to zero, those above it generate an error.

recenter

logical: Should the solution be double-centered?

Author

Philip Tzvi Reiss <reiss@stat.haifa.ac.il>

See Also

cmdscale, for the classical version

Examples

Run this code

if (interactive() && 
    requireNamespace("fda", quietly = TRUE) &&
    requireNamespace("viridisLite", quietly = TRUE) &&
    requireNamespace("vegan", quietly = TRUE)) {
    
    require(ggplot2)
    
    data("handwrit", package = "fda")
    
    fives <- 5 * 0:280  + 1
    hw <- handwrit[ , 1, ]
    sd. <- .015
    
    hh <- cbind(hw[fives,], rnorm(281, sd=sd.))
    classical <- cmdscale(dist(hh), eig=TRUE)
    ctmds <- mds.ct(dist(hh), argvals=handwritTime[fives], nbasis=100, recenter=TRUE,
                    weights="trap", norder=7, lambda=exp(2:40))  
                    # a plot of GCV versus lambda is produced
    
    pro.classical <- vegan::procrustes(hw[fives,], classical, scale=FALSE)
    dat.classical <- as.data.frame(pro.classical$Yrot)
    pro.ctmds <- vegan::procrustes(hw[fives,], fda::eval.fd(ctmds$argvals, ctmds$funcs),
                                   scale=FALSE)
    dat.ctmds <- as.data.frame(matrix(pro.ctmds$translation, length(handwritTime), 2, byrow=TRUE) +
                                   fda::eval.fd(handwritTime, ctmds$funcs) %*% pro.ctmds$rotation)
    names(dat.classical) <- names(dat.ctmds) <- c("x", "y")
    dat.classical$time <- handwritTime[fives]
    dat.ctmds$time <- handwritTime
    
    # Plot of classical (dots) versus continuous-time (curve) MDS reconstructions
    # of the handwritten "fda" (grey), corrupted by noise
    g1 <- ggplot(hw, aes(x=X, y=Y)) + geom_point(color="darkgrey", size=.6) + coord_fixed() +
        geom_point(data = dat.classical, aes(x, y, color = time), size=1) +
        geom_point(data = dat.ctmds, aes(x, y, color = time), size=.6) +
        scale_color_gradientn(colors=viridisLite::plasma(50)) + 
        labs(x="", y="", color="Time (ms)", 
             title=bquote(sigma == .(sd.) * ", " 
                          ~ .(round(100*ctmds$GOF[2,1], 1)) * "% explained")) 
    print(g1)
    
    g2 <- plot(ctmds)  # uses plot.mds.ct
    print(g2)
    
    g3 <- procrustes.plot.mds(ctmds, dat.classical[ , 1:2])
    print(g3)
    
}

Run the code above in your browser using DataLab