@@ -178,24 +178,33 @@ get_modelmatrix.svysurvreg <- get_modelmatrix.svyglm
178178
179179# ' @export
180180get_modelmatrix.brmsfit <- function (x , ... ) {
181- formula_rhs <- safe_deparse(find_formula(x , verbose = FALSE )$ conditional [[3 ]])
181+ conditional_formula <- find_formula(x , verbose = FALSE )$ conditional
182+ formula_rhs <- safe_deparse(conditional_formula [[3 ]])
183+ model_data <- get_data(x , verbose = FALSE )
182184 # exception: for null-models, we need different handling, else `reformulate()`
183185 # will not work.
184186 if (identical(formula_rhs , " 1" )) {
185- mm <- get_data(x , verbose = FALSE )
186- mm [[1 ]] <- 1
187- colnames(mm )[1 ] <- " (Intercept)"
188- as.matrix(mm [1 ])
187+ matrix (1 , nrow = nrow(model_data ), dimnames = list (NULL , " (Intercept)" ))
189188 } else {
190189 formula_rhs <- stats :: as.formula(paste0(" ~" , formula_rhs ))
190+ intercept <- has_intercept(x , verbose = FALSE )
191+ predictors <- setdiff(all.vars(formula_rhs ), " Intercept" )
191192 # the formula used in model.matrix() is not allowed to have special functions,
192193 # like brms::mo() and similar. Thus, we reformulate after using "all.vars()",
193194 # which will only keep the variable names.
194- .data_in_dots(
195- ... ,
196- object = stats :: reformulate(all.vars(formula_rhs )),
197- default_data = get_data(x , verbose = FALSE )
198- )
195+ if (! length(predictors )) {
196+ if (intercept ) {
197+ matrix (1 , nrow = nrow(model_data ), dimnames = list (NULL , " (Intercept)" ))
198+ } else {
199+ matrix (nrow = nrow(model_data ), ncol = 0 )
200+ }
201+ } else {
202+ .data_in_dots(
203+ ... ,
204+ object = stats :: reformulate(predictors , intercept = intercept ),
205+ default_data = model_data
206+ )
207+ }
199208 }
200209}
201210
0 commit comments