-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
154 lines (105 loc) · 4.58 KB
/
Copy pathREADME.Rmd
File metadata and controls
154 lines (105 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
output:
github_document:
pandoc_args: [ "--wrap=preserve", "--columns=80" ]
bibliography: inst/REFERENCES.bib
link-citations: yes
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# grasps <img src="man/figures/logo.png" align="right" alt="" width="150">
## Groupwise Regularized Adaptive Sparse Precision Solution
[](https://CRAN.R-project.org/package=grasps)
[](https://github.com/Carol-seven/grasps/blob/main/DESCRIPTION)
[](https://github.com/Carol-seven/grasps/commits/main)
[](https://github.com/Carol-seven/grasps/actions/workflows/R-CMD-check.yaml)
[](https://github.com/Carol-seven/grasps/blob/main/LICENSE.md)
The goal of **grasps** is to provide a collection of statistical methods that
incorporate both element-wise and group-wise penalties to estimate a precision
matrix, making them user-friendly and useful for researchers and practitioners.
$$
\hat{\Omega}(\lambda,\alpha,\gamma) = {\arg\min}_{\Omega \succ 0}
\{ -\log\det(\Omega) + \text{tr}(S\Omega) + \mathcal{P}_{\lambda,\alpha,\gamma}(\Omega) \},
$$
$$
\mathcal{P}_{\lambda,\alpha,\gamma}(\Omega)
= \alpha \mathcal{P}^\text{idv}_{\lambda,\gamma}(\Omega) + (1-\alpha) \mathcal{P}^\text{grp}_{\lambda,\gamma}(\Omega),
$$
$$
\mathcal{P}^\text{idv}_{\lambda,\gamma}(\Omega)
= \sum_{i,j} P_{\lambda,\gamma}(\lvert\omega_{ij}\rvert),
$$
$$
\mathcal{P}^\text{grp}_{\lambda,\gamma}(\Omega)
= \sum_{g,g^\prime} P_{\lambda,\gamma}(\lVert\Omega_{gg^\prime}\rVert_F).
$$
For more details, see the vignette
[Penalized Precision Matrix Estimation in grasps](https://shiying-xiao.com/grasps/articles/pen_est#sparse-group-estimator).

## Penalties
The package **grasps** provides functions to estimate precision matrices using
the following penalties:
| Penalty | Reference |
|:--------|:----------|
| Lasso (`penalty = "lasso"`) | @tibshirani1996regression; @friedman2008sparse |
| Adaptive lasso (`penalty = "adapt"`) | @zou2006adaptive; @fan2009network |
| Atan (`penalty = "atan"`) | @wang2016variable |
| Exp (`penalty = "exp"`) | @wang2018variable |
| Lq (`penalty = "lq"`) | @frank1993statistical; @fu1998penalized; @fan2001variable |
| LSP (`penalty = "lsp"`) | @candes2008enhancing |
| MCP (`penalty = "mcp"`) | @zhang2010nearly |
| SCAD (`penalty = "scad"`) | @fan2001variable; @fan2009network |
See the vignette
[Penalized Precision Matrix Estimation in grasps](https://shiying-xiao.com/grasps/articles/pen_est#penalties)
for more details.
## Installation
+ You can install the released version of **grasps** from
[CRAN](https://cran.r-project.org/package=grasps) with:
```
install.packages("grasps")
```
+ You can install the development version of **grasps** from
[GitHub](https://github.com/Carol-seven/grasps) with:
```
# install.packages("pak")
pak::pkg_install("Carol-seven/grasps")
```
## Example
```{r}
library(grasps)
## reproducibility for everything
set.seed(1234)
## block-structured precision matrix based on SBM
sim <- gen_prec_sbm(p = 30, K = 3,
within.prob = 0.25, between.prob = 0.05,
weight.dists = list("gamma", "unif"),
weight.paras = list(c(shape = 20, rate = 10),
c(min = 0, max = 5)),
cond.target = 100)
## ground truth visualization
plot(sim)
## n-by-p data matrix
library(MASS)
X <- mvrnorm(n = 20, mu = rep(0, 30), Sigma = sim$Sigma)
## precision matrix: adaptive lasso; BIC
prec <- grasps(X = X, membership = sim$membership, penalty = "adapt", crit = "BIC")
## precision matrix visualization
plot(prec)
## performance
performance(hatOmega = prec$hatOmega, Omega = sim$Omega)
## adjacency matrix: diagonal = 0; raw partial correlations;
## no thresholding; weighted network
adj <- prec_to_adj(prec$hatOmega,
diag.zero = TRUE, absolute = FALSE,
threshold = NULL, weighted = TRUE)
## adjacency matrix visualization
plot(adj)
```
## Reference {-}