library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.3 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)
library(pastecs)
##
## Attaching package: 'pastecs'
##
## The following objects are masked from 'package:dplyr':
##
## first, last
##
## The following object is masked from 'package:tidyr':
##
## extract
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
##
## The following object is masked from 'package:dplyr':
##
## recode
##
## The following object is masked from 'package:purrr':
##
## some
Cities <- read_xlsx("FiSC-Full-Dataset-2023-Update.xlsx")
City_V <- Cities %>% select(educ_elem_sec_city
,taxes_city,public_welfare_city,public_safety_city
) %>% arrange(-educ_elem_sec_city
,taxes_city,public_welfare_city,public_safety_city
)
City_V
## # A tibble: 10,246 × 4
## educ_elem_sec_city taxes_city public_welfare_city public_safety_city
## <dbl> <dbl> <dbl> <dbl>
## 1 5981. 2624 185. 883.
## 2 5911. 731 0 893.
## 3 5838. 723. 0 884.
## 4 5760. 1501. 0 1106.
## 5 5712. 15127. 8444. 2339.
## 6 5655. 15930. 8267. 2313.
## 7 5602. 1316. 0 1109
## 8 5500. 1271. 4.31 784.
## 9 5427. 3066. 162. 1030.
## 10 5288. 2805. 156. 783.
## # ℹ 10,236 more rows
cor(City_V)
## educ_elem_sec_city taxes_city public_welfare_city
## educ_elem_sec_city 1.0000000 0.5159397 0.3087581
## taxes_city 0.5159397 1.0000000 0.7705184
## public_welfare_city 0.3087581 0.7705184 1.0000000
## public_safety_city 0.2803620 0.7185545 0.4596637
## public_safety_city
## educ_elem_sec_city 0.2803620
## taxes_city 0.7185545
## public_welfare_city 0.4596637
## public_safety_city 1.0000000
cor.test(City_V$taxes_city,City_V$public_welfare_city,method="kendall")
##
## Kendall's rank correlation tau
##
## data: City_V$taxes_city and City_V$public_welfare_city
## z = 40.355, p-value < 2.2e-16
## alternative hypothesis: true tau is not equal to 0
## sample estimates:
## tau
## 0.2944772
The Kendall’s Tau test demonstrates that the relationship between city tax revenue and city public welfare spending is statistically significant as the p-value is close to zero, but the actual correlation is moderately weak and positive. The reason why I used Kendall’s Tau is due to a high number of ties in the values (primarily since many municipalities spend zero dollars on public welfare funding) and because the distribution of the abnormal distribution of the values.
hist(City_V$taxes_city)
hist(City_V$public_welfare_city)
Both set of variables are heavily right skewed, in particular when it
comes to public welfare
note: I attempted to use the Shapiro-Wilk normality test to demonstrate the abnormality of the data, but it exceeded the observation limit