Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Compare cluster composition over consecutive time points in R

$
0
0

Currently I am attempting to analyse neighbourhood relationships of objects, moving over time in a 2D coordinate system. Precisely I would like to cluster the objects dependent on their proximity to each other. Then I would like to asses if there is the occurence of stable cluster over time.

So far I have managed to compute distance matrixes for every time point, containing euclidian distances between all objects. Yet, I am struggeling to find an R package, which allows clustering of objects with multiple variables (one variable = one euclidian distance to another object) over time. I can perform hiercial clustering of every single time point, yet do not know how to compare the compisitions of the clusters between the time points.

Cluster, Timepoint = 1Cluster, Timepoint = 2

This is the code I use to compute the dist matrix and hclust:

head(migrationfile %>% select(X, Y, Track, Time))
              X        Y Track Time
206330 272.0473 1211.049     2    0
206331 343.7157 1252.734     3    0
206332 294.7179 1267.360     4    0
206333 235.4818 1271.748     5    0
206334 402.9518 1279.793     7    0
206335 372.9681 1291.493     8    0

subset_migrationfile <- subset(migrationfile, migrationfile$Time == TimePoint)
timepoint_migrationfile <- subset_migrationfile %>% select(X, Y)
timepoint_migrationfile <- as.matrix(timepoint_migrationfile)
rownames(timepoint_migrationfile) <- subset_migrationfile$Track
dist_matrix <- dist(timepoint_migrationfile, method = "euclidean")

str(dist_matrix)
 'dist' num [1:1128] 141 203 207 279 323 ...
 - attr(*, "Size")= int 48
 - attr(*, "Labels")= chr [1:48] "20""17""2""78" ...
 - attr(*, "Diag")= logi FALSE
 - attr(*, "Upper")= logi FALSE
 - attr(*, "method")= chr "euclidean"
 - attr(*, "call")= language dist(x = timepoint_migrationfile, method = "euclidean")

hlust_dist_matrix <- hclust(dist_matrix)
clusterheight <- 200

plot(hlust_dist_matrix, hang = -1)
cutree(hlust_dist_matrix, h = clusterheight)
rect.hclust(hlust_dist_matrix, h = clusterheight, border="red")

I'd appreciate any input on how to analyse/ compare the clusters overtime!


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>