[R] how to create initial configuraton for isoMDS
Sarah Goslee
sarah.goslee at gmail.com
Wed Apr 27 21:58:05 CEST 2016
Hi,
Your matrix needs to either be symmetric or an object of class dist.
Here's one way to reformat it:
Note that calling it dist is a poor idea, since dist() is a base function.
Also note that if the distance from 1-2 is 1 while distance from 2-1 is
Inf, as in your original matrix, then you probably need to reconsider
what you're doing.
dconfig <- as.dist(t(dist))
loc <- isoMDS(dconfig)
Sarah
LiLi (Z) wrote:
> Hi,
>
> I'm trying to use isoMDS to project a directed graph to 2-dim vectors, but I got an error.
>
> #here is the code to create the graph using igraph package and run isoMDS on it.
> library(igraph)
> library(MASS)
> g<-make_graph(c(1,2, 2,3, 2,4, 3,4, 4,5, 5,6, 3,6, 1,6, 2,5),directed=TRUE)
> dist<-distances(g, mode="out")
> loc<-isoMDS(dist)
>
> # below is content of the dist matrix
> [,1] [,2] [,3] [,4] [,5] [,6]
> [1,] 0 1 2 2 2 1
> [2,] Inf 0 1 1 1 2
> [3,] Inf Inf 0 1 2 1
> [4,] Inf Inf Inf 0 1 2
> [5,] Inf Inf Inf Inf 0 1
> [6,] Inf Inf Inf Inf Inf 0
>
> # and here is the error message:
> Error in isoMDS(dist) :
> an initial configuration must be supplied with NA/Infs in 'd'
>
> It appears that isoMDS doesn't like the "Inf" values in the dist matrix, although help(isoMDS) suggests it accepts them if proper initial configuration is provided:
> Arguments
> d
>
> distance structure of the form returned by dist, or a full, symmetric matrix. Data are assumed to be dissimilarities or relative distances, but must be positive except for self-distance. Both missing and infinite values are allowed.
>
> y
>
> An initial configuration. If none is supplied, cmdscale is used to provide the classical solution, unless there are missing or infinite dissimilarities.
>
> k
>
> The desired dimension for the solution, passed to cmdscale.
>
>
> My questions is: how do I provide the y argument for this example to work?
> Any help and suggestion is appreciated.
> Li
>
>
More information about the R-help
mailing list