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
Last revisionBoth sides next revision
krackhardt_datasets [2019/12/04 08:47] – [Using cutree] hkimscilkrackhardt_datasets [2019/12/13 14:07] hkimscil
Line 65: Line 65:
  
 <code> <code>
-krack_friend <- delete.edges(krack_full, E(krack_full)[E(krack_full)$friendship_tie==0])+krack_friend <- delete_edges(krack_full, E(krack_full)[E(krack_full)$friendship_tie==0])
 summary(krack_friend) summary(krack_friend)
 krack_friend[] krack_friend[]
  
-krack_advice <- delete.edges(krack_full, E(krack_full)[E(krack_full)$advice_tie==0])+krack_advice <- delete_edges(krack_full, E(krack_full)[E(krack_full)$advice_tie==0])
 summary(krack_advice) summary(krack_advice)
 krack_advice[] krack_advice[]
    
-krack_reports_to <- delete.edges(krack_full, E(krack_full)[E(krack_full)$reports_to_tie==0])+krack_reports_to <- delete_edges(krack_full, E(krack_full)[E(krack_full)$reports_to_tie==0])
 summary(krack_reports_to) summary(krack_reports_to)
 krack_reports_to[] krack_reports_to[]
Line 213: Line 213:
  
 <code> <code>
-# Next, we'll use the same procedure to add social-interaction+# Next, we'll use the same procedure to add advice
 # information. # information.
 krack_advice_matrix_row_to_col <- get.adjacency(krack_advice, attr='advice_tie') krack_advice_matrix_row_to_col <- get.adjacency(krack_advice, attr='advice_tie')
Line 226: Line 226:
 krack_advice_matrix <- rbind(krack_advice_matrix_row_to_col, krack_advice_matrix_col_to_row) krack_advice_matrix <- rbind(krack_advice_matrix_row_to_col, krack_advice_matrix_col_to_row)
 krack_advice_matrix krack_advice_matrix
- +</code> 
 + 
 + 
 +<code> 
 +krack_friend_matrix_row_to_col <- get.adjacency(krack_friend, attr='friendship_tie'
 +krack_friend_matrix_row_to_col 
 + 
 +# To operate on a binary graph, simply leave off the "attr"  
 +# parameter: 
 +krack_friend_matrix_row_to_col_bin <- get.adjacency(krack_friend) 
 +krack_friend_matrix_row_to_col_bin 
 + 
 +# For this lab, we'll use the valued graph. The next step is to  
 +# concatenate it with its transpose in order to capture both  
 +# incoming and outgoing task interactions. 
 +krack_friend_matrix_col_to_row <- t(as.matrix(krack_friend_matrix_row_to_col)) 
 +krack_friend_matrix_col_to_row 
 + 
 +krack_friend_matrix <- rbind(krack_friend_matrix_row_to_col, krack_friend_matrix_col_to_row) 
 +krack_friend_matrix 
 +</code> 
 + 
 + 
 +<code>  
 +# ra (ar)
 krack_reports_to_advice_matrix <- rbind(krack_reports_to_matrix, krack_advice_matrix) krack_reports_to_advice_matrix <- rbind(krack_reports_to_matrix, krack_advice_matrix)
 krack_reports_to_advice_matrix krack_reports_to_advice_matrix
 +
 +# fa
 +krack_friend_advice_matrix <- rbind(krack_friend_matrix, krack_advice_matrix)
 +krack_friend_advice_matrix
 +
 +# far
 +krack_friend_advice_reports_to_matrix <- rbind(krack_friend_advice_matrix, krack_reports_to_matrix)
 +krack_friend_advice_reports_to_matrix
 </code> </code>
 +
  
 <code> <code>
Line 238: Line 271:
 krack_reports_to_advice_cors <- cor(as.matrix(krack_reports_to_advice_matrix)) krack_reports_to_advice_cors <- cor(as.matrix(krack_reports_to_advice_matrix))
 krack_reports_to_advice_cors krack_reports_to_advice_cors
 +
 +krack_friend_advice_cors <- cor(as.matrix(krack_friend_advice_matrix))
 +krack_friend_advice_cors
 +
 +krack_friend_advice_reports_to_cors <- cor(as.matrix(krack_friend_advice_reports_to_matrix))
 +krack_friend_advice_reports_to_cors
 +
 +
 </code> </code>
  
Line 246: Line 287:
 # or equal to 0; thus, highly dissimilar (i.e., negatively  # or equal to 0; thus, highly dissimilar (i.e., negatively 
 # correlated) actors have higher values. # correlated) actors have higher values.
-dissimilarity <- 1 - krack_reports_to_advice_cors +dissimilarity_ra <- 1 - krack_reports_to_advice_cors 
-krack_reports_to_dist <- as.dist(dissimilarity+krack_reports_to_advice_dist <- as.dist(dissimilarity_ra
-krack_reports_to_dist+krack_reports_to_advice_dist
    
 +dissimilarity_fa <- 1 - krack_friend_advice_cors
 +krack_friend_advice_dist <- as.dist(dissimilarity_fa)
 +krack_friend_advice_dist
 +
 +dissimilarity_rf <- 1 - krack_reports_to_friend_cors
 +krack_reports_to_friend_dist <- as.dist(dissimilarity_rf)
 +krack_reports_to_friend_dist
 +
 +dissimilarity_far <- 1 - krack_friend_advice_reports_to_cors
 +krack_friend_advice_reports_to_dist <- as.dist(dissimilarity_far)
 +krack_friend_advice_reports_to_dist
 +
 +
 +
 # Note that it is also possible to use dist() directly on the  # Note that it is also possible to use dist() directly on the 
 # matrix. However, since cor() looks at associations between  # matrix. However, since cor() looks at associations between 
Line 1654: Line 1709:
 </code> </code>
 {{:pasted:20191204-081317.png}} {{:pasted:20191204-081317.png}}
 +
 +===== decision on # of clusters  =====
  
 <code>  <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 1680: Line 1739:
 ##################### #####################
      
- 
- 
 ### NOTE ON DEDUCTIVE CLUSTERING ### NOTE ON DEDUCTIVE CLUSTERING
  
Line 1698: Line 1755:
 # 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 1710: Line 1765:
 # 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 1732: Line 1787:
 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 1738: Line 1793:
 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 1744: Line 1801:
 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