Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature missing reference dates #64

Closed
wants to merge 190 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
190 commits
Select commit Hold shift + click to select a range
7477b32
update pre-commit yaml
seabbs Jan 29, 2022
16506c4
add outline for formula passer
seabbs Jan 29, 2022
cd274a5
add first pass at formula interface tooling
seabbs Jan 29, 2022
2b4ea43
merge changes from main
seabbs Apr 14, 2022
f6e2df3
Remove reduce_sum parallelization
adrian-lison May 13, 2022
d288fe2
Add observations with missing reference date
adrian-lison May 13, 2022
6cdf3f2
Add alpha vector
adrian-lison May 15, 2022
6ca4657
Implement random walk prior on logit alpha
adrian-lison May 16, 2022
0e43ede
Simplify non-parallelized obs_lpmf
adrian-lison May 16, 2022
c3350ab
Make alpha doc more generic
adrian-lison May 16, 2022
2864eee
Add first draft of likelihood computation for missing reference dates
adrian-lison May 16, 2022
fa415e9
Implement slicing of likelihood for obs_miss from 1+dmax onwards
adrian-lison May 16, 2022
104efd6
Bugfix obs_lmpf and improve formatting
adrian-lison May 17, 2022
4539e48
Extend generated quantities to cases with missing reference date
adrian-lison May 17, 2022
0db6ce1
Change pp_inf_obs_miss_rep assignment to loop
adrian-lison May 18, 2022
17484d0
Fix typo
adrian-lison Jun 13, 2022
87e57e8
Catch bug if data.table contains column "group"
adrian-lison Jun 13, 2022
bdd2fba
Preprocess missing reference dates
adrian-lison Jun 13, 2022
2343ee9
Add automatic completion of missing reporting dates per group and ref…
adrian-lison Jun 13, 2022
d47c510
Change structure and fix assignment
adrian-lison Jun 13, 2022
4a0b647
Change date range for missing reference dates
adrian-lison Jun 13, 2022
41187e5
Add obs_miss to stan_data_list
adrian-lison Jun 13, 2022
dfb1297
update from main
seabbs Jun 15, 2022
d70e559
plan out formula interface in more detail
seabbs Jun 15, 2022
4570a8f
streamline final construction
seabbs Jun 15, 2022
61c351e
filter rw
seabbs Jun 15, 2022
8b68665
Change code comments
adrian-lison Jun 16, 2022
4e43eb7
Move completion to separate function, account for max_date
adrian-lison Jun 16, 2022
275efc8
Adapt obs_miss length from rd to t
adrian-lison Jun 16, 2022
08b8b1f
Correct alpha and obs in stan model
adrian-lison Jun 16, 2022
8add91b
Add priors for alpha
adrian-lison Jun 16, 2022
bd449e7
add more detail to outline
seabbs Jun 16, 2022
13759ff
Add support for missing reference dates to enw_retrospective_data
adrian-lison Jun 21, 2022
724f61c
Merge branch 'main' into feature-add-rw-re-formula-int
seabbs Jun 21, 2022
2e94e01
XMerge branch 'main' into feature-add-rw-re-formula-int
seabbs Jun 21, 2022
58b7da2
morework on formula interface
seabbs Jun 21, 2022
383fbf7
working construcotr for random walks
seabbs Jun 22, 2022
6cf52ec
add partial random effects structure
seabbs Jun 22, 2022
40a0309
prototype random effects constructor
seabbs Jun 22, 2022
73460c9
add comments for formula
seabbs Jun 22, 2022
e011eb9
more commenting
seabbs Jun 22, 2022
8cfb703
put formula pieces together
seabbs Jun 23, 2022
ac809ac
Fix generated quantities and add code doc
adrian-lison Jun 24, 2022
a48ae0a
Shorten loglik missing array
adrian-lison Jun 24, 2022
0d0e13a
add random walk term extraction and effects
seabbs Jun 24, 2022
74a2572
candidate formula function implemented
seabbs Jun 24, 2022
9f2e8cd
update readme to use formula interface
seabbs Jun 24, 2022
6bf72e1
refresh documentation
seabbs Jun 24, 2022
187fb15
add skeleton documentation
seabbs Jun 24, 2022
ba8d135
update README
seabbs Jun 24, 2022
eeb6d8c
fix no report model edge case
seabbs Jun 25, 2022
67df447
fix edge case with (Intercept) in random effect matrix
seabbs Jun 25, 2022
354edd0
implement case studies using formulas and fix edge cases
seabbs Jun 25, 2022
73e0d58
add note about reduce samples and iterations to vignette
seabbs Jun 25, 2022
43fc3e9
reduce samples used in README
seabbs Jun 25, 2022
f0fe7b4
add documentation for formula parsers
seabbs Jun 27, 2022
7d8d83d
add parse_formula docs
seabbs Jun 27, 2022
6bc72d2
add parse_formula docs
seabbs Jun 27, 2022
201f756
Merge branch 'feature-move-nb-to-log' into feature-add-rw-re-formula-int
seabbs Jun 27, 2022
07bfcb1
add documentation for rw and construct_rw
seabbs Jun 27, 2022
dbf458d
update pkgdown with new formula references
seabbs Jun 27, 2022
da6aed4
add random effect documentation
seabbs Jun 27, 2022
0956484
add complete formula docs + cran check
seabbs Jun 27, 2022
e395549
spell check, style, and iterate version
seabbs Jun 27, 2022
b85faa3
add codemeta
seabbs Jun 27, 2022
701a0e7
update docs and add pkg docs
seabbs Jun 27, 2022
2272b9d
add snapshot tests for enw_manual_formula
seabbs Jun 27, 2022
962cc1f
add snapshot tests for enw_formula
seabbs Jun 27, 2022
c76e9c2
update case study to use formula interface
seabbs Jun 27, 2022
832c234
Merge branch 'main' into feature-add-rw-re-formula-int
seabbs Jun 27, 2022
80211e8
Merge branch 'develop' into feature-add-rw-re-formula-int
seabbs Jun 27, 2022
b077f0a
update image tag
seabbs Jun 27, 2022
3a135da
update from develop
seabbs Jun 28, 2022
e01f76c
update example to use formula
seabbs Jun 28, 2022
9dff353
Merge pull request #27 from epiforecasts/feature-add-rw-re-formula-int
seabbs Jun 28, 2022
cbc5cc1
Use automated doc dev mode
seabbs Jun 28, 2022
28966f2
deploy docs from develop branch
seabbs Jun 28, 2022
345e71a
fix pkgdown.yaml
seabbs Jun 28, 2022
7a191da
scaffold out location for metadelay
seabbs Jun 28, 2022
6362a77
update family links for all fns
seabbs Jun 28, 2022
73aded3
model description clarifications
sbfnk Jun 29, 2022
98d247a
add support for non-factor random effects + initial delay metadatal
seabbs Jun 29, 2022
fad80a0
future-proof array declarations
sbfnk Jun 29, 2022
1e46bf9
ensure all parameters are initialised
sbfnk Jun 29, 2022
61754c3
update docs to reflect new metadata
seabbs Jun 29, 2022
60a8ef9
tests passing
seabbs Jun 29, 2022
ae8e507
add unit tests for enw_delay_metadata
seabbs Jun 29, 2022
fcb40d2
update news
seabbs Jun 29, 2022
8c1214c
refresh documentation
seabbs Jun 29, 2022
9d9ed8a
catch all optional model parameters and add @sbfnk as ctb
seabbs Jun 29, 2022
5c9b863
add snapshot unit tests of initial conditions
seabbs Jun 29, 2022
1b9e3d6
update example data
seabbs Jun 29, 2022
be24312
style and fix example
seabbs Jun 29, 2022
8571044
Merge pull request #77 from epiforecasts/init-params
seabbs Jun 29, 2022
8025afe
fix enw_construct_data docs
seabbs Jun 29, 2022
25a7057
remove non-standard folder
seabbs Jun 29, 2022
0375553
"reference" -> "occurrence"
sbfnk Jun 29, 2022
6694b41
"date" -> "time"
sbfnk Jun 29, 2022
0510e20
clarify use of enw_retrospective_data
sbfnk Jun 29, 2022
9566583
fix CRAN check
seabbs Jun 30, 2022
fa3ceb3
further CRAN check fixes
seabbs Jun 30, 2022
4e6484e
Merge pull request #80 from epiforecasts/feature-metadelay
seabbs Jun 30, 2022
f8d0714
merge changes from develop
seabbs Jun 30, 2022
cb3a249
catch more of cmdstanr only notation
seabbs Jun 30, 2022
0e741c7
update news with new changes
seabbs Jun 30, 2022
4624707
stan changes to support exponential delays
seabbs Jun 30, 2022
6390031
Merge pull request #75 from epiforecasts/fix-stan-warnigs
seabbs Jun 30, 2022
341d9ce
add R code support
seabbs Jun 30, 2022
6e27cc1
debug and review
seabbs Jun 30, 2022
e416d52
merge changes from develop
seabbs Jun 30, 2022
456f978
add news entry
seabbs Jun 30, 2022
c81960f
compatibility with rstan for exposing functions
sbfnk Jul 1, 2022
7c96a30
update variables names
sbfnk Jul 1, 2022
2f254b3
update distribution comment
seabbs Jul 4, 2022
5789bd5
fix comma dist docs
seabbs Jul 4, 2022
25c6426
fix whitespace
seabbs Jul 4, 2022
597e5cb
bump @sbfnk to author
seabbs Jul 4, 2022
8322a04
partial conversion to use dist for parametric control
seabbs Jul 4, 2022
361c13f
convert inner likelihood code to function
seabbs Jul 4, 2022
19a65df
linking model to index changes for no dist
seabbs Jul 4, 2022
5c2d9cb
linking model to index changes for no dist
seabbs Jul 4, 2022
40a30b7
add R interface
seabbs Jul 4, 2022
7bfa573
updated init tests and news in light of changes
seabbs Jul 4, 2022
10f49c6
lint package
seabbs Jul 4, 2022
37ad9b7
Merge pull request #84 from epiforecasts/feature-exp-delays
seabbs Jul 4, 2022
12e3725
move fn to not be exported and add docs
seabbs Jul 4, 2022
1a0aee3
convert expose_stan_fns to multiple fns
seabbs Jul 4, 2022
134f6b4
update news with new PR
seabbs Jul 4, 2022
9ee9bad
add tests and improve regex
seabbs Jul 4, 2022
e741f83
inverse tests
seabbs Jul 4, 2022
36c23f8
merge develop
seabbs Jul 4, 2022
14df115
Merge pull request #85 from epiforecasts/fix-expose-fns
seabbs Jul 4, 2022
3f3c0b9
add develop branch to contributing
seabbs Jul 4, 2022
68765e2
Merge pull request #86 from epiforecasts/update-contributing
seabbs Jul 4, 2022
c40224e
merge develop
seabbs Jul 4, 2022
8960181
first pass doc and code review, clarify filtering
seabbs Jul 4, 2022
a0795f2
add check dates
seabbs Jul 4, 2022
c341429
recast retrospective data construction to modular
seabbs Jul 4, 2022
5ec053d
update example
seabbs Jul 4, 2022
da7a461
add @sbfnk regex suggestion
seabbs Jul 4, 2022
62e7ae3
update news
seabbs Jul 4, 2022
9e4768d
formatting
seabbs Jul 5, 2022
10e7d0b
fix missing bracket
seabbs Jul 5, 2022
5953dd1
add an additional line of regex for matrix and vector case
seabbs Jul 5, 2022
38ab910
Merge pull request #93 from epiforecasts/bug-safer-regex
seabbs Jul 5, 2022
77be8c0
update vignettes
seabbs Jul 5, 2022
643a1da
update news and readme.Rmd
seabbs Jul 5, 2022
42c82ac
remove references to enw_retrospective_data in docs and tests
seabbs Jul 5, 2022
8855d2b
add tests for check_dates
seabbs Jul 6, 2022
ca46036
Streamline grouping parameter of complete_dates and format
adrian-lison Jul 6, 2022
7f1a325
add filtering tests
seabbs Jul 6, 2022
27fd0e7
Streamline groups
adrian-lison Jul 6, 2022
a0fe344
Replace group with .group
adrian-lison Jul 6, 2022
ddaf6f4
styleh
seabbs Jul 6, 2022
93218fd
Merge pull request #82 from epiforecasts/clarify-retrospective
seabbs Jul 6, 2022
48430cf
Merge branch 'develop' into refactor_rename_group_variable
seabbs Jul 6, 2022
b760d8f
run styling and add check fn
seabbs Jul 6, 2022
e5f1026
add tests for check_group
seabbs Jul 6, 2022
b2a6d92
add testing of model compilation
seabbs Jul 6, 2022
6d8561d
add random walk as cumulative sum
seabbs Jul 6, 2022
833bc77
add test for profiling
seabbs Jul 6, 2022
ce93c5c
lint tests
seabbs Jul 6, 2022
183526f
get rid of loop
seabbs Jul 6, 2022
ea9f85c
add news update
seabbs Jul 6, 2022
f757b14
spell check
seabbs Jul 6, 2022
d82b711
hotfix preprocessing
seabbs Jul 6, 2022
da58625
merge hotfix for preprocessing
seabbs Jul 6, 2022
34722fe
hotfix filter preprocessing
seabbs Jul 6, 2022
9183e65
hotfix scoring
seabbs Jul 6, 2022
6dca63b
merge hotfixs
seabbs Jul 6, 2022
2a18a17
test CI using cmdstan 2.29.0
seabbs Jul 6, 2022
807c1b1
Fix typos
adrian-lison Jul 7, 2022
717057d
Merge branch 'develop' into refactor_rename_group_variable
adrian-lison Jul 7, 2022
8833763
Update example data
adrian-lison Jul 7, 2022
0a5945f
Update news
adrian-lison Jul 7, 2022
f2f60b7
Fix my own typo in news
adrian-lison Jul 7, 2022
6c9ff9f
Fix grammar in news
adrian-lison Jul 7, 2022
5d1e065
make test coverage use 2.29.0
seabbs Jul 7, 2022
ba6f217
Merge pull request #103 from epiforecasts/feature-cumulative-sum-expe…
seabbs Jul 7, 2022
df67660
merge news from develop
seabbs Jul 7, 2022
3664315
save news changes this time
seabbs Jul 7, 2022
ab7add7
merge with develop
seabbs Jul 7, 2022
66e7d71
update DESCRIPTION
seabbs Jul 7, 2022
b82e0a2
replace last occurrence references
seabbs Jul 7, 2022
d47dcbf
add link to documentation to the readme
seabbs Jul 7, 2022
598f855
Merge pull request #102 from epiforecasts/refactor_rename_group_variable
adrian-lison Jul 7, 2022
b52f792
review model description
seabbs Jul 7, 2022
005b74f
add news item
seabbs Jul 7, 2022
3dc4ac0
Merge pull request #71 from epiforecasts/model-description-sbfnk-review
seabbs Jul 7, 2022
8acaf51
merge in develop
seabbs Jul 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add complete formula docs + cran check
  • Loading branch information
