library(readxl)
district <- read_excel("district.xls")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.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
obj2 <- district %>% select(DA0AT21R,DA0912DR21R)
obj2_cleaned <- obj2 %>% filter(!is.na(DA0AT21R)&(!is.na(DA0912DR21R))&(DA0912DR21R>0))
library(dplyr)
obj2_cleaned <- district %>% select(DA0AT21R,DA0912DR21R) %>% arrange
obj2_cleaned
## # A tibble: 1,207 × 2
## DA0AT21R DA0912DR21R
## <dbl> <dbl>
## 1 96.7 0
## 2 96 0.3
## 3 95.4 0.4
## 4 95.8 0
## 5 93.7 0
## 6 94.5 0
## 7 96.7 0
## 8 92.8 0.4
## 9 97.3 0.4
## 10 95.2 0.7
## # ℹ 1,197 more rows
cor(obj2_cleaned, use = "complete.obs")
## DA0AT21R DA0912DR21R
## DA0AT21R 1.0000000 -0.3991648
## DA0912DR21R -0.3991648 1.0000000
pairs(obj2_cleaned[, c("DA0AT21R", "DA0912DR21R")])

``` r
cor.test(obj2_cleaned$DA0AT21R,obj2_cleaned$DA0912DR21R,method="pearson")
##
## Pearson's product-moment correlation
##
## data: obj2_cleaned$DA0AT21R and obj2_cleaned$DA0912DR21R
## t = -14.393, df = 1093, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.447817 -0.348156
## sample estimates:
## cor
## -0.3991648
#There is a moderately strong negative correlation between the two variables.The P-value is extrememly small which contains evidence against the null hypothesis.