2
$\begingroup$

I have a dataset with election results and crime rates per city. For each variable I have an absolute value (i.e. Total votes, Total crimes) and a relative value (i.e. Percentage shares of votes).

I want to calculate the correlation coefficient for some variables, but in the process I had a question about what value I need to use, if relative values or absolute values.

First I calculated z score for absolute values and then I calculated the correlation using excel. I also used pandas.DataFrame.corr() and pearsonr from scipy.stats.stats in python, in order to corroborate results.

For example, if I use absolute values I will get a positive correlation between candidate 1 and candidate 2.

x = df['Abs Cand 1'].tolist()
y = df['Abs Cand 2'].tolist()

print (pearsonr(x,y))
(0.95209664861187004, 0.0)

However, if I use relative ones I will get a negative correlation:

x = df['Rel Cand 1'].tolist()
y = df['Rel Cand 2'].tolist()

print (pearsonr(x,y))
(-0.99704737036262991, 0.0)

I was confused when I saw both results, and now I need some orientation to understand those differences.

Thanks in advance!

$\endgroup$
  • $\begingroup$ are candidate1 and candidate2 the votes for each candidate? in this case the absolute values are probably positively correlated because votes simply increase for both candidates with the size of the city and relative values are negatively correlated because candidate1 = 100%-candidate2. wouldn't you want to know the correlation between crime rates and votes for one of the candidates? $\endgroup$ – oW_ Oct 5 '16 at 19:08
  • $\begingroup$ @oW_ actually thats the main idea. crime rates vs votes, but I got stuck when I saw those differences. For example, using crime rates and votes, which value could be the best? $\endgroup$ – estebanpdl Oct 5 '16 at 19:33
  • 1
    $\begingroup$ turning values into percentages is simply multiplying the values with a scalar. that should not change the correlation coefficient. $\endgroup$ – oW_ Oct 5 '16 at 19:44
  • $\begingroup$ That makes sense. Thanks, @oW_ . So, in order to get a correlation coefficient for different elections, relative values would be a better choice, since absolute values are related with size of the city. this would be right? $\endgroup$ – estebanpdl Oct 5 '16 at 20:22
2
$\begingroup$

In general, the correlation coefficient is "invariant to separate changes in location and scale in the two variables". In particular, you can mix relative with absolute values.

However, that only works if you scale the variables globally. You can't scale every individual data point (here on a city level). If this was a county wide election, you could scale the city values by the county population.

But it sounds like your crime rates are on a per city level. In this case you should scale the votes on a city level as well to make them comparable. This will change the correlation coefficient and give a different result than with absolute values. I think using percentages is more intuitive in your case.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.