Takes a set of new sampling statements, which can be parametrized by other arguments, data frames, or lists, and creates an adjustr_spec object suitable for use in adjust_weights.

make_spec(...)

Arguments

...

Model specification. Each argument can either be a formula, a named vector, data frames, or lists.

Formula arguments provide new sampling statements to replace their counterparts in the original Stan model. All such formulas must be of the form variable ~ distribution(parameters), where variable and parameters are Stan data variables or parameters, or are provided by other arguments to this function (see below), and where distribution matches one of the univariate Stan distributions. Arithmetic expressions of parameters are also allowed, but care must be taken with multivariate parameter arguments. Since specifications are passed as formulas, R's arithmetic operators are used, not Stan's. As a result, matrix and elementwise multipilcation in Stan sampling statements may not be interpreted correctly. Moving these computations out of sampling statements and into local variables will ensure correct results.

For named vector arguments, each entry of the vector will be substituted into the corresponding parameter in the sampling statements. For data frames, each entry in each column will be substituted into the corresponding parameter in the sampling statements.

List arguments are coerced to data frames. They can either be lists of named vectors, or lists of lists of single-element named vectors.

The lengths of all parameter arguments must be consistent. Named vectors can have length 1 or must have length equal to the number of rows in all data frame arguments and the length of list arguments.

Value

An object of class adjustr_spec, which is essentially a list with two elements: samp, which is a list of sampling formulas, and params, which is a list of lists of parameters. Core dplyr verbs which don't involve grouping (filter, arrange, mutate, select, rename, and slice) are supported and operate on the underlying table of specification parameters.

Examples

make_spec(eta ~ cauchy(0, 1))
#> Sampling specifications:
#> eta ~ cauchy(0, 1)
#> <environment: 0x13b19e5f8>

make_spec(eta ~ student_t(df, 0, 1), df=1:10)
#> Sampling specifications:
#> eta ~ student_t(df, 0, 1)
#> <environment: 0x13b19e5f8>
#> 
#> Specification parameters:
#>  df
#>   1
#>   2
#>   3
#>   4
#>   5
#>   6
#>   7
#>   8
#>   9
#>  10

params = tidyr::crossing(df=1:10, infl=c(1, 1.5, 2))
make_spec(eta ~ student_t(df, 0, 1),
          y ~ normal(theta, infl*sigma),
          params)
#> Sampling specifications:
#> eta ~ student_t(df, 0, 1)
#> <environment: 0x13b19e5f8>
#> y ~ normal(theta, infl * sigma)
#> <environment: 0x13b19e5f8>
#> 
#> Specification parameters:
#>  df infl
#>   1    1
#>   1  1.5
#>   1    2
#>   2    1
#>   2  1.5
#>   2    2
#>   3    1
#>   3  1.5
#>   3    2
#>   4    1
#>   4  1.5
#>   4    2
#>   5    1
#>   5  1.5
#>   5    2
#>  [ reached 'max' / getOption("max.print") -- omitted 15 rows ]