Generate data for brms models to be passed to Stan.
Arguments
- object
An object of class
formula,brmsformula, ormvbrmsformula(or one that can be coerced to that classes): A symbolic description of the model to be fitted. The details of model specification are explained inbrmsformula.- data
An object of class
data.frame(or one that can be coerced to that class) containing data of all variables used in the model.- family
A description of the response distribution and link function to be used in the model. This can be a family function, a call to a family function or a character string naming the family. Every family function has a
linkargument allowing to specify the link function to be applied on the response variable. If not specified, default links are used. For details of supported families seebrmsfamily. By default, a lineargaussianmodel is applied. In multivariate models,familymight also be a list of families.- prior
One or more
brmspriorobjects created byset_prioror related functions and combined using thecmethod or the+operator. See alsodefault_priorfor more help.- autocor
(Deprecated) An optional
cor_brmsobject describing the correlation structure within the response variable (i.e., the 'autocorrelation'). See the documentation ofcor_brmsfor a description of the available correlation structures. Defaults toNULL, corresponding to no correlations. In multivariate models,autocormight also be a list of autocorrelation structures. It is now recommend to specify autocorrelation terms directly withinformula. Seebrmsformulafor more details.- data2
A named
listof objects containing data, which cannot be passed via argumentdata. Required for some objects used in autocorrelation structures to specify dependency structures as well as for within-group covariance matrices.- cov_ranef
(Deprecated) A list of matrices that are proportional to the (within) covariance structure of the group-level effects. The names of the matrices should correspond to columns in
datathat are used as grouping factors. All levels of the grouping factor should appear as rownames of the corresponding matrix. This argument can be used, among others to model pedigrees and phylogenetic effects. It is now recommended to specify those matrices in the formula interface using thegrand related functions. Seevignette("brms_phylogenetics")for more details.- sample_prior
Indicate if draws from priors should be drawn additionally to the posterior draws. Options are
"no"(the default),"yes", and"only". Among others, these draws can be used to calculate Bayes factors for point hypotheses viahypothesis. Please note that improper priors are not sampled, including the default improper priors used bybrm. Seeset_prioron how to set (proper) priors. Please also note that prior draws for the overall intercept are not obtained by default for technical reasons. Seebrmsformulahow to obtain prior draws for the intercept. Ifsample_prioris set to"only", draws are drawn solely from the priors ignoring the likelihood, which allows among others to generate draws from the prior predictive distribution. In this case, all parameters must have proper priors.- stanvars
An optional
stanvarsobject generated by functionstanvarto define additional variables for use in Stan's program blocks.- threads
Number of threads to use in within-chain parallelization. For more control over the threading process,
threadsmay also be abrmsthreadsobject created bythreading. Within-chain parallelization is experimental! We recommend its use only if you are experienced with Stan'sreduce_sumfunction and have a slow running model that cannot be sped up by any other means. Can be set globally for the current R session via the"brms.threads"option (seeoptions).- knots
Optional list containing user specified knot values to be used for basis construction of smoothing terms. See
gammfor more details.- drop_unused_levels
Should unused factors levels in the data be dropped? Defaults to
TRUE.- ...
Other arguments for internal use.
Examples
sdata1 <- standata(rating ~ treat + period + carry + (1|subject),
data = inhaler, family = "cumulative")
str(sdata1)
#> List of 13
#> $ N : int 572
#> $ Y : num [1:572(1d)] 1 1 1 1 1 1 1 1 1 1 ...
#> $ nthres : int 3
#> $ K : int 3
#> $ Kc : num 3
#> $ X : num [1:572, 1:3] 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...
#> ..- attr(*, "dimnames")=List of 2
#> .. ..$ : chr [1:572] "1" "2" "3" "4" ...
#> .. ..$ : chr [1:3] "treat" "period" "carry"
#> $ Z_1_1 : num [1:572(1d)] 1 1 1 1 1 1 1 1 1 1 ...
#> ..- attr(*, "dimnames")=List of 1
#> .. ..$ : chr [1:572] "1" "2" "3" "4" ...
#> $ disc : num 1
#> $ J_1 : int [1:572(1d)] 1 2 3 4 5 6 7 8 9 10 ...
#> $ N_1 : int 286
#> $ M_1 : int 1
#> $ NC_1 : int 0
#> $ prior_only: int 0
#> - attr(*, "class")= chr [1:2] "standata" "list"
sdata2 <- standata(count ~ zAge + zBase * Trt + (1|patient),
data = epilepsy, family = "poisson")
str(sdata2)
#> List of 11
#> $ N : int 236
#> $ Y : num [1:236(1d)] 5 3 2 4 7 5 6 40 5 14 ...
#> $ K : int 5
#> $ Kc : num 4
#> $ X : num [1:236, 1:5] 1 1 1 1 1 1 1 1 1 1 ...
#> ..- attr(*, "dimnames")=List of 2
#> .. ..$ : chr [1:236] "1" "2" "3" "4" ...
#> .. ..$ : chr [1:5] "Intercept" "zAge" "zBase" "Trt1" ...
#> ..- attr(*, "assign")= int [1:5] 0 1 2 3 4
#> ..- attr(*, "contrasts")=List of 1
#> .. ..$ Trt: num [1:2, 1] 0 1
#> .. .. ..- attr(*, "dimnames")=List of 2
#> .. .. .. ..$ : chr [1:2] "0" "1"
#> .. .. .. ..$ : chr "1"
#> $ Z_1_1 : num [1:236(1d)] 1 1 1 1 1 1 1 1 1 1 ...
#> ..- attr(*, "dimnames")=List of 1
#> .. ..$ : chr [1:236] "1" "2" "3" "4" ...
#> $ J_1 : int [1:236(1d)] 1 2 3 4 5 6 7 8 9 10 ...
#> $ N_1 : int 59
#> $ M_1 : int 1
#> $ NC_1 : int 0
#> $ prior_only: int 0
#> - attr(*, "class")= chr [1:2] "standata" "list"