pseudo_r2: Pseudo R-Square for Logistic Regression Models

Description Usage Arguments Value Examples

View source: R/pseudo_r2.r

Description

This functions computes several types of Pseudo-R-Squares from one or several logistic regression models obtained from glm, polr, or multinom.

Usage

1
pseudo_r2(..., type = c("McFadden", "Nagelkerke", "CoxSnell"), digits = 2)

Arguments

...

one or several objects of type glm, polr, or multinom.

type

character, one or several out of "McFadden", "Nagelkerke", "CoxSnell".

digits

how many digits should be printed?

Value

A table with all Pseudo-R-Squares.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Simulate data
set.seed(666)
x1 = rnorm(1000)           # some continuous variables 
x2 = rnorm(1000)
z = 1 + 2*x1 + 3*x2        # linear combination with a bias
pr = 1/(1+exp(-z))         # pass through an inv-logit function
y = rbinom(1000,1,pr)      # bernoulli response variable
d = data.frame(y=y,x1=x1,x2=x2)

# Estimate models
m1 <- glm(y~x1, data=d, family="binomial")
m2 <- glm(y~x1+x2, data=d, family="binomial")

# Run function
pseudo_r2(m1, m2, digits = 3)

masurp/pmstats documentation built on Oct. 6, 2020, 9:24 p.m.