Returns the values the response variable(s) from a model object. If the model is a multivariate response model, a data frame with values from all response variables is returned.

get_response(x, select = NULL)

Arguments

x

A fitted model.

select

Optional name(s) of response variables for which to extract values. Can be used in case of regression models with multiple response variables.

Value

The values of the response variable, as vector, or a data frame if x has more than one defined response variable.

Examples

library(lme4) data(cbpp) data(mtcars) cbpp$trials <- cbpp$size - cbpp$incidence m <- glm(cbind(incidence, trials) ~ period, data = cbpp, family = binomial) head(get_response(m))
#> incidence trials #> 1 2 12 #> 2 3 9 #> 3 4 5 #> 4 0 5 #> 5 3 19 #> 6 1 17
get_response(m, select = "incidence")
#> [1] 2 3 4 0 3 1 1 8 2 0 2 2 0 2 0 5 0 0 1 3 0 0 1 8 1 #> [26] 3 0 12 2 0 0 0 1 1 0 2 0 5 3 1 2 1 0 0 1 2 0 0 11 0 #> [51] 0 0 1 1 1 0
m <- lm(mpg ~ wt + cyl + vs, data = mtcars) get_response(m)
#> [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4 #> [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7 #> [31] 15.0 21.4