# Politician map 2015 from HS.fi voting machine data # by Juha Törmänen http://kirkas.info # # You can use this file to duplicate the analysis with # the R software suite and the 'psych' package. require(psych) # The voting machine data file needs to be in the current # working directory data <- read.csv('23821113ehdokasvastaukset-17-04-clari.csv') # These are the quantitative answer columns datadims <- 13:42 # Check estimate of data dimensionality # Note how the first two dimensions are very strong # If this wouldn't be true, 2D political mapping wouldn't be of much use! VSS.scree(data[,datadims]) # Perform factor analysis # Two dimensions, principal axis factoring, varimax rotation f <- fa(data[,datadims], nfactors=2, fm="pa", rotate="bentlerT") # Check that results are as expected - parties are separated # (party data is in column 4, colors are automatic and # don't correspond to actual party colors) plot(f$scores, col=data[,4]) # Collect participant data and scores results <- data.frame(id=data[,1], name=data[,2], area=data[,3], party=data[,4], partytext=data[,5], age=data[,6], gender=data[,7], elected=data[,8], www=data[,9], scorex=f$scores[,1], scorey=f$scores[,2]) # Write results write.csv(results, file='votingmachine.csv')