Fixed effect + random effects.

extract_random_coefs(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  component = NULL,
  ...
)

# S3 method for merMod
extract_random_coefs(model, re = NULL, ci_level = 0.95, digits = 3, ...)

# S3 method for glmmTMB
extract_random_coefs(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  component = "cond",
  ...
)

# S3 method for lme
extract_random_coefs(model, re = NULL, ci_level = NULL, digits = 3, ...)

# S3 method for brmsfit
extract_random_coefs(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  component = NULL,
  ...
)

# S3 method for stanreg
extract_random_coefs(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  component = NULL,
  ...
)

# S3 method for gam
extract_random_coefs(model, re = NULL, ci_level = 0.95, digits = 3, ...)

extract_coef(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  component = NULL,
  ...
)

extract_random_coefficients(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  component = NULL,
  ...
)

Arguments

model

A merMod, nlme, brms, or glmmTMB object

re

The name of the grouping variable for the random effects.

ci_level

Where possible, confidence level < 1, typically above 0.90. A value of 0 will not report it. Default is .95. Not applicable to nlme objects.

digits

Rounding. Default is 3.

component

For glmmTMB objects, which of the two components 'cond' or 'zi' to select. Default is 'cond'. For brmsfit objects, this can filter results to a certain part of the output, e.g. 'sigma' or 'zi' of distributional models, or a specific outcome of a multivariate model. In this case component is a regular expression that ends the name of the parameters of the output (e.g. '__component').

...

Other arguments specific to the method. Unused at present.

Value

A data frame of the random coefficients and their standard errors.

Details

Returns a data frame with random coefficients, a.k.a. random intercepts and random slopes, and their standard errors. Note that the standard errors assume independence of the conditional variance and the fixed-effects variance, thus the standard errors are the sum of variances for the respective fixed and random effects. See Bolker's demo here and additional discussion at the GLMM FAQ. As noted there, this assumption may not be appropriate, and if you are really interested in an accurate uncertainty estimate you should probably use brms.

For more complex models that include multiple outcomes/categories or have other anomalies, this function likely will not work at present, even if the underlying extract_fixed_effects and extract_random_effects do, as naming conventions are not consistent enough to deal with this without a lot of tedium that still may not satisfy every situation. I will possibly be able to update this in the future.

The nlme package only provides the coefficients no estimated variance, so this function doesn't add to what you get from basic functionality for those models. In addition, nlme adds all random effects to the fixed effects, whereas lme4 and others only add the effects requested.

extract_coef and extract_random_coefficients are aliases.

See also

Examples

library(lme4) library(mixedup) lmer_1 <- lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy) extract_random_coefs(lmer_1, re = 'Subject')
#> # A tibble: 18 x 7 #> group_var effect group value se lower_2.5 upper_97.5 #> <chr> <chr> <fct> <dbl> <dbl> <dbl> <dbl> #> 1 Subject Intercept 308 292. 13.6 266. 319. #> 2 Subject Intercept 309 174. 13.6 147. 200. #> 3 Subject Intercept 310 188. 13.6 162. 215. #> 4 Subject Intercept 330 256. 13.6 229. 282. #> 5 Subject Intercept 331 262. 13.6 235. 288. #> 6 Subject Intercept 332 260. 13.6 233. 286. #> 7 Subject Intercept 333 268. 13.6 241. 295. #> 8 Subject Intercept 334 248. 13.6 222. 275. #> 9 Subject Intercept 335 206. 13.6 179. 233. #> 10 Subject Intercept 337 324. 13.6 297. 350. #> 11 Subject Intercept 349 230. 13.6 204. 257. #> 12 Subject Intercept 350 266. 13.6 239. 292. #> 13 Subject Intercept 351 244. 13.6 217. 270. #> 14 Subject Intercept 352 288. 13.6 261. 314. #> 15 Subject Intercept 369 258. 13.6 232. 285. #> 16 Subject Intercept 370 245. 13.6 218. 272. #> 17 Subject Intercept 371 248. 13.6 221. 275. #> 18 Subject Intercept 372 270. 13.6 243. 296.
library(glmmTMB) tmb_1 <- glmmTMB(Reaction ~ Days + (1 | Subject), data = sleepstudy)
#> Warning: 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
#> Warning: 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
#> Warning: 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
extract_random_coefs(tmb_1, re = 'Subject')
#> # A tibble: 18 x 7 #> group_var effect group value se lower_2.5 upper_97.5 #> <chr> <chr> <fct> <dbl> <dbl> <dbl> <dbl> #> 1 Subject Intercept 308 292. 15.7 261. 323. #> 2 Subject Intercept 309 174. 15.8 143. 205. #> 3 Subject Intercept 310 189. 15.8 158. 219. #> 4 Subject Intercept 330 256. 15.7 225. 287. #> 5 Subject Intercept 331 262. 15.7 231. 292. #> 6 Subject Intercept 332 260. 15.7 229. 290. #> 7 Subject Intercept 333 268. 15.7 237. 299. #> 8 Subject Intercept 334 248. 15.7 218. 279. #> 9 Subject Intercept 335 206. 15.7 175. 237. #> 10 Subject Intercept 337 323. 15.8 292. 354. #> 11 Subject Intercept 349 230. 15.7 200. 261. #> 12 Subject Intercept 350 265. 15.7 235. 296. #> 13 Subject Intercept 351 244. 15.7 213. 274. #> 14 Subject Intercept 352 288. 15.7 257. 318. #> 15 Subject Intercept 369 258. 15.7 228. 289. #> 16 Subject Intercept 370 245. 15.7 214. 276. #> 17 Subject Intercept 371 248. 15.7 217. 279. #> 18 Subject Intercept 372 269. 15.7 239. 300.