I have a dissimilarity dataset with the form: 1 1 dissimilarity value 1 2 ... 1 3 1 4 2 2 2 3 2 4 ... I would like to do nonmetric multidimensional scaling with this data, but I am having trouble using this format. I would like to either find a function that accepts this format or find a way to easily convert this format to a matrix for use with existing functions. Thanks! [[alternative HTML version deleted]]
Marcelino de la Cruz
2009-Feb-18 18:52 UTC
[R] multidimensional scaling with long form data
This is my approach: If "cosa" is your data.frame . e.g. >cosa i1 i2 dis [1,] 1 1 0.00 [2,] 1 2 0.93 [3,] 1 3 0.80 [4,] 1 4 1.00 [5,] 2 2 0.00 [6,] 2 3 0.02 [7,] 2 4 0.22 [8,] 3 3 0.00 [9,] 3 4 0.95 [10,] 4 4 0.00 # first crate a square matrix of 0´s, of the appropriate dimensions (in this example, 4) pepe <- matrix(0, nr=4, nc=4) # then assign your long disimilarity data to trhe lower tree of the square matrix # check the diag argument! pepe[lower.tri(pepe, diag=T)] <- cosa[,3] # then transpose the matrix pepe <- t(pepe) # and symmetrize the resulting matrix library(calibrator) pepe <- symmetrize(pepe) # finaly, transform to a dist matrix: pepe <- as.dist (pepe) HTH, Marcelino kirsten-beyer@uiowa.edu wrote: I have a dissimilarity dataset with the form: 1 1 dissimilarity value 1 2 ... 1 3 1 4 2 2 2 3 2 4 ... I would like to do nonmetric multidimensional scaling with this data, but I am having trouble using this format. I would like to either find a function that accepts this format or find a way to easily convert this format to a matrix for use with existing functions. Thanks! ________________________________ Marcelino de la Cruz Rot Departamento de Biología Vegetal E.U.T.I. Agrícola Universidad Politécnica de Madrid 28040-Madrid Tel.: 91 336 54 35 Fax: 91 336 56 56 marcelino.delacruz@upm.es _________________________________ [[alternative HTML version deleted]]