Dear R community, I am analyzing plant communities with the function mvpart, using a dissimilarit matrix as input. The matrix is calculated with the funtion gdist. fit <- mvpart(gdist (ba12[,18:29], meth="maximum", full=TRUE, sq=F) ~ beers + slope_dem + elev_dem+ plc_dem + pr_curv+ +curv+max_depth+doc_rocks+ abandon+land_use+ca_old, data=ba12, xv="p") This works fine. Now I would like to use other dissimilarity measures as can be found in the function dist (STATS) or vegdist (VEGAN). De'Ath notes that gdist should be interchangeable with dist - but I receive following error message: > fit21 <- mvpart(dist (ba12[,18:29], meth="minkowski", diag=T, upper=T p=2) ~ beers + slope_dem + elev_dem+ plc_dem + pr_curv+ curv+max_depth+doc_rocks+ abandon+land_use+ca_old, data=ba12, xv="p") Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : Variable lengths differ When computing the matrices directly... ba12.dist1 <- gdist (ba12[,18:29], method="maximum", full=T, sq=F) ba12.dist2 <- vegdist (ba12[,18:29], method="jaccard", diag=T, upper=T) ba12.dist3 <- dist (ba12[,18:29], method="minkowski", p=1, diag=T, upper=T) and looking at them, there appears to be no difference though only ba12.dist1 works with mvpart. With the other two I get the same error message as above. What I am missing? Where is the problem? Thanks for helping. Sina University of Potsdam, Germany Department of Geoecology
On Wed, 2006-03-08 at 19:12 +0100, Sina Muster wrote:> Dear R community, > > What I am missing? Where is the problem?That dist returns an object of class "dist", even if you use upper TRUE. ?dist says: upper: logical value indicating whether the upper triangle of the distance matrix should be printed by 'print.dist'. Beware confusing the printed representation of the object with what the object actually looks like. The reason gdist works, is that is does not do what its help page says: Value: Should be interchangeable with 'dist' and returns a distance object of the same type. Which the following sequence illustrates does not happen (using the spider dataset from mvpart):> spider.dist <- gdist(spider[1:12,]) > class(spider.dist)[1] "dist"> spider.dist <- gdist(spider[1:12,], full = TRUE) > class(spider.dist)[1] "matrix" You might consider contacting the maintainer and submit a bug report to him about this... So even though you thought the two (dist and gdist) were the same, they are not. To solve this problem then, a simple modification to your mvpart call is required, as shown below:> spider.dist2 <- dist(spider[, 1:12], method="minkowski", p=1, diag=T,upper=T)> class(spider.dist2)[1] "dist"> mvpart(spider.dist2~herbs+reft+moss+sand+twigs+water,spider)Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : variable lengths differ> mvpart(as.matrix(spider.dist2)~herbs+reft+moss+sand+twigs+water,spider) The key is the as.matrix() wrapped around the lhs of the formula. It would have been useful if you'd included an reproducible example using a built in data set - like I do above. Readers of the list wont have your "ba12", so extra work is required to investigate the problem.> > Thanks for helping. > SinaYou're welcome, hope this helps. Gav -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way [W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%