Entering edit mode
6.8 years ago
zizigolu
★
4.3k
Hi,
I have two matrices of normalized read counts for control and treatment in a time series day1 to day26. I want to calculate distance matrix by Dynamic Time Wrapping but seems too complicated. I did so; who can help for more clarification please? Thanks a lot
head(control[,1:4])
MAST2 WWC2 PHYHIPL R3HDM2
Control_D1 6.591024 5.695156 3.388652 5.756384
Control_D10 8.043454 5.365221 6.859768 6.936970
Control_D11 7.731590 4.868267 6.919972 6.931073
Control_D12 8.129948 5.105528 6.627016 7.090268
Control_D13 7.690863 4.729501 6.824746 6.904610
Control_D14 8.101723 5.334501 6.868990 7.115883
head(lead[,1:4])
MAST2 WWC2 PHYHIPL R3HDM2
Lead30_D1 6.418423 5.610699 3.734425 5.778046
Lead30_D10 7.918360 4.295191 6.559294 6.780952
Lead30_D11 7.807142 4.294722 6.599187 6.716040
Lead30_D12 7.856720 4.432136 6.572337 6.848483
Lead30_D13 7.827311 4.204738 6.607107 6.784094
Lead30_D14 7.848760 4.458451 6.581216 6.943003
dim(control)
[1] 26 2603
dim(lead)
[1] 26 2603
library(dtw)
Control=dist(control,method="DTW");
Lead=dist(lead,method="DTW");
Question is unclear. What package are we using,
method="DTW"
? Also, maybe irrelevant, the row ordering is1, 10, 11,
not1,2,3,
.Thank you,
I want to calculate distance matrix of my time series, I can't figure out how do that
You can't assign elements to a matrix that you haven't pre-allocated. You can't index with more dimensions than your array has, e.g. if it's a matrix, you can only have two indices. I think part of the problem is that you don't know how to program in R.
Also, read the dtw() doc to figure out what the arguments to the function should be.
And avoid duplicating your question, either keep the discussion in the previous thread or in the new question but not both.
The
dist
function doesn't have adtw
method! If you are trying to use the "Distance matrix computation" function from thestats
package see here: https://stat.ethz.ch/R-manual/R-devel/library/stats/html/dist.htmlYou probabely need something like this:
The OP is trying to compute a dynamic time warping distance as offered in the dtw package. An "almost" answer can be found in my comments in the other post.