Skip to content

Commit 9c01d30

Browse files
committed
setup air
1 parent 8440615 commit 9c01d30

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
^LICENSE
77
^docs/.
88
^README.Rmd
9+
^air.toml
910
^pkgdown/.
1011
^paper.*$
1112
^paper/.

R/group_level_total.R

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,41 +109,47 @@
109109
params <- NULL
110110

111111
# create full data frame of all random effects retrieved from coef()
112-
params <- do.call(rbind, lapply(group_factors, function(i) {
113-
# we want the posterior distribution from coef(), so we can
114-
# use bayestestR
115-
ranef <- stats::coef(x, summary = FALSE)[[i]]
116-
parameter_names <- dimnames(ranef)[[3]]
117-
out <- lapply(
118-
parameter_names,
119-
function(pn) {
120-
# summary of posterior
121-
d <- bayestestR::describe_posterior(as.data.frame(ranef[, , pn]), verbose = FALSE, ...)
122-
# add information about group factor and levels
123-
d$Group <- i
124-
# Parameters in the returned data frame are actually the levels
125-
# # from the group factors
126-
d$Level <- d$Parameter
127-
# the parameter names can be taken from dimnames
128-
d$Parameter <- pn
129-
d
130-
}
131-
)
132-
names(out) <- parameter_names
133-
do.call(rbind, out)
134-
}))
112+
params <- do.call(
113+
rbind,
114+
lapply(group_factors, function(i) {
115+
# we want the posterior distribution from coef(), so we can
116+
# use bayestestR
117+
ranef <- stats::coef(x, summary = FALSE)[[i]]
118+
parameter_names <- dimnames(ranef)[[3]]
119+
out <- lapply(
120+
parameter_names,
121+
function(pn) {
122+
# summary of posterior
123+
d <- bayestestR::describe_posterior(as.data.frame(ranef[,, pn]), verbose = FALSE, ...)
124+
# add information about group factor and levels
125+
d$Group <- i
126+
# Parameters in the returned data frame are actually the levels
127+
# # from the group factors
128+
d$Level <- d$Parameter
129+
# the parameter names can be taken from dimnames
130+
d$Parameter <- pn
131+
d
132+
}
133+
)
134+
names(out) <- parameter_names
135+
do.call(rbind, out)
136+
})
137+
)
135138

136139
# select parameters to keep. We want all intercepts, and all random slopes
137140
# from conditional and potential zero-inflation component
138141
parameters_to_keep <- params$Parameter %in% c("Intercept", random_slopes$random)
139-
parameters_to_keep <- parameters_to_keep | params$Parameter %in% c("zi_Intercept", random_slopes$zero_inflated_random)
142+
parameters_to_keep <- parameters_to_keep |
143+
params$Parameter %in% c("zi_Intercept", random_slopes$zero_inflated_random)
140144
# furthermore, categorical random slopes have levels in their name, so we
141145
# try to find those parameters here, too
142146
if (!is.null(random_slopes$random)) {
143-
parameters_to_keep <- parameters_to_keep | startsWith(params$Parameter, random_slopes$random)
147+
parameters_to_keep <- parameters_to_keep |
148+
startsWith(params$Parameter, random_slopes$random)
144149
}
145150
if (!is.null(random_slopes$zero_inflated_random)) {
146-
parameters_to_keep <- parameters_to_keep | startsWith(params$Parameter, paste0("zi_", random_slopes$zero_inflated_random))
151+
parameters_to_keep <- parameters_to_keep |
152+
startsWith(params$Parameter, paste0("zi_", random_slopes$zero_inflated_random))
147153
}
148154

149155
# add Component column

air.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[format]
2+
line-width = 100
3+
indent-width = 2
4+
indent-style = "space"
5+
line-ending = "auto"
6+
persistent-line-breaks = true
7+
exclude = []
8+
default-exclude = true

0 commit comments

Comments
 (0)