Closed RRRannwwwmdudsss closed 3 months ago
Hi! Can you try with nCores = 1
? Note that you need to write the function as if it is a new R session when using multi-core, so include packages and definitions (like k
and numCovar
). Do not include set.seed
.
Hi! Can you try with
nCores = 1
? Note that you need to write the function as if it is a new R session when using multi-core, so include packages and definitions (likek
andnumCovar
). Do not includeset.seed
.
Hey, Sacha. I have a question that why it is necessary to exclude set.seed
? I'm curious about this.
set.seed
could lead to unexpected results when bootstrapping. E.g., I think when nCores = 1
at least it would lead also to the bootstrap samples to be identical. Not sure about multicore.
set.seed
could lead to unexpected results when bootstrapping. E.g., I think whennCores = 1
at least it would lead also to the bootstrap samples to be identical. Not sure about multicore.
Thanks for your reply. I just curious the mechanism of the conflict between set.seed
and nCores >1
.
Thanks for your reply. I tried with nCores = 1 not include set.seed. The multi-core has been resolved. However, biased case-dropping and plotting issue is still the same as above.
CLPN.net <- function(data) {
library(glmnet)
numCovar <- 4
k <- 9 adjMatCovCLPN <- matrix(0, k + numCovar, k + numCovar) for (i in 1:k) { set.seed(1) # commented out so that it doesn't give the same answer every time when bootstrapping lassoreg <- cv.glmnet(x = as.matrix(data[, c(1:k, (k 2 + 1):(k 2 + numCovar))]), y = data[, (k + i)], nfolds = 10, family = "gaussian", alpha = 1, standardize = TRUE, parallel = TRUE) lambda <- lassoreg$lambda.min adjMatCovCLPN[1:(k + numCovar), i] <- coef(lassoreg, s = lambda, exact = FALSE)[2:(k + numCovar + 1)] } adjMatCLPN <- adjMatCovCLPN[1:k, 1:k] return(adjMatCLPN) }
net.t1.t2 <- estimateNetwork(net.t1.t2.df.cov.emerge, fun=CLPN.net, labels=labels, directed=T)
caseBoot.t1.t2 <- bootnet(net.t1.t2, nCores = 8, nBoots = 1000, type = "case", statistics = c("outStrength", "inStrength", "edge"), directed = TRUE)
print(corStability(caseBoot.t1.t2)) plot(swan.caseBoot.t1.t2, statistics = c("outStrength", "inStrength"))
And, plotting centrality stability showing no 95% CI:
Correction to: plot(caseBoot.t1.t2, statistics = c("outStrength", "inStrength"))
I'm afraid that I cannot reproduce the problem. Is it possible for you to make a reproducible example or to share the data perhaps?
Best, Sacha
There's an example dataset that resulted in similar plots. Could you try to replicate my issue using that data?
Thanks a lot! Best, Ran
Data1<- read_excel("example2_Data1_t1.xlsx")#time1 Data2<- read_excel("example2_Data2_t2.xlsx")#time2 df <- as.matrix(cbind(Data1,Data2)) nt1=paste0("T1",colnames(Data1)) nt2=paste0("T2",colnames(Data2)) colnames(df)=c(nt1,nt2) labels=paste0(1:25)
CLPN.net <- function(data) {
library(glmnet)
numCovar <- 3
k <- 25 adjMatCovCLPN <- matrix(0, k + numCovar, k + numCovar) for (i in 1:k) { set.seed(1) # commented out so that it doesn't give the same answer every time when bootstrapping lassoreg <- cv.glmnet(x = as.matrix(data[, c(1:k, (k 2 + 1):(k 2 + numCovar))]), y = data[, (k + i)], nfolds = 10, family = "gaussian", alpha = 1, standardize = TRUE, parallel = TRUE) lambda <- lassoreg$lambda.min adjMatCovCLPN[1:(k + numCovar), i] <- coef(lassoreg, s = lambda, exact = FALSE)[2:(k + numCovar + 1)] } adjMatCLPN <- adjMatCovCLPN[1:k, 1:k] diag(adjMatCLPN) <- 0 return(adjMatCLPN) }
Network_CL <- estimateNetwork(df, fun = CLPN.net, labels = labels, directed = T)
Boot_CL_1 <- bootnet(Network_CL, directed = T, nCores = 4, nBoots = 1000, type = "nonparametric", statistics = c("edge", "OutStrength", "InStrength")) Boot_CL_2 <- bootnet(Network_CL, nCores = 4, nBoots = 1000, type = "case", statistics = c("outStrength", "inStrength"), directed = T)
plot(Boot_CL_1, labels = FALSE, order = "sample") print(corStability(Boot_CL_2)) plot(Boot_CL_2, statistics = c("outStrength", "inStrength")) example2_Data1_t1.xlsx example2_Data2_t2.xlsx
I think I've found a solution to the problem: avoid including set.seed in the function.
CLPN.net <- function(data) { numCovar <- 3 k <- 25 adjMatCovCLPN <- matrix(0, k + numCovar, k + numCovar) for (i in 1:k) { lassoreg <- cv.glmnet(x = as.matrix(data[, c(1:k, (k 2 + 1):(k 2 + numCovar))]), y = data[, (k + i)], nfolds = 10, family = "gaussian", alpha = 1, standardize = TRUE, parallel = TRUE) lambda <- lassoreg$lambda.min adjMatCovCLPN[1:(k + numCovar), i] <- coef(lassoreg, s = lambda, exact = FALSE)[2:(k + numCovar + 1)] } adjMatCLPN <- adjMatCovCLPN[1:k, 1:k] diag(adjMatCLPN) <- 0 return(adjMatCLPN) }
Thank you for your kind help, Dr. Epskamp. With best regards and sincere wishes.
Hi, Sacha,
I used the following code for estimating CLPN network using bootnet(215 samples, 9 nodes, 4 covariates):
but found biased case-dropping (only one sampling in drop% 71.6, 38.1, 30.2……):
another question is about plotting centrality stability showing no 95% CI:
plot(caseBoot.t1.t2, statistics = c("outStrength", "inStrength"))
Expect your reply. Thanks a lot!