Removing nodes with non-finite edge weights in plots when using qgraph package in R

StackOverflow https://stackoverflow.com/questions/21167996

  •  28-09-2022
  •  | 
  •  

Domanda

I want to see relationships in my data on a network and have used the qgraph package to do so, my data, combined.data, is used. The correlation of my data which I passed as an input has a lot of NA values. The command I used to get the network plot is

   qgraph(cor(combined.data, method="spearman"),layout="spring", groups=gr, labels=nm, 
   label.scale=FALSE, label.cex=1) 
   # I chose spearman because the data variables are on ordinal scale

gr is list of the groups, nm is a vector containing the tags/labels of the nodes. The command runs well but comes with a warning

  Warning message:
  In qgraph(cor(combined.data, method = "spearman"), layout = "spring",  :
  Non-finite weights are omitted

The network has a lot of empty edges (non-finite weights) and I want to remove the nodes with the non-finite weights. I have tried to set the minimum and maximum arguments but it still comes up with those redundant nodes. Any suggestion on how to achieve this will be appreciated.

È stato utile?

Soluzione

Probably you have missing data leading to NA in the correlation matrix? I always use cor(combined.data, method="spearman", use = "pairwise.complete.obs") which gives no NA correlations.

Alternatively, easiest is to change the input:

foo <- cor(combined.data, method="spearman")
foo[!is.finite(foo)] <- 0
qgraph(foo)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top