User Tools

Site Tools


krackhardt_datasets

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
krackhardt_datasets [2019/12/04 08:37] – [correlation matrix out of the combined matrix (friend and advice)] hkimscilkrackhardt_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) 
- +</code> 
 + 
 +<code> 
 +> cutree(krack_friend_advice_hclust, k=2) 
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21  
 +  2  1  1  1  2  1  1  1  1  2  2  1  2  1  1  2  1  1  1  1  
 +>  
 +>  
 +</code> 
 + 
 +<code> 
 # 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, produce matrices of within- and between- # configurations, produce matrices of within- and between-
Line 1407: Line 1418:
    
 # pdf("6.3_m182_studentnet_task_social_clustered_observed_corrs.pdf") # pdf("6.3_m182_studentnet_task_social_clustered_observed_corrs.pdf")
-clustered_observed_cors <-clustConfigurations(num_vertices, krack_reports_to_advice_hclustkrack_reports_to_advice_cors)+clustered_observed_cors <-clustConfigurations(num_vertices, krack_friend_advice_hclustkrack_friend_advice_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
 +</code>
 +
 +<code>
 +> clustered_observed_cors <-clustConfigurations(num_vertices, krack_friend_advice_hclust, krack_friend_advice_cors)
 +Warning message:
 +In cor(as.vector(d[g1[i], , ]), as.vector(d[g2[j], , ]), use = "complete.obs") :
 +  표준편차가 0입니다
 +> clustered_observed_cors
 +$label
 +[1] "number of clusters:  1"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1 
 +
 +$correlation
 +[1] NA
 +
 +$label
 +[1] "number of clusters:  2"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  1  1  1  2  1  1  1  1  2  2  1  2  1  1  2  1  1  1  1 
 +
 +$correlation
 +[1] 0.4896211
 +
 +$label
 +[1] "number of clusters:  3"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  1  3  2  1  1  3  3  2  2  3  2  3  1  2  3  3  1  1 
 +
 +$correlation
 +[1] 0.5944114
 +
 +$label
 +[1] "number of clusters:  4"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  1  3  2  1  1  3  4  2  2  3  2  3  1  2  4  3  1  1 
 +
 +$correlation
 +[1] 0.6398013
 +
 +$label
 +[1] "number of clusters:  5"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  1  3  2  4  1  3  5  2  2  3  2  3  1  2  5  3  4  4 
 +
 +$correlation
 +[1] 0.6538231
 +
 +$label
 +[1] "number of clusters:  6"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  1  3  4  5  1  3  6  4  2  3  4  3  1  4  6  3  5  5 
 +
 +$correlation
 +[1] 0.6723019
 +
 +$label
 +[1] "number of clusters:  7"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  1  3  4  5  1  3  6  4  2  3  4  3  1  4  6  3  5  7 
 +
 +$correlation
 +[1] 0.7019599
 +
 +$label
 +[1] "number of clusters:  8"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  1  3  4  5  1  3  6  4  2  3  4  3  1  7  6  3  5  8 
 +
 +$correlation
 +[1] 0.727137
 +
 +$label
 +[1] "number of clusters:  9"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  1  3  4  5  1  3  6  4  2  7  4  7  1  8  6  7  5  9 
 +
 +$correlation
 +[1] 0.7743714
 +
 +$label
 +[1] "number of clusters:  10"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  4  3  5  6  4  3  7  5  2  8  5  8  4  9  7  8  6 10 
 +
 +$correlation
 +[1] 0.7919439
 +
 +$label
 +[1] "number of clusters:  11"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  4  3  5  6  4  3  7  5  2  8  5  8  4  9 10  8  6 11 
 +
 +$correlation
 +[1] 0.8093965
 +
 +$label
 +[1] "number of clusters:  12"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  4  3  5  6  7  3  8  5  2  9  5  9  7 10 11  9  6 12 
 +
 +$correlation
 +[1] 0.8445199
 +
 +$label
 +[1] "number of clusters:  13"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  4  3  5  6  7  3  8  5  2  9  5 10  7 11 12  9  6 13 
 +
 +$correlation
 +[1] 0.8700886
 +
 +$label
 +[1] "number of clusters:  14"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  4  3  5  6  7  3  8  9  2 10  5 11  7 12 13 10  6 14 
 +
 +$correlation
 +[1] 0.8844067
 +
 +$label
 +[1] "number of clusters:  15"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  4  3  5  6  7  3  8  9  2 10 11 12  7 13 14 10  6 15 
 +
 +$correlation
 +[1] 0.9115517
 +
 +$label
 +[1] "number of clusters:  16"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  4  3  5  6  7  3  8  9  2 10 11 12  7 13 14 10 15 16 
 +
 +$correlation
 +[1] 0.9403353
 +
 +$label
 +[1] "number of clusters:  17"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  4  3  5  6  7  3  8  9  2 10 11 12  7 13 14 15 16 17 
 +
 +$correlation
 +[1] 0.9502702
 +
 +$label
 +[1] "number of clusters:  18"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  4  3  5  6  7  3  8  9 10 11 12 13  7 14 15 16 17 18 
 +
 +$correlation
 +[1] 0.9633198
 +
 +$label
 +[1] "number of clusters:  19"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  4  3  5  6  7  8  9 10 11 12 13 14  7 15 16 17 18 19 
 +
 +$correlation
 +[1] 0.9762881
 +
 +$label
 +[1] "number of clusters:  20"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  4  3  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 
 +
 +$correlation
 +[1] 0.9895545
 +
 +$label
 +[1] "number of clusters:  21"
 +
 +$clusters
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
 +
 +$correlation
 +[1] 1
 +
 +$correlations
 + [1]        NA 0.4896211 0.5944114 0.6398013 0.6538231 0.6723019 0.7019599 0.7271370 0.7743714 0.7919439 0.8093965 0.8445199 0.8700886 0.8844067 0.9115517 0.9403353
 +[17] 0.9502702 0.9633198 0.9762881 0.9895545 1.0000000
 +
 +> plot(clustered_observed_cors$correlations)
 +
 +> clustered_observed_cors$correlations
 + [1]        NA 0.4896211 0.5944114 0.6398013 0.6538231 0.6723019 0.7019599 0.7271370 0.7743714 0.7919439 0.8093965 0.8445199 0.8700886 0.8844067 0.9115517 0.9403353
 +[17] 0.9502702 0.9633198 0.9762881 0.9895545 1.0000000
 +>
 +</code>
 +{{:pasted:20191204-081317.png}}
 +
 +===== decision on # of clusters  =====
 +
 +<code> 
 # 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't appear on the plot because its correlation  # solution doesn't appear on the plot because its correlation 
 # 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) 
-                                            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, krack_reports_to_advice_cors+gcor(cluster_cor_mat, krack_friend_advice_cors
- + 
 +</code> 
 + 
 +<code> 
 ##################### #####################
 # 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_clusters)+
 deductive_cluster_cor_mat deductive_cluster_cor_mat
-gcor(deductive_cluster_cor_mat, krack_reports_to_advice_cors)+gcor(deductive_cluster_cor_mat, krack_friend_advice_cors)
  
 ### END NOTE ON DEDUCTIVE CLUSTERING ### END NOTE ON DEDUCTIVE CLUSTERING
Line 1467: Line 1710:
 # networks. # networks.
  
-Task valued +Friendship valued 
-task_mean <- mean(as.matrix(krack_reports_to_matrix_row_to_col)_ +friend_mean <- mean(as.matrix(krack_friend_matrix_row_to_col)
-task_mean+friend_mean
  
-task_valued_blockmodel <- blockmodel(krack_reports_to_matrix_row_to_col, clusters) +friend_valued_blockmodel <- blockmodel(krack_friend_matrix_row_to_col, clusters) 
-task_valued_blockmodel+friend_valued_blockmodel
  
-Task binary +friend binary 
-task_density <- graph.density(krack_reports_to+friend_density <- graph.density(krack_friend
-task_density+friend_density
  
-task_binary_blockmodel <- blockmodel(as.matrix(krack_reports_to_matrix_row_to_col_bin), clusters) +friend_binary_blockmodel <- blockmodel(as.matrix(krack_friend_matrix_row_to_col_bin), clusters) 
-task_binary_blockmodel+friend_binary_blockmodel
  
  
-Social valued+advice valued
 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 binary+advice binary
 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), clusters) advice_binary_blockmodel <- blockmodel(as.matrix(krack_advice_matrix_row_to_col_bin), clusters)
 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) cluster_cor_mat_per <- permute_matrix(clusters, cluster_cor_mat)
 cluster_cor_mat_per cluster_cor_mat_per
 +</code>
  
 +<code>
 ##################### #####################
 # Questions: # Questions:
krackhardt_datasets.txt · Last modified: 2019/12/13 14:11 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki