Skip to content

Commit 2c139e7

Browse files
committed
update example
1 parent 59dceea commit 2c139e7

10 files changed

Lines changed: 64 additions & 35 deletions

README.Rmd

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ matrix, making them user-friendly and useful for researchers and practitioners.
3838

3939
$$
4040
\hat{\Omega}(\lambda,\alpha,\gamma) = {\arg\min}_{\Omega \succ 0}
41-
\left\{ -\log\det(\Omega) + \text{tr}(S\Omega)
42-
+ \mathcal{P}_{\lambda,\alpha,\gamma}(\Omega) \right\},
41+
\left\{ -\log\det(\Omega) + \text{tr}(S\Omega) +
42+
\mathcal{P}_{\lambda,\alpha,\gamma}(\Omega) \right\},
4343
$$
4444
$$
4545
\mathcal{P}_{\lambda,\alpha,\gamma}(\Omega)
@@ -124,19 +124,30 @@ sim <- gen_prec_sbm(p = 30, K = 3,
124124
weight.paras = list(c(shape = 20, rate = 10),
125125
c(min = 0, max = 5)),
126126
cond.target = 100)
127+
## ground truth visualization
128+
plot(sim)
127129
128-
## synthetic data
130+
## n-by-p data matrix
129131
library(MASS)
130132
X <- mvrnorm(n = 20, mu = rep(0, 30), Sigma = sim$Sigma)
131133
132-
## solution
133-
res <- grasps(X = X, membership = sim$membership, penalty = "adapt", crit = "HBIC")
134+
## precision matrix: adaptive lasso; BIC
135+
prec <- grasps(X = X, membership = sim$membership, penalty = "adapt", crit = "BIC")
134136
135-
## visualization
136-
plot(res)
137+
## precision matrix visualization
138+
plot(prec)
137139
138140
## performance
139-
performance(hatOmega = res$hatOmega, Omega = sim$Omega)
141+
performance(hatOmega = prec$hatOmega, Omega = sim$Omega)
142+
143+
## adjacency matrix: diagonal = 0; raw partial correlations;
144+
## no thresholding; weighted network
145+
adj <- prec_to_adj(prec$hatOmega,
146+
diag.zero = TRUE, absolute = FALSE,
147+
threshold = NULL, weighted = TRUE)
148+
149+
## adjacency matrix visualization
150+
plot(adj)
140151
```
141152

142153

README.md

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ matrix, making them user-friendly and useful for researchers and practitioners.
1717

1818
$$
1919
\hat{\Omega}(\lambda,\alpha,\gamma) = {\arg\min}_{\Omega \succ 0}
20-
\left\{ -\log\det(\Omega) + \text{tr}(S\Omega)
21-
+ \mathcal{P}_{\lambda,\alpha,\gamma}(\Omega) \right\},
20+
\left\{ -\log\det(\Omega) + \text{tr}(S\Omega) +
21+
\mathcal{P}_{\lambda,\alpha,\gamma}(\Omega) \right\},
2222
$$
2323
$$
2424
\mathcal{P}_{\lambda,\alpha,\gamma}(\Omega)
@@ -90,40 +90,58 @@ sim <- gen_prec_sbm(p = 30, K = 3,
9090
weight.paras = list(c(shape = 20, rate = 10),
9191
c(min = 0, max = 5)),
9292
cond.target = 100)
93+
## ground truth visualization
94+
plot(sim)
95+
```
96+
97+
<img src="man/figures/README-unnamed-chunk-2-1.png" alt="" width="100%" />
9398

94-
## synthetic data
99+
``` r
100+
101+
## n-by-p data matrix
95102
library(MASS)
96103
X <- mvrnorm(n = 20, mu = rep(0, 30), Sigma = sim$Sigma)
97104

98-
## solution
99-
res <- grasps(X = X, membership = sim$membership, penalty = "adapt", crit = "HBIC")
105+
## precision matrix: adaptive lasso; BIC
106+
prec <- grasps(X = X, membership = sim$membership, penalty = "adapt", crit = "BIC")
100107

101-
## visualization
102-
plot(res)
108+
## precision matrix visualization
109+
plot(prec)
103110
```
104111

105-
<img src="man/figures/README-unnamed-chunk-2-1.png" alt="" width="100%" />
112+
<img src="man/figures/README-unnamed-chunk-2-2.png" alt="" width="100%" />
106113

107114
``` r
108115

109116
## performance
110-
performance(hatOmega = res$hatOmega, Omega = sim$Omega)
117+
performance(hatOmega = prec$hatOmega, Omega = sim$Omega)
111118
#> measure value
112-
#> 1 sparsity 0.9103
113-
#> 2 Frobenius 24.6557
114-
#> 3 KL 7.2100
115-
#> 4 quadratic 54.4284
116-
#> 5 spectral 13.1234
117-
#> 6 TP 22.0000
118-
#> 7 TN 370.0000
119-
#> 8 FP 17.0000
120-
#> 9 FN 26.0000
121-
#> 10 TPR 0.4583
122-
#> 11 FPR 0.0439
123-
#> 12 F1 0.5057
124-
#> 13 MCC 0.4545
119+
#> 1 sparsity 0.8805
120+
#> 2 Frobenius 23.9013
121+
#> 3 KL 7.6775
122+
#> 4 quadratic 69.1639
123+
#> 5 spectral 12.3571
124+
#> 6 TP 23.0000
125+
#> 7 TN 358.0000
126+
#> 8 FP 29.0000
127+
#> 9 FN 25.0000
128+
#> 10 TPR 0.4792
129+
#> 11 FPR 0.0749
130+
#> 12 F1 0.4600
131+
#> 13 MCC 0.3904
132+
133+
## adjacency matrix: diagonal = 0; raw partial correlations;
134+
## no thresholding; weighted network
135+
adj <- prec_to_adj(prec$hatOmega,
136+
diag.zero = TRUE, absolute = FALSE,
137+
threshold = NULL, weighted = TRUE)
138+
139+
## adjacency matrix visualization
140+
plot(adj)
125141
```
126142

143+
<img src="man/figures/README-unnamed-chunk-2-3.png" alt="" width="100%" />
144+
127145
## Reference
128146

129147
<div id="refs" class="references csl-bib-body hanging-indent">

inst/example/ex-grasps.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ sim <- gen_prec_sbm(p = 30, K = 3,
1010
weight.paras = list(c(shape = 20, rate = 10),
1111
c(min = 0, max = 5)),
1212
cond.target = 100)
13-
## visualization
13+
## ground truth visualization
1414
plot(sim)
1515

1616
## n-by-p data matrix
468 Bytes
Loading
24.4 KB
Loading
19.2 KB
Loading

man/grasps.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/performance.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plot.adjmat.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/prec_to_adj.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)