# GINI calculation R code

Description
R code to calculate GINI index

View again

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information
Category:

## Documents

Publish on:

Views: 2 | Pages: 2

Share
Transcript
setwd( c:/amit ) dataset1 <- modeling_data_22ndMarch2017_yes_signal_thinfile.csv   data1 <- read.csv(file = dataset1, header = TRUE,na.strings='NULL', sep = , ) filename <- Rank1 and Plots_Indifi_15Feb_2 dep_var <- decision groups <- 10 vars <- c( new_score_bureau_only )  library(Hmisc) library(R2HTML) fl <- paste(filename, .xls ,sep = ) rankNplot_sub <- function(temp1,groups,tag) { temp1\$buckets <- as.numeric(cut2(temp1[,2] ,g=groups)) df = data.frame(matrix(mat.or.vec(groups,7), groups, 7, dimnames=list(c(), c( Group , Mtestvar , Mlongbad , Min , Max , Nobs , nbad ))),stringsAsFactors=F) for (i in 1:groups) { subset <- temp1[which(temp1[,3] == i),] df\$Group[i] <- i df\$Mtestvar[i] <- mean(subset[,2]) df\$Mlongbad[i] <- mean(subset[,1]) df\$Min[i] <- min(subset[,2]) df\$Max[i] <- max(subset[,2]) df\$Nobs[i] <- nrow(subset) df\$nbad[i] <- sum(subset[,1]) } M = max(temp1\$buckets,na.rm=TRUE) df <- df[1:M,] par(mar = rep(2, 4)) p.plot <- plot(df\$Mtestvar,df\$Mlongbad) d.data <- df return(list(p.plot,d.data)) } for (j in 1:length(vars)) { ind_var <- vars[j] print( ind_var ) print(ind_var) svars <- c(dep_var,ind_var) temp1 <- data1[,svars] temp1\$buckets <- as.numeric(cut2(temp1[,2] ,g=groups)) M = max(temp1\$buckets,na.rm=TRUE) temp_min <- temp1[which(temp1\$buckets == 1),svars] temp_max <- temp1[which(temp1\$buckets == M),svars] title1 <- paste(ind_var, vs ,dep_var, sep= ) title2 <- paste( Min Bucket of ,ind_var, vs ,dep_var, sep= ) title3 <- paste( Max Bucket of ,ind_var, vs ,dep_var, sep= ) HTML.title(title1, HR=3 ,file=fl, append = TRUE ) d1 <- rankNplot_sub(temp1[,svars],groups, overall ) html.data.frame(d1[[2]],file=fl, append = TRUE ) HTML.title(title2, HR=3 ,file=fl, append = TRUE ) d2 <- rankNplot_sub(temp_min,groups, min ) html.data.frame(d2[[2]],file=fl, append = TRUE )   HTML.title(title3, HR=3 ,file=fl, append = TRUE ) d3 <- rankNplot_sub(temp_max,groups, max ) html.data.frame(d3[[2]],file=fl, append = TRUE ) } dep_var <- Bureau_thickness groups <- 20
Related Search
Similar documents

View more...