Learn R Programming

MDMA (version 2.0.0)

f2Local: Local \(f^2\)

Description

Calculate local \(f^2\) for (generalized) linear (mixed) models

[Experimental]

Usage

f2Local(object, method, ...)

# S3 method for lm f2Local(object, method = "r.squared", ...)

# S3 method for glm f2Local(object, method = "r2", ...)

# S3 method for vglm f2Local(object, method = "mcfadden", ...)

# S3 method for glmmTMB f2Local(object, method = "nakagawa", type = "marginal", ...)

Value

f2Local returns a list containing \(f^2\) values for every parameter in a model. For the glmmTMB

class, a list of all reduced models is returned as well. In a future version, this will be available for other classes as well.

Arguments

object

a model object (currently supported: lm, glm, vglm).

method

method for calculation of \(R^2\), which is needed for the calculation of \(f^2\). See Details.

...

currently not used

type

indicate whether the marginal (fixed effects only) or the conditional (fixed + random effects) \(R^2\) should be used. Default value is marginal, using conditional might be considered ambiguous.

Methods (by class)

  • f2Local(lm): Method for lm object

  • f2Local(glm): Method for glm object

  • f2Local(vglm): Method for vglm object

  • f2Local(glmmTMB): Method for glmmTMB object

Author

Mathijs Deen

Details

The following methods can be specified:

  • lm objects: r.squared and adj.r.squared as extracted from the lm object.

  • glm objects: mcfadden, nagelkerke, coxsnell, tjur and efron, as implemented in the performance package.

  • vglm objects: mcfadden, nagelkerke, coxsnell, tjur and efron, as implemented in the R2.vglm function.

  • glmmTMB objects: nakagawa, as implemented in the performance package. It can also be specified whether the marginal or the conditional \(R^2\) should be used, however only the marginal \(R^2\) would make sense.

Note that for multinomial models, using method="efron" gives questionable with glm objects and is not possible for vglm objects. For glm objects, method=coxsnell cannot be used when the response is not binary.

Examples

Run this code
# linear model
model1 <- lm(mpg ~ cyl + wt*drat, data = mtcars)
f2Local(model1)

# generalized linear model (glm)
model2 <- glm(vs ~  cyl*wt + mpg, data = mtcars, family = "binomial")
f2Local(model2, method = "coxsnell")

# generalized linear model (vglm)
if(require(VGAM)){
  pneumo <- transform(pneumo, let = log(exposure.time))
  model3 <- vglm(cbind(normal, mild, severe) ~ let, multinomial, pneumo)
  f2Local(model3)
}
# generalized linear mixed model
if(require(ClusterBootstrap) & require(glmmTMB)){
  model4 <- glmmTMB(pos ~ treat*time + (1 + time | id), data = medication)
  f2Local(model4)
}

Run the code above in your browser using DataLab