seabbs committed Jun 27, 2022
commit 0956484b602b0c0f4c055067adfc427da17900ce
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ Imports:
posterior,
purrr,
rstan,
scales,
lme4
scales
Suggests:
loo (>= 2.4.1),
knitr,
Expand Down
145 changes: 130 additions & 15 deletions R/formula-tools.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@

#' Define a model manually using fixed and random effects
#'
#' @description For most typical use cases [enw_formula()] should
#' provide sufficient flexibility to allow models to be defined. However,
#' there may be some instances where more manual model specification is
#' required. This function supports this by allowing the user to supply
#' vectors of fixed, random, and customised random effects (where they are
#' not first treated as fixed effect terms). Prior to `1.0.0` this was the
#' main interface for specifying models and it is still used internally to
#' handle some parts of the model specification process.
#'
#' @param fixed A character vector of fixed effects.
#'
#' @param random A character vector of random effects. Random effects
#' specified here will be added to the fixed effects.
#'
#' @param custom_random A vector of random effects. Random effects added here
#' will not be added to the vector of fixed effects. This can be used to random
#' effects for fixed effects that only have a partial name match.
#'
#' @param no_contrasts Defaults to `FALSE`. `TRUE` means that no variable uses
#' contrast. Alternatively a character vector of variables can be supplied
#' indicating which variables should not have contrasts.
#'
#' @return A list specifying the fixed effects (formula, design matrix, and
#' design matrix index), and random effects (formula and design matrix).
#'
#' @inheritParams enw_formula
#' @family formulatools
#' @importFrom data.table copy
#' @importFrom stats as.formula
#' @export
#' @examples
#' data <- enw_example("prep")$metareference[[1]]
#' enw_manual_formula(data, fixed ="max_confirm", random = "day_of_week")
enw_manual_formula <- function(data, fixed = c(), random = c(),
custom_random = c(), no_contrasts = FALSE) {
data <- data.table::copy(data)
form <- c("1")

cr_in_dt <- purrr::map(
custom_random, ~ colnames(data)[startsWith(colnames(data), .)]
)
cr_in_dt <- unlist(cr_in_dt)

form <- c(form, fixed, random, cr_in_dt)
if (length(random) > 0) {
no_contrasts <- c(random)
}
form <- as.formula(paste0("~ ", paste(form, collapse = " + ")))

# build effects design matrix (with no contrasts)
fixed <- enw_design(form, data,
no_contrasts = no_contrasts,
sparse = TRUE
)

# get effects
effects <- enw_effects_metadata(fixed$design)

random <- c(random, custom_random)

if (length(random) == 0) {
random <- enw_design(~1, effects, sparse = FALSE)
} else {
for (i in random) {
effects <- enw_add_pooling_effect(effects, i, var_name = i)
}
rand_form <- c("0", "fixed", random)
rand_form <- as.formula(paste0("~ ", paste(rand_form, collapse = " + ")))
random <- enw_design(rand_form, effects, sparse = FALSE)
}
return(list(fixed = fixed, random = random))
}

