Last data update: 2014.03.03

R: Display confusion or classification matrix following logistic...
confusion_statR Documentation

Display confusion or classification matrix following logistic regression using glm with binomial family.

Description

Provides a confusion matrix of classification statistics following logistic regression.

Usage

confusion_stat(pred=pred,obs=obs)

Arguments

pred

Predicted values

obs

Observed values

Format

x

The function has two arguments: predicted values, response values

Value

confusion matrix

Note

confusion_stat() must be loaded into memory in order to be effectve. As a function in LOGIT, it is immediately available to a user.

Author(s)

Rafael de Souza, ELTE University, and Joseph M. Hilbe, Arizona State University

References

Hilbe, Joseph M. (2015), Practical Guide to Logistic Regression, Chapman & Hall/CRC.

Hilbe, Joseph M. (2009), Logistic Regression Models, Chapman & Hall/CRC.

See Also

glm

Examples

library(MASS)
library(LOGIT)
data(R84)
R84$cage <- R84$age - mean(R84$age)
R84$cdoc <- R84$docvis - mean(R84$docvis)
mylogit <- glm(outwork ~ cdoc + female + kids + cage + factor(edlevel),
family=binomial, data=R84)
mu <- predict(mylogit, type="response")
cutpoint<-ROCtest(mylogit, fold=10, type="Sensitivity")$cut
mu[mu>=cutpoint]<-1
mu[mu<cutpoint]<-0
confusion_stat(mu, R84$outwork)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(LOGIT)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/LOGIT/confusion_stat.Rd_%03d_medium.png", width=480, height=480)
> ### Name: confusion_stat
> ### Title: Display confusion or classification matrix following logistic
> ###   regression using glm with binomial family.
> ### Aliases: confusion_stat
> ### Keywords: models
> 
> ### ** Examples
> 
> library(MASS)
> library(LOGIT)
> data(R84)
> R84$cage <- R84$age - mean(R84$age)
> R84$cdoc <- R84$docvis - mean(R84$docvis)
> mylogit <- glm(outwork ~ cdoc + female + kids + cage + factor(edlevel),
+ family=binomial, data=R84)
> mu <- predict(mylogit, type="response")
> cutpoint<-ROCtest(mylogit, fold=10, type="Sensitivity")$cut
> mu[mu>=cutpoint]<-1
> mu[mu<cutpoint]<-0
> confusion_stat(mu, R84$outwork)
$matrix
     obs    0    1  Sum
pred                   
0        1812  298 2110
1         642 1122 1764
Sum      2454 1420 3874

$statistics
   Accuracy Sensitivity Specificity 
  0.7573567   0.7383863   0.7901408 

> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>