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?