Learn R Programming

rcompanion (version 2.4.36)

countRSquare: Count pseudo r-squared for logistic and other binary outcome models

Description

Produces the count pseudo r-squared measure for models with a binary outcome.

Usage

countRSquare(
  fit,
  digits = 3,
  suppressWarnings = TRUE,
  plotit = FALSE,
  jitter = FALSE,
  pch = 1,
  ...
)

Value

A list including a description of the submitted model, a data frame with the pseudo r-squared results, and a confusion matrix of the results.

Arguments

fit

The fitted model object for which to determine pseudo r-squared. glm and glmmTMB are supported. Others may work as well.

digits

The number of digits in the outputted values.

suppressWarnings

If TRUE, suppresses warning messages.

plotit

If TRUE, produces a simple plot of actual vs. predicted values.

jitter

If TRUE, jitters the "actual" values in the plot.

pch

Passed to plot.

...

Additional arguments.

Author

Salvatore Mangiafico, mangiafico@njaes.rutgers.edu

Details

The count pseudo r-squared is simply the number of correctly predicted observations divided the total number of observations.

This version is appropriate for models with a binary outcome.

The adjusted value deducts the count of the most frequent outcome from both the numerator and the denominator.

It is recommended that the model is fit on data in long format. That is, that the weight option not be used in the model.

The function makes no provisions for NA values. It is recommended that NA values be removed before the determination of the model.

References

https://stats.oarc.ucla.edu/other/mult-pkg/faq/general/faq-what-are-pseudo-r-squareds/, https://rcompanion.org/handbook/H_08.html, https://rcompanion.org/rcompanion/e_06.html

See Also

nagelkerke, efronRSquared, accuracy

Examples

Run this code
data(AndersonBias)

### Covert data to long format

Long = AndersonBias[rep(row.names(AndersonBias), AndersonBias$Count),
                    c("Result", "County", "Gender")]
rownames(Long) = seq(1:nrow(Long))
str(Long)

### Fit model and determine count r-square

model = glm(Result ~ County + Gender + County:Gender,
            data = Long,
            family = binomial())

countRSquare(model)

Run the code above in your browser using DataLab