Chi-Square in R on by State Politics (Red/Blue) and Income (Higher/Lower)

This is a significant result, but instead of a logistic regression looking at the income average per state and the likelihood of being a Democratic state, it uses Chi-Square. Interpreting this is pretty straightforward, in that liberal states typically have cities and people that earn more money. When using adjusted incomes, by cost of living, this difference disappears.

Example Code

 # R - Chi Square  
 rm(list = ls())  
 stateData <- read.table("CostByStateAndSalary.csv", header = TRUE, sep = ",")  
 # Create vectors   
 affluence.median <- median(stateData$Y2014, na.rm = TRUE)  
 affluence.v <- ifelse(stateData$Y2014 > affluence.median, 1, 0)  
 liberal.v <- stateData$Liberal  
 # Solve  
 pol.Data = table(liberal.v, affluence.v)  
 result <- chisq.test(pol.Data)  

Example Results

 Pearson's Chi-squared test with Yates' continuity correction  
 data: pol.Data  
 X-squared = 12.672, df = 1, p-value = 0.0003711  
 > print(pol.Data)  
 liberal.v     0  1  
            0  22 7  
            1  4 16  

Sample Data

Popular posts from this blog

Decision Tree in R, with Graphs: Predicting State Politics from Big Five Traits

Logistic Regression in R on State Voting in National Elections and Income