Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correlation matrix is not positive definite #129

Closed
stonelight816 opened this issue Apr 10, 2024 · 3 comments
Closed

Correlation matrix is not positive definite #129

stonelight816 opened this issue Apr 10, 2024 · 3 comments

Comments

@stonelight816
Copy link

Hi Sacha,

I encounter a problem when I used bootnet function. For my data, I got 37 nodes and 43 samples. Although the number of samples is not large, it still exceeds the number of nodes.

The code I'm using is as follows:
mynetwork <- estimateNetwork(raw_data, default = "EBICglasso", tuning = 0.5,corMethod="spearman")
b1<-bootnet(mynetwork,nBoots=1000,type="nonparametric",nCores=1,statistics=c("strength","betweenness", "closeness","edge"))

I got the following error message:
Note: bootnet will store only the following statistics: strength, betweenness, closeness, edge
Bootstrapping...
| | 0%Error in bootnet_correlate(data = data, corMethod = corMethod, corArgs = corArgs, :
Correlation matrix is not positive definite.
Error in bootnet_correlate(data = data, corMethod = corMethod, corArgs = corArgs, :
Correlation matrix is not positive definite.
Error in bootnet_correlate(data = data, corMethod = corMethod, corArgs = corArgs, :
Correlation matrix is not positive definite.
Error in bootnet_correlate(data = data, corMethod = corMethod, corArgs = corArgs, :
Correlation matrix is not positive definite.
Error in bootnet_correlate(data = data, corMethod = corMethod, corArgs = corArgs, :
Correlation matrix is not positive definite.
Error in bootnet_correlate(data = data, corMethod = corMethod, corArgs = corArgs, :
Correlation matrix is not positive definite.
Error in bootnet_correlate(data = data, corMethod = corMethod, corArgs = corArgs, :
Correlation matrix is not positive definite.
Error in bootnet_correlate(data = data, corMethod = corMethod, corArgs = corArgs, :
Correlation matrix is not positive definite.
Error in bootnet_correlate(data = data, corMethod = corMethod, corArgs = corArgs, :
Correlation matrix is not positive definite.
Error in bootnet_correlate(data = data, corMethod = corMethod, corArgs = corArgs, :
Correlation matrix is not positive definite.
Error in bootnet_correlate(data = data, corMethod = corMethod, corArgs = corArgs, :
Correlation matrix is not positive definite.
Error in bootnet(mynetwork, nBoots = 1000, type = "nonparametric", nCores = 1, :
Maximum number of errors in bootstraps reached

Thanks for the help!

@SachaEpskamp
Copy link
Owner

While the original sample has 43 cases, the bootstrapped samples will have fewer than 43 cases leading to potentially non-positive definite correlation matrices used as input. While technically EBICglasso can still be used (you would have to overwrite this error both in qgraph and bootnet) I really do not advice you to do so. See here for more info:

#126

@stonelight816
Copy link
Author

Hi Sacha,

thanks for your response. In this example:#126, the number of datapoints was fewer than number of nodes. In my project, number of datapoints (43) beyonds the number of nodes (37). Why would this error still happened?

@SachaEpskamp
Copy link
Owner

Even though you have more datapoints than nodes in the original data, you don't have this in the bootstrapped data as you resample cases with replacement, leading to less unique cases. See for example:


# Original data with N = 11; P = 10:
data <- matrix(rnorm(11*10),11,10)
all(eigen(cor(data))$values > 0)
# Is positive definite

# Bootstrap sample:
set.seed(42)
bootdata <- data[sample(1:nrow(data),nrow(data),TRUE),]
all(eigen(cor(bootdata))$values > 0)
# No longer positive definite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants