Skip to content

Instantly share code, notes, and snippets.

This post provides an overview of performing diagnostic and performance evaluation on logistic regression models in R. After training a statistical model, it’s important to understand how well that model did in regards to it’s accuracy and predictive power. The following content will provide the background and theory to ensure that the right technique are being utilized for evaluating logistic regression models in R.
Logistic Regression Example
We will use the GermanCredit dataset in the caret package for this example. It contains 62 characteristics and 1000 observations, with a target variable (Class) that is allready defined. The response variable is coded 0 for bad consumer and 1 for good. It’s always recommended that one looks at the coding of the response variable to ensure that it’s a factor variable that’s coded accurately with a 0/1 scheme or two factor levels in the right order. The first step is to partition the data into training and testing sets.
```
library(caret)
data(GermanCredit)
Train <- cr
#' Convert a list of vectors to a data frame.
#'
#' This function will convert a list of vectors to a data frame. This function
#' will handle three different types of lists of vectors. First, if all the elements
#' in the list are named vectors, the resulting data frame will have have a number
#' of columns equal to the number of unique names across all vectors. In cases
#' where some vectors do not have names in other vectors, those values will be
#' filled with \code{NA}.
#'
#' The second case is when all the vectors are of the same length. In this case,
@albiondervishi
albiondervishi / lsa_hack.r
Created November 2, 2015 04:03 — forked from swayson/lsa_hack.r
Analyze Text Similarity with R: Latent Semantic Analysis and Multidimentional Scaling
# script stolen from http://goo.gl/YbQyAQ
# install.packages("tm")
# install.packages("ggplot2")
# install.packages("lsa")
# install.packages("scatterplot3d")
#install.packages("SnowballC")
#if !(require('SnowballC')) then install.packages("SnowballC")
library(tm)
library(ggplot2)
@albiondervishi
albiondervishi / Programming Assignment 2:
Created September 21, 2014 19:32
Programming Assignment 2: Lexical Scoping
makeCacheMatrix <- function( m = matrix() ) {
## Initialize the inverse property
i <- NULL
set <- function( matrix ) {
m <<- matrix
i <<- NULL
}
## Method the get the matrix
get <- function() {
makeVector <- function(x = numeric()) {
+ m <- NULL
+ set <- function(y) {
+ x <<- y
+ m <<- NULL
+ }
+ get <- function() x
+ setmean <- function(mean) m <<- mean
+ getmean <- function() m
+ list(set = set, get = get,