Dear all, Could you please point me out to a function or set of functions that would allow me to optimize positions on the 2D map of points for which I are distance contrainted? for example, if I have: a b c a 0.0 0.5 0.7 b 0.5 0.0 0.3 c 0.7 0.3 0.0 I would like to obtain (x,y) coordinates to plot A,B,C so that the distance constraints are satisfied. i.e. a is 0.5 far from b, and o.7 far from c. etc ... Many thanks for your help, Best, Emmanuel
Look at the cmdscale function (there are variations in some packages, but that should get you started). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Emmanuel Levy > Sent: Thursday, April 05, 2007 7:05 AM > To: r-help at stat.math.ethz.ch > Subject: [R] Transform distance constraints into a 2D-map > > Dear all, > > Could you please point me out to a function or set of > functions that would allow me to optimize positions on the 2D > map of points for which I are distance contrainted? > > for example, if I have: > a b c > a 0.0 0.5 0.7 > b 0.5 0.0 0.3 > c 0.7 0.3 0.0 > > I would like to obtain (x,y) coordinates to plot A,B,C so > that the distance constraints are satisfied. i.e. a is 0.5 > far from b, and o.7 far from c. etc ... > > Many thanks for your help, > > Best, > > Emmanuel > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
On 05-Apr-07 13:05:29, Emmanuel Levy wrote:> Dear all, > > Could you please point me out to a function or set of functions > that would allow me to optimize positions on the 2D map of points > for which I are distance contrainted? > > for example, if I have: > a b c > a 0.0 0.5 0.7 > b 0.5 0.0 0.3 > c 0.7 0.3 0.0 > > I would like to obtain (x,y) coordinates to plot A,B,C so that the > distance constraints are satisfied. i.e. a is 0.5 far from b, and o.7 > far from c. etc ... > > Many thanks for your help, > > Best, > > EmmanuelProbably any of the multidimensional scaling functions variously available would do (it is not clear what you mean by "optimize", though). In your example above, an exact solution exists. For example library(MASS) D<-matrix(c(0.0, 0.5, 0.7, 0.5, 0.0, 0.3, 0.7, 0.3, 0.0),nrow=3) rownames(D)<-c("a","b","c") colnames(D)<-c("a","b","c") P<-isoMDS(D)$points plot(P[,1],P[,2],pch="+",col="blue") P ## [,1] [,2] ## a 0.39114338 0.03809598 ## b -0.08358748 -0.11884547 ## c -0.30755590 0.08074949 dist(P) ## a b ## b 0.5 ## c 0.7 0.3 The last result shows that the distances betweem the three points in the 3 rows of P are as desired: a<->b=0.5, a<->c=0.7, b<->c=0.3 Hoping this helps! Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 05-Apr-07 Time: 16:29:49 ------------------------------ XFMail ------------------------------
Dear All, Thank you for your replies. That will definitly get me started. Ted: I said optimize because I suppose that an exact solution does not necessarily exists sometimes. Best, Emmanuel On 4/5/07, Ted Harding <ted.harding at nessie.mcc.ac.uk> wrote:> On 05-Apr-07 13:05:29, Emmanuel Levy wrote: > > Dear all, > > > > Could you please point me out to a function or set of functions > > that would allow me to optimize positions on the 2D map of points > > for which I are distance contrainted? > > > > for example, if I have: > > a b c > > a 0.0 0.5 0.7 > > b 0.5 0.0 0.3 > > c 0.7 0.3 0.0 > > > > I would like to obtain (x,y) coordinates to plot A,B,C so that the > > distance constraints are satisfied. i.e. a is 0.5 far from b, and o.7 > > far from c. etc ... > > > > Many thanks for your help, > > > > Best, > > > > Emmanuel > > Probably any of the multidimensional scaling functions variously > available would do (it is not clear what you mean by "optimize", > though). In your example above, an exact solution exists. > > For example > > library(MASS) > D<-matrix(c(0.0, 0.5, 0.7, 0.5, 0.0, 0.3, 0.7, 0.3, 0.0),nrow=3) > rownames(D)<-c("a","b","c") > colnames(D)<-c("a","b","c") > > P<-isoMDS(D)$points > plot(P[,1],P[,2],pch="+",col="blue") > > P > ## [,1] [,2] > ## a 0.39114338 0.03809598 > ## b -0.08358748 -0.11884547 > ## c -0.30755590 0.08074949 > > dist(P) > ## a b > ## b 0.5 > ## c 0.7 0.3 > > The last result shows that the distances betweem the three points > in the 3 rows of P are as desired: a<->b=0.5, a<->c=0.7, b<->c=0.3 > > Hoping this helps! > Ted. > > -------------------------------------------------------------------- > E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk> > Fax-to-email: +44 (0)870 094 0861 > Date: 05-Apr-07 Time: 16:29:49 > ------------------------------ XFMail ------------------------------ >