GithubHelp home page GithubHelp logo

Comments (6)

SachaEpskamp avatar SachaEpskamp commented on August 18, 2024 1

Right, I see. Thanks! This may not be trivial for now, I need to open up the function and add that the edge colors are also retained properly. Will put it on the todo list!

from qgraph.

SachaEpskamp avatar SachaEpskamp commented on August 18, 2024 1

This is now fixed in the devel version (sorry for the delay).

from qgraph.

heinonmatti avatar heinonmatti commented on August 18, 2024

Here's the covariance matrix:

covSacha.zip

and here's what I did with mgm:

bctdf_pa_combinedAgreementBcts <- bctdf_pa_combinedAgreementBcts %>% na.omit()
mgm_pa_variable_types <- c("g", "g", rep("c", 7))
mgm_pa_variable_levels <- c("1", "1", rep("2", 7))

mgm_obj <- mgm::mgm(data = bctdf_pa_combinedAgreementBcts,
  type = mgm_pa_variable_types,
  level = mgm_pa_variable_levels,
  lambdaSel = "CV",
  lambdaFolds = 10,
  pbar = FALSE, 
  binarySign = TRUE)

pred_obj <- predict(object = mgm_obj,
                         data = bctdf_pa_combinedAgreementBcts)

pred_obj$errors

# Take R2 from gaussian, CC from categorical variables 
pie_errors <- c(pred_obj$errors[1, 3],
                pred_obj$errors[2, 3],
                pred_obj$errors[3:nrow(pred_obj$errors), 4])

# PLOT NETWORK 

node_colors <- c(viridis::viridis(4, begin = 0.3, end = 0.8)[1], 
                 viridis::viridis(4, begin = 0.3, end = 0.8)[2],
                 rep(viridis::viridis(4, begin = 0.3, end = 0.8)[3], 7)) 

BCT_mgm <- qgraph::qgraph(mgm_obj$pairwise$wadj, 
            layout = "spring",
            repulsion = 1, # To nudge the network from originally bad visual state
            title = "agreement-measured BCTs and PA",
            edge.color = ifelse(mgm_obj$pairwise$edgecolor == "darkgreen", "blue", mgm_obj$pairwise$edgecolor),
            pie = pie_errors,
            pieColor = viridis::viridis(4, begin = 0.3, end = 0.8)[4],
            color = node_colors,
            labels = names(bctdf_pa_combinedAgreementBcts),
            label.cex = 0.75,
            label.scale = FALSE,
            label.color = c(rep("black", 9)),
            theme = "colorblind")

from qgraph.

kamione avatar kamione commented on August 18, 2024

Same issue happens to me. I am thinking whether it is because the edge color specific in the mgm model does not inherit to the flow function. Any idea?

from qgraph.

SachaEpskamp avatar SachaEpskamp commented on August 18, 2024

Hi both,

Sorry for the late response. How do I read that cov matrix Matti? And do you possibly have an easier to reproduce example? It is possible indeed that this is due to the edge colors not being supplied. Perhaps try to store the results of flow(...) and then manually change the edge colors in the qgraph object?

Best, Sacha

from qgraph.

heinonmatti avatar heinonmatti commented on August 18, 2024

Apologies for being a bit novice with this. I now tinkered a bit with what little I could simulate, and found a hopefully more reproducible way to come about those grey edges.

If you use 5000 instead of 200 in MASS::mvrnorm(n = 200, mu = mus, Sigma = S), you'll get blue/red edges instead of grey ones, even though the categorical variables have two levels and grey edges don't appear in the "normal" (non-flow) network.

# Make covariance matrix. 
S <- matrix(c(1.0, 0.2, 0.1, 0.35, 0.0,
             0.2, 1.0, 0.0, 0.4, 0.0,
             0.1, 0.0, 1.0, 0.0, 0.4,
             0.35, 0.4, 0.0, 1.0, 0.6,
             0.0, 0.0, 0.4, 0.6, 1.0), ncol = 5)
colnames(S) <- c("Y1", "X1", "X2", "Z1" ,"Z2")
rownames(S) <- colnames(S)

# Make mean vector
mus <- c(1, 2, 3, 4, 5); names(mus) = colnames(S)

# Generate 5347 observations
obs <- MASS::mvrnorm(n = 200, mu = mus, Sigma = S)

obs <- data.frame(obs)
obs$categorical <- ifelse(obs$Y1 > 2, 1, 0)
obs$categorical2 <- ifelse(obs$X1 > 2, 1, 0)

bctdf_pa_combinedAgreementBcts <- obs

mgm_pa_variable_types <- c(rep("g", 5), "c", "c")
mgm_pa_variable_levels <- c(rep("1", 5), "2", "2")

mgm_obj <- mgm::mgm(data = bctdf_pa_combinedAgreementBcts,
                    type = mgm_pa_variable_types,
                    level = mgm_pa_variable_levels,
                    lambdaSel = "CV",
                    lambdaFolds = 10,
                    pbar = FALSE, 
                    binarySign = TRUE)

# PLOT NETWORK 

BCT_mgm <- qgraph::qgraph(mgm_obj$pairwise$wadj, 
                          layout = "spring",
                          repulsion = 1, # To nudge the network from originally bad visual state
                          title = "agreement-measured BCTs and PA",
                          edge.color = ifelse(mgm_obj$pairwise$edgecolor == "darkgreen", "blue", mgm_obj$pairwise$edgecolor),
                          labels = names(bctdf_pa_combinedAgreementBcts),
                          label.cex = 0.75,
                          label.scale = FALSE,
                          label.color = c(rep("black", 9)),
                          theme = "colorblind")

qgraph::flow(BCT_mgm, from = "Y1")

from qgraph.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.