#' Converts formulas to strings
#'
#' @return A character string of the supplied formula
Expand Down Expand Up @@ -144,7 +220,8 @@ parse_formula <- function(formula) {
#' @param time Defines the random walk time period.
#'
#' @param by Defines the grouping parameter used for the random walk.
#' If not specified no grouping is used.
#' If not specified no grouping is used. Currently this is limited to a single
#' variable.
#'
#' @param type Character string, defaults to "independent". How should the
#' standard deviation of byed random walks be estimated. Currently this can
Expand Down Expand Up @@ -271,16 +348,16 @@ construct_rw <- function(rw, data) {
#' when a random effect is defined using the [lme4] syntax in
#' formula. Currently only simplified random effecs (i.e
#' LHS | RHS) are supported.
#'
#'
#' @export
#' @return A list defining the fixed and random effects of the specified
#' random effect
#' @family formulatools
#' @examples
#' form <- parse_formula(~ 1 + (1 | age_group))
#' form <- epinowcast:::parse_formula(~ 1 + (1 | age_group))
#' re(form$random[[1]])
#'
#' form <- parse_formula(~ 1 + (location | age_group))
#' form <- epinowcast:::parse_formula(~ 1 + (location | age_group))
#' re(form$random[[1]])
re <- function(formula) {
terms <- strsplit(as_string_formula(formula), " \\| ")[[1]]
Expand All @@ -292,7 +369,7 @@ re <- function(formula) {
}

#' Constructs random effect terms
#'
#'
#' @param re A random effect as defined using [re()] which itself takes
#' random effects specifed in a model formula using the [lme4] syntax.
#'
Expand All @@ -303,18 +380,19 @@ re <- function(formula) {
#' @return A list containing the fixed effects terms ("terms") and
#' a `data.frame` specfying the random effect structure betwee
#' these terms (`effects`).
#'
#'
#' @family formulatools
#' @importFrom data.table copy
#' @examples
#' form <- parse_formula(~ 1 + (1 | day_of_week))
#' form <- epinowcast:::parse_formula(~ 1 + (1 | day_of_week))
#' data <- enw_example("prepr")$metareference[[1]]
#' random_effect <- re(form$random[[1]])
#' epinowcast:::construct_re(random_effect, data)
construct_re <- function(re, data) {
if (!(class(re) %in% "enw_re_term")) {
stop("re must be a random effect term as constructed by re")
}
data <- data.table::as.data.table(data)
data <- data.table::copy(data)

# extract random and fixed effects
fixed <- strsplit(re$fixed, " \\+ ")[[1]]
Expand Down Expand Up @@ -351,19 +429,56 @@ construct_re <- function(re, data) {
return(list(terms = terms, effects = effects))
}

#' @title FUNCTION_TITLE
#' @description FUNCTION_DESCRIPTION
#' Define a model using a formula interface
#'
#' @param formula DESCRIPTION
#' @description This function allows models to be defined using a
#' flexible formula interface that supports fixed effects, random effects
#' (using [lme4] syntax). Note that the returned fixed effects design matrix is
#' sparse and so the index supplied is required to link observations to the
#' appropriate design matrix row.
#'
#' @param data DESCRIPTION
#' @param formula A model formula that may use standard fixed
#' effects, random effects using [lme4] syntax (see [re()]), and random walks
#' defined using the [rw()] helper function.
#'
#' @param data A `data.frame` of observations. It must include all
#' variables used in the supplied formula.
#
#' @return A design matrix and metadata
#' @family modeldesign
#' @return A list containing the following:
#' - `formula`: The user supplied formula
#' - `parsed_formula`: The formula as parsed by [parse_formula()]
#' - `extended_formula`: The flattened version of the formula with
#' both user supplied terms and terms added for the user supplied
#' complex model components.
#' - `fixed`: A list containing the fixed effect formula, sparse design
#' matrix, and the index linking the design matrix with observations.
#' - `random`: A list containing the random effect formula, sparse design
#' matrix, and the index linking the design matrix with random effects.
#'
#' @family formulatools
#' @export
#' @importFrom purrr map transpose
#' @importFrom data.table rbindlist setnafill
#' @importFrom data.table as.data.table rbindlist setnafill
#' @examples
#' # Use meta data for references dates from the Germany COVID-19
#' # hospitalisation data.
#' obs <- enw_retrospective_data(
#' germany_covid19_hosp[location == "DE"], rep_days = 40, ref_days = 40
#' )
#' pobs <- enw_preprocess_data(obs, by = c("age_group", "location"))
#' data <- pobs$metareference[[1]]
#'
#' # Model with fixed effects for age group
#' enw_formula(~ 1 + age_group, data)
#'
#' # Model with random effects for age group
#' enw_formula(~ 1 + (1 | age_group), data)
#'
#' # Model with a random effect for age group and a random walk
#' enw_formula(~ 1 + (1 | age_group) + rw(week), data)
enw_formula <- function(formula, data) {
data <- data.table::as.data.table(data)

# Parse formula
parsed_formula <- parse_formula(formula)

Expand Down
57 changes: 0 additions & 57 deletions R/model-design-tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,60 +172,3 @@ enw_add_cumulative_membership <- function(metaobs, feature) {
}
return(metaobs[])
}

#' @title FUNCTION_TITLE
#' @description FUNCTION_DESCRIPTION
#' @param metaobs PARAM_DESCRIPTION
#'
#' @param fixed PARAM_DESCRIPTION. Default: c()
#'
#' @param random PARAM_DESCRIPTION. Default: c()
#'
#' @param custom_random PARAM_DESCRIPTION. Default: c()
#'
#' @param no_contrasts PARAM_DESCRIPTION
#' @return OUTPUT_DESCRIPTION
#'
#' @family modeldesign
#' @importFrom data.table copy
#' @importFrom stats as.formula
#' @export
enw_manual_formula <- function(metaobs, fixed = c(), random = c(),
custom_random = c(), no_contrasts = FALSE) {
metaobs <- data.table::copy(metaobs)
form <- c("1")

cr_in_dt <- purrr::map(
custom_random, ~ colnames(metaobs)[startsWith(colnames(metaobs), .)]
)
cr_in_dt <- unlist(cr_in_dt)

form <- c(form, fixed, random, cr_in_dt)
if (length(random) > 0) {
no_contrasts <- c(random)
}
form <- as.formula(paste0("~ ", paste(form, collapse = " + ")))

# build effects design matrix (with no contrasts)
fixed <- enw_design(form, metaobs,
no_contrasts = no_contrasts,
sparse = TRUE
)

# get effects
effects <- enw_effects_metadata(fixed$design)

random <- c(random, custom_random)

if (length(random) == 0) {
random <- enw_design(~1, effects, sparse = FALSE)
} else {
for (i in random) {
effects <- enw_add_pooling_effect(effects, i, var_name = i)
}
rand_form <- c("0", "fixed", random)
rand_form <- as.formula(paste0("~ ", paste(rand_form, collapse = " + ")))
random <- enw_design(rand_form, effects, sparse = FALSE)
}
return(list(fixed = fixed, random = random))
}
6 changes: 5 additions & 1 deletion man/as_string_formula.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/construct_re.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/construct_rw.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/enw_add_cumulative_membership.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/enw_add_pooling_effect.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/enw_dates_to_factors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/enw_design.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/enw_effects_metadata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading