Skip to contents

Format formula data for use with stan

Usage

enw_formula_as_data_list(formula, prefix, drop_intercept = FALSE)

Arguments

formula

The output of enw_formula().

prefix

A character string indicating variable label to use as a prefix.

drop_intercept

Logical, defaults to FALSE. Should the intercept be included as a fixed effect or excluded. This is used internally in model modules where an intercept must be present/absent.

Value

A list defining the model formula. This includes:

  • prefix_fintercept: Is an intercept present for the fixed effects design matrix.

  • prefix_fdesign: The fixed effects design matrix

  • prefix_fnrow: The number of rows of the fixed design matrix

  • prefix_findex: The index linking design matrix rows to observations

  • prefix_fnindex: The length of the index

  • prefix_fncol: The number of columns (i.e effects) in the fixed effect design matrix (minus 1 if drop_intercept = TRUE).

  • prefix_rdesign: The random effects design matrix

  • prefix_rncol: The number of columns (i.e random effects) in the random effect design matrix (minus 1 as the intercept is dropped).

See also

Functions used to help convert models into the format required for stan enw_get_cache(), enw_model(), enw_priors_as_data_list(), enw_replace_priors(), enw_sample(), enw_set_cache(), enw_stan_to_r(), enw_unset_cache(), remove_profiling(), write_stan_files_no_profile()

Examples

f <- enw_formula(~ 1 + (1 | cyl), mtcars)
enw_formula_as_data_list(f, "mtcars")
#> $mtcars_fdesign
#>   (Intercept) cyl4 cyl6 cyl8
#> 1           1    0    1    0
#> 3           1    1    0    0
#> 5           1    0    0    1
#> 
#> $mtcars_fintercept
#> [1] 1
#> 
#> $mtcars_fnrow
#> [1] 3
#> 
#> $mtcars_findex
#>  [1] 1 1 2 1 3 1 3 2 2 1 1 3 3 3 3 3 3 2 2 2 2 3 3 3 3 2 2 2 3 1 3 2
#> 
#> $mtcars_fnindex
#> [1] 32
#> 
#> $mtcars_fncol
#> [1] 4
#> 
#> $mtcars_rdesign
#>   fixed cyl
#> 1     0   1
#> 2     0   1
#> 3     0   1
#> attr(,"assign")
#> [1] 1 2
#> 
#> $mtcars_rncol
#> [1] 1
#> 

# A missing formula produces the default list
enw_formula_as_data_list(prefix = "missing")
#> $missing_fdesign
#> numeric(0)
#> 
#> $missing_fintercept
#> [1] 0
#> 
#> $missing_fnrow
#> [1] 0
#> 
#> $missing_findex
#> numeric(0)
#> 
#> $missing_fnindex
#> [1] 0
#> 
#> $missing_fncol
#> [1] 0
#> 
#> $missing_rdesign
#> numeric(0)
#> 
#> $missing_rncol
#> [1] 0
#>