brmsfit
Objectspredict
method.
This is because the measurement error is not incorporated.
The estimated means of both methods should, however, be very similar.## S3 method for class 'brmsfit':
fitted(object, newdata = NULL, re_formula = NULL,
scale = c("response", "linear"), allow_new_levels = FALSE,
subset = NULL, nsamples = NULL, summary = TRUE, probs = c(0.025,
0.975), ...)
brmsfit
NULL
(default), the orginal data of the model is used.NULL
(default), include all random effects;
if NA
, include no random effects."response"
or "linear"
.
If "response"
results are returned on the scale
of the response variable. If "linear"
fitted values are returned on the scale of the linear predictor.FALSE
).
Only relevant if newdata
is provided.NULL
(the default), all samples are used.NULL
(the default) all samples are used.
Ignored if subset
is not NULL
.TRUE
.quantile
function.
Only used if summary
is TRUE
.object
.
The output depends on the family:
If summary = TRUE
it is a N x E x C array
for categorical and ordinal models and a N x E matrix else.
If summary = FALSE
it is a S x N x C array
for categorical and ordinal models and a S x N matrix else.
N is the number of observations, S is the number of samples,
C is the number of categories, and E is equal to length(probs) + 2
.NA
values within factors in newdata
,
are interpreted as if all dummy variables of this factor are
zero. This allows, for instance, to make predictions of the grand mean
when using sum coding.
For models fitted with newdata with factors
in fixed or random effects. The predicted results are only valid
if all factor levels present in the initial
data are also defined and ordered correctly
for the factors in newdata
.
Grouping factors may contain fewer levels than in the
inital data without causing problems.
When using higher versions of brms ,
all factors are automatically checked
for correctness and amended if necessary.=>
## fit a model
fit <- brm(rating ~ treat + period + carry + (1|subject),
data = inhaler)
## extract fitted values
fitted_values <- fitted(fit)
head(fitted_values)
## plot fitted means against actual response
dat <- as.data.frame(cbind(Y = standata(fit)$Y, fitted_values))
ggplot(dat) + geom_point(aes(x = Estimate, y = Y))
Run the code above in your browser using DataLab