r2_cor {mlmhelpr}R Documentation

Pseudo R-squared: Squared correlation between predicted and observed values

Description

The r2_cor function estimates a pseudo R-squared by correlating predicted \hat{Y} values and observed Y values. This pseudo R-squared is similar to the R^2 used in OLS regression. It indicates amount of variation in the outcome that is explained by the model (Peugh, 2010; Singer & Willett, 2003, p. 36).

Usage

r2_cor(x, verbose = FALSE)

Arguments

x

A model produced using the lme4::lmer() function. This is an object of class merMod and subclass lmerMod.

verbose

If true, prints an explanatory message, "The squared correlation between predicted and observed values is...". If false (default), returns a value.

Value

If verbose == TRUE, a console message. If verbose == FALSE (default), a numeric value.

References

Peugh JL (2010). “A Practical Guide to Multilevel Modeling.” Journal of School Psychology, 48(1), 85–112. ISSN 00224405, doi:10.1016/j.jsp.2009.09.002.

Singer JD, Willett JB (2003). Applied Longitudinal Data Analysis: Modeling Change and Event Occurrence. Oxford University Press. ISBN 978-0-19-515296-8.

Examples


fit <- lme4::lmer(mathach ~ 1 + ses + catholic + (1|id),
data=hsb, REML=TRUE)

# returns a numeric value
r2_cor(fit)

# returns a console message with the r2 value
r2_cor(fit, verbose = TRUE)

[Package mlmhelpr version 0.1.1 Index]