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_patrons.xls <-read_excel("library_patrons.xls")
library_example<-library_patrons.xls %>% select(PostalCode,`AVG HH INCOME`,`EDUCATION BA OR HIGHER`) %>% arrange(-PostalCode,`AVG HH INCOME`,`EDUCATION BA OR HIGHER`)
library_example
## # A tibble: 88 × 3
## PostalCode `AVG HH INCOME` `EDUCATION BA OR HIGHER`
## <dbl> <dbl> <dbl>
## 1 78266 146792 48.4
## 2 78265 28500 29
## 3 78264 54409 14
## 4 78263 70833 20.5
## 5 78262 28500 29.4
## 6 78261 102163 55.8
## 7 78260 109424 51.7
## 8 78259 98266 55
## 9 78258 106036 62.3
## 10 78257 115560 65.5
## # ℹ 78 more rows
cor(library_example)
## PostalCode AVG HH INCOME EDUCATION BA OR HIGHER
## PostalCode 1.0000000 0.1103646 0.1840783
## AVG HH INCOME 0.1103646 1.0000000 0.7196605
## EDUCATION BA OR HIGHER 0.1840783 0.7196605 1.0000000
pairs(~ PostalCode + `AVG HH INCOME` + `EDUCATION BA OR HIGHER`, data = library_example)
cor.test(library_example$`EDUCATION BA OR HIGHER`, library_example$`AVG HH INCOME`, method = "kendall")
##
## Kendall's rank correlation tau
##
## data: library_example$`EDUCATION BA OR HIGHER` and library_example$`AVG HH INCOME`
## z = 6.438, p-value = 1.211e-10
## alternative hypothesis: true tau is not equal to 0
## sample estimates:
## tau
## 0.4745713
Used the Kendall Tau correlation method, due to “ties” in the selected data and the sample size. According to the Kendall correlation model this shows a strong correlation at .4745. This shows a strong correlation of residents in Bexar County that hold an education of a BA or Higher will tend to have higher average household incomes.