Hi,
the documentation of hopach says that the result of the distancevector and distancematrix functions should be "identical". However, that is not the case.
This is the example in the documentation:
mydata<-matrix(rnorm(50),nrow=10)
deuclid<-distancematrix(mydata,d="euclid")
# old method vdeuclid<-dissvector(deuclid)
vdeuclid<-deuclid@Data
ddaisy<-daisy(mydata)
vdeuclid ddaisy/sqrt(length(mydata[1,]))d1<-distancematrix(mydata,d="abscosangle")
d2<-distancevector(mydata,mydata[1,],d="abscosangle")
d1[1,] d2 #equal to d1[1,]
However, at least since hopach-2.50, the results of distancevector apply also the extra step used in "ddaisy/sqrt(length(mydata[1,]))"
> mydata<-matrix(rnorm(50),nrow=10)
> deuclid<-distancematrix(mydata,d="euclid")
> vdeuclid<-deuclid@Data
> ddaisy<-daisy(mydata)
> vdeuclid[1:10]
[1] 3.534428 2.764194 4.274093 4.037899 1.942037 5.592038 2.539513 1.451171 4.565247 1.354340
> ddaisy/sqrt(length(mydata[1,]))[1]
Dissimilarities :
1 2 3 4 5 6 7 8 9
2 1.5806443
3 1.2361851 0.6056791
4 1.9114325 0.7752572 0.9199244
5 1.8058033 1.3887343 1.4681481 1.3347749
6 0.8685054 1.2025777 0.9410266 1.7518570 1.6624963
7 2.5008355 2.0364315 2.2338201 2.4665746 1.8328549 1.8465481
8 1.1357047 0.9515974 0.8468085 1.1752720 0.8702290 0.9018104 1.7221714
9 0.6489835 1.4214805 0.9261624 1.6151358 1.7102315 0.8523305 2.4401483 0.9605887
10 2.0416405 2.1729064 2.0948553 2.2511179 1.4792959 1.8247131 1.5366251 1.3427259 1.8488145
Metric : euclidean
Number of objects : 10
> d1<-distancematrix(mydata,d="euclid")
> d2<-distancevector(mydata,mydata[1,],d="euclid")
> d1[1,]
1 2 3 4 5 6 7 8 9 10
1 0 3.534428 2.764194 4.274093 4.037899 1.942037 5.592038 2.539513 1.451171 4.565247
> d2
[1] 0.0000000 1.5806443 1.2361851 1.9114325 1.8058033 0.8685054 2.5008355 1.1357047 0.6489835 2.0416405
> d1[1,]/sqrt(length(mydata[1,]))
1 2 3 4 5 6 7 8 9 10
1 0 1.580644 1.236185 1.911433 1.805803 0.8685054 2.500836 1.135705 0.6489835 2.041641
Is this the intended behavior? Shouldn't both distancevector and distancematrix return the same without adding an extra step?? Since when is this happening?
Thanks,
Txema
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] hopach_2.54.0 Biobase_2.54.0 BiocGenerics_0.40.0 cluster_2.1.2 sfsmisc_1.1-12
[6] pheatmap_1.0.12 gridExtra_2.3 ggplot2_3.3.5 SeuratObject_4.0.4 Seurat_4.1.0
[11] MASS_7.3-55 Matrix_1.4-0
loaded via a namespace (and not attached):
[1] nlme_3.1-155 spatstat.sparse_2.1-0 matrixStats_0.61.0 RcppAnnoy_0.0.19 RColorBrewer_1.1-2
[6] httr_1.4.2 sctransform_0.3.3 tools_4.1.2 utf8_1.2.2 R6_2.5.1
[11] irlba_2.3.5 rpart_4.1.16 KernSmooth_2.23-20 uwot_0.1.11 mgcv_1.8-38
[16] lazyeval_0.2.2 colorspace_2.0-2 withr_2.4.3 tidyselect_1.1.1 compiler_4.1.2
[21] cli_3.2.0 plotly_4.10.0 scales_1.1.1 spatstat.data_2.1-2 lmtest_0.9-39
[26] ggridges_0.5.3 pbapply_1.5-0 goftest_1.2-3 stringr_1.4.0 digest_0.6.29
[31] spatstat.utils_2.3-0 pkgconfig_2.0.3 htmltools_0.5.2 parallelly_1.30.0 fastmap_1.1.0
[36] htmlwidgets_1.5.4 rlang_1.0.1 shiny_1.7.1 generics_0.1.2 zoo_1.8-9
[41] jsonlite_1.7.3 spatstat.random_2.1-0 ica_1.0-2 dplyr_1.0.8 magrittr_2.0.2
[46] patchwork_1.1.1 Rcpp_1.0.8 munsell_0.5.0 fansi_1.0.2 abind_1.4-5
[51] reticulate_1.24 lifecycle_1.0.1 stringi_1.7.6 Rtsne_0.15 plyr_1.8.6
[56] grid_4.1.2 parallel_4.1.2 listenv_0.8.0 promises_1.2.0.1 ggrepel_0.9.1
[61] crayon_1.5.0 deldir_1.0-6 miniUI_0.1.1.1 lattice_0.20-45 cowplot_1.1.1
[66] splines_4.1.2 tensor_1.5 pillar_1.7.0 igraph_1.2.11 spatstat.geom_2.3-2
[71] future.apply_1.8.1 reshape2_1.4.4 codetools_0.2-18 leiden_0.3.9 glue_1.6.1
[76] data.table_1.14.2 BiocManager_1.30.16 png_0.1-7 vctrs_0.3.8 httpuv_1.6.5
[81] polyclip_1.10-0 gtable_0.3.0 RANN_2.6.1 purrr_0.3.4 spatstat.core_2.4-0
[86] tidyr_1.2.0 scattermore_0.8 future_1.23.0 mime_0.12 xtable_1.8-4
[91] later_1.3.0 survival_3.2-13 viridisLite_0.4.0 tibble_3.1.6 globals_0.14.0
[96] fitdistrplus_1.1-6 ellipsis_0.3.2 ROCR_1.0-11