Hi list! I'm computing multivar. distances from a set of centroids to a (large) set of individuals. I'm now just using rbind to create a matrix (x) with the centroid and the individuals, then run as.matrix(dist(x)) and finally select the appropriate columns, as I'm not interested on the distances among individuals. Therefore, this procedure implies a waste of computing time. Is there any way to use dist only between each individual and the centroids (avoiding loops in R)? or should I just go and try to make a modified version of dist by hacking the C code? Thanks Dr. Agustin Lobo Instituto de Ciencias de la Tierra (CSIC) Lluis Sole Sabaris s/n 08028 Barcelona SPAIN tel 34 93409 5410 fax 34 93411 0012 alobo at ija.csic.es -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 19 Nov 2001, Agustin Lobo wrote:> > Hi list! > > I'm computing multivar. distances from a set of centroids > to a (large) set of individuals. I'm now just using rbind > to create a matrix (x) with the centroid and the individuals, > then run as.matrix(dist(x)) and finally select the appropriate columns, > as I'm not interested on the distances among individuals. > Therefore, this procedure implies a waste of computing time. > Is there any way to use dist only between each individual > and the centroids (avoiding loops in R)? or should I just go and try to > make > a modified version of dist by hacking the C code?You don't need C code for this. Take a look at e.g. predict.lda and predict.qda. You might want to do the individuals in batches if the number really is large (millions?). -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi Agustin You mingth not need this after Brain's reply but just in case... The package geoR has a function which might help loccoords(coords, locations) where the arguments are 2 column matrices with coordinates. The function which returns the distance between each element of coords (centroids) to each element of locations(individuals) The function is just a "wrapper" to a piece of C code Cheers P.J. On Mon, 19 Nov 2001, Agustin Lobo wrote:> > Hi list! > > I'm computing multivar. distances from a set of centroids > to a (large) set of individuals. I'm now just using rbind > to create a matrix (x) with the centroid and the individuals, > then run as.matrix(dist(x)) and finally select the appropriate columns, > as I'm not interested on the distances among individuals. > Therefore, this procedure implies a waste of computing time. > Is there any way to use dist only between each individual > and the centroids (avoiding loops in R)? or should I just go and try to > make > a modified version of dist by hacking the C code? > > Thanks > > Dr. Agustin Lobo > Instituto de Ciencias de la Tierra (CSIC) > Lluis Sole Sabaris s/n > 08028 Barcelona SPAIN > tel 34 93409 5410 > fax 34 93411 0012 > alobo at ija.csic.es > > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >Paulo Justiniano Ribeiro Jr Dept Maths & Stats - Fylde College Lancaster University Lancaster LA1 4YF - U.K. e-mail: Paulo.Ribeiro at est.ufpr.br http://www.maths.lancs.ac.uk/~ribeiro -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi all R-users: I am getting some differences from the loglin function in R and S-Plus. Is there a bug in the R function? Juan C. Correa> parentesco<-array(c(27,12,23,7,394,142,421,94,18,13,24,4,48,25,55,13,2,2,4,1,32,19,38,11,1,1,0,3,6,4,15,4),c(2,2,2,2,2)) Output from R 1.3.1> temp<-loglin(parentesco,list(c(3,4),c(1,2)), param=T)2 iterations: deviation 2.273737e-13> temp$lrt [1] 1126.472 $pearson [1] 968.6632 $df [1] 25 $margin $margin[[1]] [1] 1 2 $margin[[2]] [1] 3 4 $param $param$"(Intercept)" [1] 2.927703 $param$"1.5" [,1] [,2] [1,] 0.5819121 0.5819121 [2,] -0.5819121 -0.5819121 $param$"2" [1] 0.09264558 -0.09264558 $param$"3" [1] -0.9171482 0.9171482 $param$"4" [1] 0.5276034 -0.5276034 $param$"1.2.5" , , 1 [,1] [,2] [1,] -0.1396115 0.1396115 [2,] 0.1396115 -0.1396115 , , 2 [,1] [,2] [1,] -0.1396115 0.1396115 [2,] 0.1396115 -0.1396115 $param$"3.4" [,1] [,2] [1,] -0.4286906 0.4286906 [2,] 0.4286906 -0.4286906 ===========================================================Output from S-Plus 6> temp<-loglin(parentesco,list(c(3,4),c(1,2)), param=T)2 iterations: deviation 1.52588e-005> temp$lrt: [1] 1126.472 $pearson: [1] 968.6632 $df: [1] 25 $margin: $margin[[1]]: [1] 3 4 $margin[[2]]: [1] 1 2 $param: $constant: [1] 2.927703 $"1": [1] 0.5819121 -0.5819121 $"2": [1] 0.09264556 -0.09264556 $"1 X 2": [,1] [,2] [1,] -0.1396115 0.1396115 [2,] 0.1396115 -0.1396115 $"3": [1] -0.9171482 0.9171482 $"4": [1] 0.5276034 -0.5276034 $"3 X 4": [,1] [,2] [1,] -0.4286905 0.4286905 [2,] 0.4286905 -0.4286905>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._