Comments (3)
Hi! Indeed you can use the fun
argument for specifying a custom estimation function! Please make sure that the input to EBICglasso
is the sample variance-covariance matrix and not a matrix with artificially changed values - such a matrix would no longer lead to the correct Gaussian likelihood of the data making the EBICglasso function not work at all.
from bootnet.
It turns out that the example above actually does not work: that is, setting a correlation to zero does not guarantee that its edges will be absent in the estimated weights matrix.
However, with respect to the original question, I finally found an answer to this question in the documentation. It turns out that as long as your function returns a results
object i.e. a weights matrix, then you can just use this function with the estimateNetwork()
function with the additional argument fun = my_function
.
Again: in my case, the actual rationale for modifying this correlation matrix does not make sense. However, for those who might have have a case where the process of estimating a weights matrix is too idiosyncratic to automate with bootnet, perhaps you will find it helpful to know that you can stipulate how you want your weight matrix to be calculated by intervening with that fun
argument.
Here is how I accomplished this for my specific situation:
library(psych)
library(qgraph)
library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.1.2
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(bootnet)
#> Loading required package: ggplot2
#>
#> Attaching package: 'ggplot2'
#> The following objects are masked from 'package:psych':
#>
#> %+%, alpha
#> This is bootnet 1.5
#> For questions and issues, please see github.com/SachaEpskamp/bootnet.
# get data
network_data <- bfi %>% select(contains("1") | contains("2"))
# get correlation matrix (for input into unconstrained model)
cors <- cor_auto(network_data, detectOrdinal = TRUE)
#> Variables detected as ordinal: A1; C1; E1; N1; O1; A2; C2; E2; N2; O2
# set correlations to zero (for input into constrained model)
cors_constrained <- cors
cors_constrained[6, 1] <- 0
cors_constrained[7, 2] <- 0
cors_constrained[1, 6] <- 0
cors_constrained[2, 7] <- 0
constrained_weights <- EBICglasso(S = cors_constrained, n = nrow(network_data))
#> Warning in EBICglassoCore(S = S, n = n, gamma = gamma, penalize.diagonal =
#> penalize.diagonal, : A dense regularized network was selected (lambda < 0.1 *
#> lambda.max). Recent work indicates a possible drop in specificity. Interpret the
#> presence of the smallest edges with care. Setting threshold = TRUE will enforce
#> higher specificity, at the cost of sensitivity.
# plot network with qgraph
qgraph(constrained_weights, edge.labels = TRUE, curveAll = TRUE, title = "constrained", layout = "spring")
# achieve same network with bootnet
my_fun <- function(data){
set.seed(352)
cor_example <- cor_auto(data)
n <- nrow(data)
cors_constrained <- cor_example
cors_constrained[6, 1] <- 0
cors_constrained[7, 2] <- 0
cors_constrained[1, 6] <- 0
cors_constrained[2, 7] <- 0
# estimate weights matrix
graph <- EBICglasso(S = cors_constrained, n = n)
return(graph = graph)
}
estimateNetwork(network_data, fun = my_fun) %>% plot(edge.labels = TRUE, layout = "spring")
#> Variables detected as ordinal: A1; C1; E1; N1; O1; A2; C2; E2; N2; O2
#> Warning in EBICglassoCore(S = S, n = n, gamma = gamma, penalize.diagonal =
#> penalize.diagonal, : A dense regularized network was selected (lambda < 0.1 *
#> lambda.max). Recent work indicates a possible drop in specificity. Interpret the
#> presence of the smallest edges with care. Setting threshold = TRUE will enforce
#> higher specificity, at the cost of sensitivity.
Created on 2022-08-24 by the reprex package (v2.0.1)
from bootnet.
Thank you for replying, and for the heads up about the likelihood!!
from bootnet.
Related Issues (20)
- How to adjust the size of labels HOT 2
- Similar question to "Plotting centrality stability showing only "strength" #88" HOT 3
- I cannot calculate the difference of "closeness". HOT 2
- Question about edge color difference between "mgm" and "estimatenetwork(bootnet)" HOT 2
- How to set alpha parameter of elastic net penalty in estimatenetwork function? HOT 2
- some question about big sample size HOT 2
- failed installing botnet HOT 2
- Cross-lagged panel networks in bootnet HOT 8
- Bootnet should plot categorical interaction edges as grey when using mgm
- Mixing different data types in GGM - preprocessing ? HOT 1
- How to display computing progress when using estimateNetwork function with mgm method? HOT 2
- correlation matrix is not positive definite HOT 1
- Can not plotting subset bootstrapped estimates when using "plot='difference' "
- Node-Dropping Bootstrap: "Lowest Lambda was selected" HOT 1
- partial correlations HOT 2
- Some issues about the cormethod of ggmmodselect & NCT HOT 2
- Error with dplyr::bind_rows() HOT 1
- Correlation matrix is not positive definite HOT 1
- Code credit HOT 1
- Correlation matrix is not positive definite HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bootnet.