-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
169 lines (124 loc) · 4.01 KB
/
Copy pathREADME.Rmd
File metadata and controls
169 lines (124 loc) · 4.01 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
---
output: github_document
bibliography: references.bib
editor_options:
markdown:
wrap: 72
---
<!-- 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%"
)
```
# ggcommonality <img src="man/ggcommonality_sticker.png" align="right"/>
<!-- badges: start -->
<!-- badges: end -->
ggcommonality creates bar plots of unique and joint effects from a
commonality analysis of a linear regression model. The S4 branch extends
its functionality using an object-oriented syntax. The package calls on
`yhat` to perform commonality analyses [@nimon2023r], building bar plots
in the style of those appearing in the [MAPLE
Lab's](https://maplelab.net) work applying commonality analysis to the
compositions of Bach and Chopin [@delle2025breaking;
@anderson2022exploring].
Partitions are plotted sequentially in alphabetical order, starting with
unique effects and are built iteratively with joint effects at higher
orders on top.
Note: This package is a hobby project and is currently under development, so there are likely many bugs I have yet to find and fix.
## Installation
You can install ggcommonality (under development) from
[GitHub](https://github.com/) with:
``` r
devtools::install_github("cmndrsn/ggcommonality", build_vignettes = TRUE, force = TRUE)
```
## Example
The function produces a GGCommonality object, containing ingredients for
plotting commonality effects, along with the results from the
commonality analysis.
```{r example, warning=FALSE}
library(ggcommonality)
my_formula <- mpg ~ wt + hp
p <- ggcom(formula = my_formula,
data = mtcars)
p |> attributes() |> summary()
```
ggcommonality objects can be defined, plotted, and summarized using
built-in methods.
```{r}
# visualize commonality effects and add confidence intervals
plot(p) +
ggcom_ci(p)
```
We can also check the output from the `yhat` package
```{r commonality, warning=FALSE}
ggcom_yhat(p)
```
Commonality effects can be stacked in multiple ways:
```{r warning=FALSE}
# update object
p@stack <- 'common'
# stack
plot(p) +
ggcom_ci(p)+
ylim(0, 0.7)
```
```{r}
# update object
slot(p, 'stack') <- "partition"
# stack
plot(p) +
ggcom_ci(p)
```
The `ggcom_ci()` method prints confidence intervals generated for stacked
effects.
```{r}
ggcom_ci(p)
```
# Confidence intervals
The `resample_type` argument specifies whether to generate random-*x*,
confidence intervals, fixed-*x*, or wild-*x* confidence intervals. The
[appendices](https://www.john-fox.ca/Companion/) to @fox2018r summarizes
the advantages and disadvantages of fixed vs. random-*x* bootstrapping.
There is also a wild-*x* option implemented as described[here](https://stats.stackexchange.com/a/408688).
If `stack_by = "partition"`, confidence intervals represent the sum of
unique and joint effects for individual commonality partitions.
Otherwise, if `stack_by = "common"`, separate confidence intervals are
generated for the sum of unique effects and the sum of joint effects.
Confidence intervals by default for these options are based on positive coefficients, but
can be specified with an argument to `ggcom_ci()` (sign = "+" for positive coefficients, sign = "-" for negative ones, or sign = "" for both).
## Comparing confidence intervals
```{r warning=FALSE, message=FALSE}
# set r's random number generator
p1 <- ggcom(
formula = my_formula,
data = mtcars,
resample_type = "fixed"
)
p2 <- ggcom(
formula = my_formula,
data = mtcars,
resample_type = "wild"
)
library(patchwork)
# stack
plot(p1) +
ggcom_ci(p1)+
ylim(0,0.65)+
ggtitle("Fixed")|
plot(p2) +
ggcom_ci(p2)+
ylim(0,0.65)+
ggtitle("Wild")
```
# Getting help
For additional details about on plotting with ggcommonality, see the 'Advanced ggcommonality' vignette:
```{r}
vignette('advanced-ggcommonality', 'ggcommonality')
```
You can also read the help documentation
`?ggcom()`, or [email me](mailto:[email protected]).
# References