strength returns NAs, when used in for loop.

Hello!
for some reason, strength(g) returns NAs when is used in permutation test. In each iteration an induced_subgraph is produced. then degree and strength for all nodes are calculated. The script worked well before but not anymore. I dont know why and If you have any way you can help or guide me to resolve this it would be much appreciated!

The script:

#Iterating
for (i in c(1:iterations)){

#Sub-network:
# 1.1 sample the feature table n from each group.
features.subset.2 <- features %>% 
  group_by(core) %>% #Group by core \ no core
  sample_n(n, replace = F) #Sample eachgroup n times with no replacment

# 1.2 use the names of the genomes (nodes) to sample the original graph object to create an induced sub-graph.
#sub.g1 <- induced_subgraph(g1, which(V(g1)$name %in% features.subset.2$sample)) %>%
 # set_vertex_attr("Label", value = ifelse(features.subset.2$core == 1,"Core","NonCore")) #Set core\noncore attributes
sub.g1 <- igraph::induced_subgraph(g1, which(V(g1)$name %in% features.subset.2$sample)) %>%
  set_vertex_attr("Label", value = ifelse(features.subset.2$core == 1,"Core","NonCore")) #Set core\noncore attributes

#Even if I resample the matrix it dosnot work.
#adj_matrix.sub = adj_matrix[features.subset.2$sample,features.subset.2$sample]
#sub.g1 <- graph.adjacency(adj_matrix.sub, weighted  = T, mode = "directed")

# 1.3 get the directed features of all the nodes:
Indegree <- degree(sub.g1, mode= "in")
Outdegree <- degree(sub.g1, mode = "out")

Instrength <- strength(sub.g1, mode = "in")
Outstrength <- strength(sub.g1, mode = "out")

image

Sorry, Iā€™m unable to replicate the problem. Doing something like the followings works exactly as expected:

library(igraph)
G <- graph.famous('Zachary')
E(G)$weight = 0.5
print(strength(G, mode='out'))
G1 <- induced_subgraph(G, vids=c(1:10) )
print(strength(G1, mode='out'))

Could you perhaps try to make a minimal reproducible example, so that we can replicate the problem and perhaps suggest a solution?

Hey I appreciate the help!
I was able to resolve the problem. For some reason (I guess a mistake) when I read the adjacency matrix to a graph object I deleted the diag = F. And since my diagonal is contacting onlt NA, it cant sum the woghts.
Thanks!

1 Like