Skip to main content
Tweeted twitter.com/#!/StackStats/status/496506223379107840
added 254 characters in body
Source Link
rdorlearn
  • 3.6k
  • 6
  • 29
  • 29

I have some prior knowledge of grouping, but this may be incorrect or is not sufficient as I need larger number of groups (i.e. subgroups). For example in the following data I have 3 groups in addition to two variables. I would like to use the group information (as prior knowledge) (here 3 groups) to create meaningful groups (here 9 groups/clusters). Is there a correct way to perform such analysis.

# Dummy data 
group <- rep(1:3, each =3000)
X <- c(rnorm(1000, 0.1, 0.04), rnorm(1000,0.2, 0.04), rnorm(1000, 0.34, 0.0402),
       rnorm(1000, 0.4, 0.04), rnorm(1000,0.5, 0.0408), rnorm(1000, 0.6, 0.0412), 
       rnorm(1000, 0.7, 0.0408), rnorm(1000,0.8, 0.041), rnorm(1000, 0.9, 0.0406)
)

Y <-  c(rnorm(1000, 0.5, 0.04), rnorm(1000,0.6, 0.04), rnorm(1000, 0.7, 0.04),
       rnorm(1000, 0.35, 0.0412), rnorm(1000,0.45, 0.04), rnorm(1000, 0.3, 0.0402), 
       rnorm(1000, 0.55, 0.0409), rnorm(1000,0.65, 0.0412), rnorm(1000, 0.65, 0.04)
)

Prior information of 3 clusters:

col = c("red", "cyan", "green")
plot(cbind(X,Y), col = col[group], pch = ".")

enter image description here

Clustering analysis assuming 9 clusters.

cl <- kmeans(cbind(X,Y), 9)

colrs <- c("red","purple", "yellow", "tan", "pink", "cyan", "blue", "green", "black")
plot(cbind(X,Y), col = colrs[cl$cluster], pch = ".")
plot(cbind(X,Y), col = colrs[group], pch = ".")

enter image description here

I have some prior knowledge of grouping, but this may be incorrect or is not sufficient as I need larger number of groups (i.e. subgroups). For example in the following data I have 3 groups in addition to two variables. I would like to use the group information (as prior knowledge) (here 3 groups) to create meaningful groups (here 9 groups/clusters). Is there a correct way to perform such analysis.

# Dummy data 
group <- rep(1:3, each =3000)
X <- c(rnorm(1000, 0.1, 0.04), rnorm(1000,0.2, 0.04), rnorm(1000, 0.3, 0.04),
       rnorm(1000, 0.4, 0.04), rnorm(1000,0.5, 0.04), rnorm(1000, 0.6, 0.04), 
       rnorm(1000, 0.7, 0.04), rnorm(1000,0.8, 0.04), rnorm(1000, 0.9, 0.04)
)

Y <-  c(rnorm(1000, 0.5, 0.04), rnorm(1000,0.6, 0.04), rnorm(1000, 0.7, 0.04),
       rnorm(1000, 0.35, 0.04), rnorm(1000,0.45, 0.04), rnorm(1000, 0.3, 0.04), 
       rnorm(1000, 0.55, 0.04), rnorm(1000,0.65, 0.04), rnorm(1000, 0.65, 0.04)
)

plot(X,Y, pch = ".")
cl <- kmeans(cbind(X,Y), 9)

colrs <- c("red","purple", "yellow", "tan", "pink", "cyan", "blue", "green", "black")
plot(cbind(X,Y), col = colrs[cl$cluster], pch = ".")
plot(cbind(X,Y), col = colrs[group], pch = ".")

I have some prior knowledge of grouping, but this may be incorrect or is not sufficient as I need larger number of groups (i.e. subgroups). For example in the following data I have 3 groups in addition to two variables. I would like to use the group information (as prior knowledge) (here 3 groups) to create meaningful groups (here 9 groups/clusters). Is there a correct way to perform such analysis.

# Dummy data 
group <- rep(1:3, each =3000)
X <- c(rnorm(1000, 0.1, 0.04), rnorm(1000,0.2, 0.04), rnorm(1000, 0.4, 0.02),
       rnorm(1000, 0.4, 0.04), rnorm(1000,0.5, 0.08), rnorm(1000, 0.6, 0.12), 
       rnorm(1000, 0.7, 0.08), rnorm(1000,0.8, 0.1), rnorm(1000, 0.9, 0.06)
)

Y <-  c(rnorm(1000, 0.5, 0.04), rnorm(1000,0.6, 0.04), rnorm(1000, 0.7, 0.04),
       rnorm(1000, 0.35, 0.12), rnorm(1000,0.45, 0.04), rnorm(1000, 0.3, 0.02), 
       rnorm(1000, 0.55, 0.09), rnorm(1000,0.65, 0.12), rnorm(1000, 0.65, 0.04)
)

Prior information of 3 clusters:

col = c("red", "cyan", "green")
plot(cbind(X,Y), col = col[group], pch = ".")

enter image description here

Clustering analysis assuming 9 clusters.

cl <- kmeans(cbind(X,Y), 9)

colrs <- c("red","purple", "yellow", "tan", "pink", "cyan", "blue", "green", "black")
plot(cbind(X,Y), col = colrs[cl$cluster], pch = ".")

enter image description here

Source Link
rdorlearn
  • 3.6k
  • 6
  • 29
  • 29

how to complement the results of cluster analysis with known groups

I have some prior knowledge of grouping, but this may be incorrect or is not sufficient as I need larger number of groups (i.e. subgroups). For example in the following data I have 3 groups in addition to two variables. I would like to use the group information (as prior knowledge) (here 3 groups) to create meaningful groups (here 9 groups/clusters). Is there a correct way to perform such analysis.

# Dummy data 
group <- rep(1:3, each =3000)
X <- c(rnorm(1000, 0.1, 0.04), rnorm(1000,0.2, 0.04), rnorm(1000, 0.3, 0.04),
       rnorm(1000, 0.4, 0.04), rnorm(1000,0.5, 0.04), rnorm(1000, 0.6, 0.04), 
       rnorm(1000, 0.7, 0.04), rnorm(1000,0.8, 0.04), rnorm(1000, 0.9, 0.04)
)

Y <-  c(rnorm(1000, 0.5, 0.04), rnorm(1000,0.6, 0.04), rnorm(1000, 0.7, 0.04),
       rnorm(1000, 0.35, 0.04), rnorm(1000,0.45, 0.04), rnorm(1000, 0.3, 0.04), 
       rnorm(1000, 0.55, 0.04), rnorm(1000,0.65, 0.04), rnorm(1000, 0.65, 0.04)
)

plot(X,Y, pch = ".")
cl <- kmeans(cbind(X,Y), 9)

colrs <- c("red","purple", "yellow", "tan", "pink", "cyan", "blue", "green", "black")
plot(cbind(X,Y), col = colrs[cl$cluster], pch = ".")
plot(cbind(X,Y), col = colrs[group], pch = ".")