krackhardt_datasets
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
krackhardt_datasets [2019/12/04 08:37] – [correlation matrix out of the combined matrix (friend and advice)] hkimscil | krackhardt_datasets [2019/12/04 09:01] – [Using cutree] hkimscil | ||
---|---|---|---|
Line 1374: | Line 1374: | ||
# different numbers of clusters and assign vertices to clusters | # different numbers of clusters and assign vertices to clusters | ||
# as appropriate. For example: | # as appropriate. For example: | ||
- | cutree(krack_reports_to_advice_hclust, k=2) | + | cutree(krack_friend_advice_hclust, k=2) |
- | + | </ | |
+ | |||
+ | < | ||
+ | > cutree(krack_friend_advice_hclust, | ||
+ | | ||
+ | | ||
+ | > | ||
+ | > | ||
+ | </ | ||
+ | |||
+ | < | ||
# Now we'll try to figure out the number of clusters that best | # Now we'll try to figure out the number of clusters that best | ||
# describes the underlying data. To do this, we'll loop through | # describes the underlying data. To do this, we'll loop through | ||
Line 1399: | Line 1409: | ||
# set a variable for our number of vertices. | # set a variable for our number of vertices. | ||
clustered_observed_cors = vector() | clustered_observed_cors = vector() | ||
- | num_vertices = length(V(krack_reports_to)) | + | num_vertices = length(V(krack_advice)) |
- | + | ||
# Next, we loop through the different possible cluster | # Next, we loop through the different possible cluster | ||
# configurations, | # configurations, | ||
Line 1407: | Line 1418: | ||
# pdf(" | # pdf(" | ||
- | clustered_observed_cors < | + | clustered_observed_cors < |
clustered_observed_cors | clustered_observed_cors | ||
plot(clustered_observed_cors$correlations) | plot(clustered_observed_cors$correlations) | ||
# dev.off() | # dev.off() | ||
- | + | ||
clustered_observed_cors$correlations | clustered_observed_cors$correlations | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | > clustered_observed_cors < | ||
+ | Warning message: | ||
+ | In cor(as.vector(d[g1[i], | ||
+ | 표준편차가 0입니다 | ||
+ | > clustered_observed_cors | ||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] NA | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.4896211 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.5944114 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.6398013 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.6538231 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.6723019 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.7019599 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.727137 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.7743714 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.7919439 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.8093965 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.8445199 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.8700886 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.8844067 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.9115517 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.9403353 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.9502702 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.9633198 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.9762881 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 0.9895545 | ||
+ | |||
+ | $label | ||
+ | [1] " | ||
+ | |||
+ | $clusters | ||
+ | | ||
+ | | ||
+ | |||
+ | $correlation | ||
+ | [1] 1 | ||
+ | |||
+ | $correlations | ||
+ | | ||
+ | [17] 0.9502702 0.9633198 0.9762881 0.9895545 1.0000000 | ||
+ | |||
+ | > plot(clustered_observed_cors$correlations) | ||
+ | > | ||
+ | > clustered_observed_cors$correlations | ||
+ | | ||
+ | [17] 0.9502702 0.9633198 0.9762881 0.9895545 1.0000000 | ||
+ | > | ||
+ | </ | ||
+ | {{: | ||
+ | |||
+ | ===== decision on # of clusters | ||
+ | |||
+ | < | ||
# From a visual inspection of the correlation matrix, we can | # From a visual inspection of the correlation matrix, we can | ||
# decide on the proper number of clusters in this network. | # decide on the proper number of clusters in this network. | ||
- | # For this network, we'll use 4. (Note that the 1-cluster | + | # For this network, we'll use 6. (Note that the 1-cluster |
# solution doesn' | # solution doesn' | ||
# with the observed correlation matrix is undefined.) | # with the observed correlation matrix is undefined.) | ||
num_clusters = 4 | num_clusters = 4 | ||
- | clusters <- cutree(krack_reports_to_advice_hclust, k = num_clusters) | + | clusters <- cutree(krack_friend_advice_hclust, k = num_clusters) |
clusters | clusters | ||
- | + | ||
- | cluster_cor_mat <- clusterCorr(krack_reports_to_advice_cors, | + | cluster_cor_mat <- clusterCorr(krack_friend_advice_cors, clusters) |
- | | + | round(cluster_cor_mat,2) |
- | cluster_cor_mat | + | |
- | + | ||
# Let's look at the correlation between this cluster configuration | # Let's look at the correlation between this cluster configuration | ||
# and the observed correlation matrix. This should match the | # and the observed correlation matrix. This should match the | ||
# corresponding value from clustered_observed_cors above. | # corresponding value from clustered_observed_cors above. | ||
- | gcor(cluster_cor_mat, | + | gcor(cluster_cor_mat, |
- | + | ||
+ | </ | ||
+ | |||
+ | < | ||
##################### | ##################### | ||
# Questions: | # Questions: | ||
Line 1437: | Line 1684: | ||
##################### | ##################### | ||
| | ||
- | |||
- | |||
### NOTE ON DEDUCTIVE CLUSTERING | ### NOTE ON DEDUCTIVE CLUSTERING | ||
Line 1455: | Line 1700: | ||
# You could then examine the fitness of this cluster configuration | # You could then examine the fitness of this cluster configuration | ||
# as follows: | # as follows: | ||
- | deductive_cluster_cor_mat <- generate_cluster_cor_mat( | + | deductive_cluster_cor_mat <- generate_cluster_cor_mat(krack_friend_advice_cors, deductive_clusters) |
- | krack_reports_to_advice_cors, | + | |
- | | + | |
deductive_cluster_cor_mat | deductive_cluster_cor_mat | ||
- | gcor(deductive_cluster_cor_mat, | + | gcor(deductive_cluster_cor_mat, |
### END NOTE ON DEDUCTIVE CLUSTERING | ### END NOTE ON DEDUCTIVE CLUSTERING | ||
Line 1467: | Line 1710: | ||
# networks. | # networks. | ||
- | # Task valued | + | # Friendship |
- | task_mean | + | friend_mean |
- | task_mean | + | friend_mean |
- | task_valued_blockmodel | + | friend_valued_blockmodel |
- | task_valued_blockmodel | + | friend_valued_blockmodel |
- | # Task binary | + | # friend |
- | task_density | + | friend_density |
- | task_density | + | friend_density |
- | task_binary_blockmodel | + | friend_binary_blockmodel |
- | task_binary_blockmodel | + | friend_binary_blockmodel |
- | # Social | + | # advice |
advice_mean <- mean(as.matrix(krack_advice_matrix_row_to_col)) | advice_mean <- mean(as.matrix(krack_advice_matrix_row_to_col)) | ||
advice_mean | advice_mean | ||
Line 1489: | Line 1732: | ||
advice_valued_blockmodel | advice_valued_blockmodel | ||
- | # Social | + | # advice |
advice_density <- graph.density(krack_advice) | advice_density <- graph.density(krack_advice) | ||
advice_density | advice_density | ||
Line 1495: | Line 1738: | ||
advice_binary_blockmodel <- blockmodel(as.matrix(krack_advice_matrix_row_to_col_bin), | advice_binary_blockmodel <- blockmodel(as.matrix(krack_advice_matrix_row_to_col_bin), | ||
advice_binary_blockmodel | advice_binary_blockmodel | ||
+ | |||
+ | |||
# We can also permute the network to examine the within- and | # We can also permute the network to examine the within- and | ||
Line 1501: | Line 1746: | ||
cluster_cor_mat_per <- permute_matrix(clusters, | cluster_cor_mat_per <- permute_matrix(clusters, | ||
cluster_cor_mat_per | cluster_cor_mat_per | ||
+ | </ | ||
+ | < | ||
##################### | ##################### | ||
# Questions: | # Questions: |
krackhardt_datasets.txt · Last modified: 2019/12/13 14:11 by hkimscil