1
$\begingroup$

I have a dataset as follows:

DT <- structure(list(Income = c(72.5637996502787, 96.1085035433461, 
92.7967726182757, 68.5725226962365, 39.847663413856, 50.5181067098064, 
21.2527722688882, 65.0901036096242, 77.2172733657477), upto20tax = c(4, 
4, 4, 4, 4, 4, 4, 4, 4), over20tax = c(18.3973298775976, 26.6379762401711, 
25.4788704163965, 17.0003829436828, 6.9466821948496, 10.6813373484322, 
0.438470294110858, 15.7815362633685, 20.0260456780117), Tax = c(22.3973298775976, 
30.6379762401711, 29.4788704163965, 21.0003829436828, 10.9466821948496, 
14.6813373484322, 4.43847029411086, 19.7815362633685, 24.0260456780117
), Educ = c(3, 4, 4, 2, 2, 3, 1, 3, 3)), row.names = c(NA, -9L
), class = c("tbl_df", "tbl", "data.frame"))

I want to see if Tax is correlated with education (Educ), so I want to check for the correlation between tax and education. However, the amount of taxation is obviously related to Income as well. So I want to get the effect of Income out of the equation. I thought I could do this by first controlling for income by regressing Tax on Income, adding the residuals as a variable, and then checking the correlation of Educ with the residual.

m1 <- lm(Tax~Income, data=DT)  #Create a linear model
DT <- DT %>% add_residuals(m1, var="resid")
correl <- cor(DT$resid, DT$Educ)

Would this make any sense?

$\endgroup$

1 Answer 1

2
$\begingroup$

You have perfect correlation between Tax and Income (as expected if we assume income actually is only wage and tax is only wage tax). Any residuals result from computers using floating point numbers with a limited precision.

residuals(m1)
#            1             2             3             4             5             6             7             8             9 
# 4.865437e-14 -4.711937e-14 -1.097692e-17  2.053093e-14  5.330439e-17 -4.459489e-14 -8.235134e-15  2.929943e-14  1.422336e-15 

sum(residuals(m1)^2)
#[1] 7.926006e-27

help(".Machine")
.Machine$double.eps
#[1] 2.220446e-16

I suggest you focus on correlation between income and education instead:

cor.test(DT$Educ, DT$Income)
#   Pearson's product-moment correlation
#
#data:  DT$Educ and DT$Income
#t = 5.1284, df = 7, p-value = 0.001356
#alternative hypothesis: true correlation is not equal to 0
#95 percent confidence interval:
# 0.5480318 0.9764919
#sample estimates:
#      cor 
#0.8887018 
$\endgroup$
5
  • $\begingroup$ Thank you for your answer. I'm a bit confused. I made the data with a 0.2 tax over the first 20 and a 0.35 thereafter, especially to avoid an exact proportional relation. This does not work apparently, because they still always move in the same direction? $\endgroup$
    – Tom
    Commented Nov 10, 2020 at 14:36
  • $\begingroup$ As an additional comment (which you probably deduced from the first comment), the data I presented is completely arbitrary.. What I am interested in is whether what I am doing makes sense (in the situation where there is no perfect correlation). $\endgroup$
    – Tom
    Commented Nov 10, 2020 at 14:38
  • 1
    $\begingroup$ @TomKisters In that case, your approach makes some sense. I would probably just use a model like Tax ~ Income * Education though. That would be more informative. $\endgroup$
    – Roland
    Commented Nov 10, 2020 at 15:33
  • $\begingroup$ However, usually the relationship between tax and income is well understood and one should focus on the relationship between income and education instead. $\endgroup$
    – Roland
    Commented Nov 10, 2020 at 15:35
  • $\begingroup$ Thank you very much! I will come up with a better example next time, that makes more sense for the question at hand. $\endgroup$
    – Tom
    Commented Nov 10, 2020 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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