Learn R Programming

mlmhelpr (version 0.1.1)

r2_cor: 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)

Value

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

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.

References

peugh2010mlmhelpr

singer2003mlmhelpr

Examples

Run this code

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)

Run the code above in your browser using DataLab