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)
County_Data <- read_excel("County Data.xlsx")
## New names:
## • `Unreliable` -> `Unreliable...4`
## • `95% CI - Low` -> `95% CI - Low...7`
## • `95% CI - High` -> `95% CI - High...8`
## • `National Z-Score` -> `National Z-Score...9`
## • `95% CI - Low` -> `95% CI - Low...39`
## • `95% CI - High` -> `95% CI - High...40`
## • `National Z-Score` -> `National Z-Score...41`
## • `Unreliable` -> `Unreliable...42`
## • `95% CI - Low` -> `95% CI - Low...44`
## • `95% CI - High` -> `95% CI - High...45`
## • `National Z-Score` -> `National Z-Score...46`
## • `95% CI - Low` -> `95% CI - Low...69`
## • `95% CI - High` -> `95% CI - High...70`
## • `National Z-Score` -> `National Z-Score...71`
## • `95% CI - Low` -> `95% CI - Low...73`
## • `95% CI - High` -> `95% CI - High...74`
## • `National Z-Score` -> `National Z-Score...75`
## • `National Z-Score` -> `National Z-Score...77`
## • `National Z-Score` -> `National Z-Score...84`
## • `National Z-Score` -> `National Z-Score...86`
## • `National Z-Score` -> `National Z-Score...90`
## • `National Z-Score` -> `National Z-Score...94`
## • `National Z-Score` -> `National Z-Score...98`
## • `National Z-Score` -> `National Z-Score...100`
## • `National Z-Score` -> `National Z-Score...107`
## • `95% CI - Low` -> `95% CI - Low...115`
## • `95% CI - High` -> `95% CI - High...116`
## • `National Z-Score` -> `National Z-Score...117`
## • `95% CI - Low` -> `95% CI - Low...119`
## • `95% CI - High` -> `95% CI - High...120`
## • `National Z-Score` -> `National Z-Score...130`
## • `95% CI - Low` -> `95% CI - Low...132`
## • `95% CI - High` -> `95% CI - High...133`
## • `National Z-Score` -> `National Z-Score...134`
## • `95% CI - Low` -> `95% CI - Low...152`
## • `95% CI - High` -> `95% CI - High...153`
## • `National Z-Score` -> `National Z-Score...154`
## • `National Z-Score` -> `National Z-Score...156`
## • `National Z-Score` -> `National Z-Score...158`
## • `95% CI - Low` -> `95% CI - Low...161`
## • `95% CI - High` -> `95% CI - High...162`
## • `National Z-Score` -> `National Z-Score...163`
## • `National Z-Score` -> `National Z-Score...165`
## • `Population` -> `Population...167`
## • `95% CI - Low` -> `95% CI - Low...169`
## • `95% CI - High` -> `95% CI - High...170`
## • `National Z-Score` -> `National Z-Score...171`
## • `Population` -> `Population...173`
## • `95% CI - Low` -> `95% CI - Low...175`
## • `95% CI - High` -> `95% CI - High...176`
## • `National Z-Score` -> `National Z-Score...177`
## • `National Z-Score` -> `National Z-Score...181`
## • `National Z-Score` -> `National Z-Score...185`
## • `95% CI - Low` -> `95% CI - Low...187`
## • `95% CI - High` -> `95% CI - High...188`
## • `National Z-Score` -> `National Z-Score...189`
## • `95% CI - Low` -> `95% CI - Low...197`
## • `95% CI - High` -> `95% CI - High...198`
## • `National Z-Score` -> `National Z-Score...199`
## • `National Z-Score` -> `National Z-Score...223`
## • `National Z-Score` -> `National Z-Score...225`
## • `National Z-Score` -> `National Z-Score...226`
## • `Health Group` -> `Health Group...227`
## • `Health Group Range` -> `Health Group Range...228`
## • `National Z-Score` -> `National Z-Score...229`
## • `Health Group` -> `Health Group...230`
## • `Health Group Range` -> `Health Group Range...231`
## • `95% CI - Low` -> `95% CI - Low...233`
## • `95% CI - High` -> `95% CI - High...234`
## • `# Deaths` -> `# Deaths...256`
## • `95% CI - Low` -> `95% CI - Low...258`
## • `95% CI - High` -> `95% CI - High...259`
## • `# Deaths` -> `# Deaths...281`
## • `95% CI - Low` -> `95% CI - Low...283`
## • `95% CI - High` -> `95% CI - High...284`
## • `# Deaths` -> `# Deaths...306`
## • `95% CI - Low` -> `95% CI - Low...308`
## • `95% CI - High` -> `95% CI - High...309`
## • `95% CI - Low` -> `95% CI - Low...332`
## • `95% CI - High` -> `95% CI - High...333`
## • `95% CI - Low` -> `95% CI - Low...335`
## • `95% CI - High` -> `95% CI - High...336`
## • `95% CI - Low` -> `95% CI - Low...340`
## • `95% CI - High` -> `95% CI - High...341`
## • `95% CI - Low` -> `95% CI - Low...343`
## • `95% CI - High` -> `95% CI - High...344`
## • `# Deaths` -> `# Deaths...345`
## • `95% CI - Low` -> `95% CI - Low...347`
## • `95% CI - High` -> `95% CI - High...348`
## • `95% CI - Low` -> `95% CI - Low...372`
## • `95% CI - High` -> `95% CI - High...373`
## • `95% CI - Low` -> `95% CI - Low...379`
## • `95% CI - High` -> `95% CI - High...380`
## • `95% CI - Low` -> `95% CI - Low...382`
## • `95% CI - High` -> `95% CI - High...383`
## • `95% CI - Low` -> `95% CI - Low...408`
## • `95% CI - High` -> `95% CI - High...409`
## • `95% CI - Low` -> `95% CI - Low...413`
## • `95% CI - High` -> `95% CI - High...414`
## • `95% CI - Low` -> `95% CI - Low...417`
## • `95% CI - High` -> `95% CI - High...418`
## • `95% CI - Low` -> `95% CI - Low...441`
## • `95% CI - High` -> `95% CI - High...442`
## • `95% CI - Low` -> `95% CI - Low...444`
## • `95% CI - High` -> `95% CI - High...445`
## • `95% CI - Low` -> `95% CI - Low...448`
## • `95% CI - High` -> `95% CI - High...449`
## • `95% CI - Low` -> `95% CI - Low...452`
## • `95% CI - High` -> `95% CI - High...453`
## • `95% CI - Low` -> `95% CI - Low...459`
## • `95% CI - High` -> `95% CI - High...460`
## • `95% CI - Low` -> `95% CI - Low...463`
## • `95% CI - High` -> `95% CI - High...464`
## • `Average Grade Performance` -> `Average Grade Performance...474`
## • `Average Grade Performance (AIAN)` -> `Average Grade Performance
##   (AIAN)...475`
## • `Average Grade Performance (Asian)` -> `Average Grade Performance
##   (Asian)...476`
## • `Average Grade Performance (Black)` -> `Average Grade Performance
##   (Black)...477`
## • `Average Grade Performance (Hispanic)` -> `Average Grade Performance
##   (Hispanic)...478`
## • `Average Grade Performance (White)` -> `Average Grade Performance
##   (White)...479`
## • `Average Grade Performance` -> `Average Grade Performance...480`
## • `Average Grade Performance (AIAN)` -> `Average Grade Performance
##   (AIAN)...481`
## • `Average Grade Performance (Asian)` -> `Average Grade Performance
##   (Asian)...482`
## • `Average Grade Performance (Black)` -> `Average Grade Performance
##   (Black)...483`
## • `Average Grade Performance (Hispanic)` -> `Average Grade Performance
##   (Hispanic)...484`
## • `Average Grade Performance (White)` -> `Average Grade Performance
##   (White)...485`
## • `Segregation Index` -> `Segregation Index...486`
## • `95% CI - Low` -> `95% CI - Low...493`
## • `95% CI - High` -> `95% CI - High...494`
## • `95% CI - Low` -> `95% CI - Low...496`
## • `95% CI - High` -> `95% CI - High...497`
## • `Segregation Index` -> `Segregation Index...515`
## • `95% CI - Low` -> `95% CI - Low...517`
## • `95% CI - High` -> `95% CI - High...518`
## • `95% CI - Low` -> `95% CI - Low...542`
## • `95% CI - High` -> `95% CI - High...543`
## • `95% CI - Low` -> `95% CI - Low...567`
## • `95% CI - High` -> `95% CI - High...568`
## • `95% CI - Low` -> `95% CI - Low...591`
## • `95% CI - High` -> `95% CI - High...592`
## • `95% CI - Low` -> `95% CI - Low...594`
## • `95% CI - High` -> `95% CI - High...595`
## • `95% CI - Low` -> `95% CI - Low...614`
## • `95% CI - High` -> `95% CI - High...615`
## • `95% CI - Low` -> `95% CI - Low...619`
## • `95% CI - High` -> `95% CI - High...620`
## • `Population` -> `Population...623`
  1. Use your approved data-set
County_Data_clean<-County_Data |> drop_na(`Primary Care Physicians Rate`) %>% filter(`Primary Care Physicians Rate`>0)
  1. Select some variables of interest and see if there is any obvious correlations using the COR command

Variables of Interest = Preventable Hospitalization Rate, Primary Care Physicians Rate, % Vaccinated, and % Severe Housing Problems

County_Example <- County_Data %>% select(`Preventable Hospitalization Rate`,`Primary Care Physicians Rate`,`Severe Housing Cost Burden`,`Mental Health Provider Rate`) %>% arrange(-`Preventable Hospitalization Rate`,`Primary Care Physicians Rate`,`Severe Housing Cost Burden`,`Mental Health Provider Rate`)
cor(County_Example)
##                                  Preventable Hospitalization Rate
## Preventable Hospitalization Rate                                1
## Primary Care Physicians Rate                                   NA
## Severe Housing Cost Burden                                     NA
## Mental Health Provider Rate                                    NA
##                                  Primary Care Physicians Rate
## Preventable Hospitalization Rate                           NA
## Primary Care Physicians Rate                                1
## Severe Housing Cost Burden                                 NA
## Mental Health Provider Rate                                NA
##                                  Severe Housing Cost Burden
## Preventable Hospitalization Rate                         NA
## Primary Care Physicians Rate                             NA
## Severe Housing Cost Burden                                1
## Mental Health Provider Rate                              NA
##                                  Mental Health Provider Rate
## Preventable Hospitalization Rate                          NA
## Primary Care Physicians Rate                              NA
## Severe Housing Cost Burden                                NA
## Mental Health Provider Rate                                1
  1. Examine the same variables visually using the PAIRS command
pairs(County_Example)

  1. Select two variables that seem correlated (positively or negatively) and examine them using PEARSON, SPEARMAN or KENDALL (depending on which is more appropriate)
cor.test(County_Example$`Primary Care Physicians Rate`,County_Example$`Mental Health Provider Rate`,method="spearman")
## Warning in cor.test.default(County_Example$`Primary Care Physicians Rate`, :
## cannot compute exact p-value with ties
## 
##  Spearman's rank correlation rho
## 
## data:  County_Example$`Primary Care Physicians Rate` and County_Example$`Mental Health Provider Rate`
## S = 603113, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##       rho 
## 0.5978665
  1. Explain your findings and justify your choice in selecting the correlation method

I chose to utilize Spearman as the variables for the Primary Care Physicicians Rate and Mental Health Provider Rate seemed to be positively correlated. However, these variables did not have a straight linear correlation such as what would be seen with Pearson. Furthermore, I did not beleive my data necessarily had “ties” that would be seen with Kendall. Overall, the Spearman test shows that there is a positive correlation between the two variables as the rho is .598 showing that areas with more PCP’s likely have higher numbers of mental health providers. In other words, based on these findings, the likelihood of a county having both a high number of PCP’s and mental health providers is high/more likely. With this in mind, it can also be inferred that counties with higher numbers of mental health and primary care providers may have a better quality of life or population health.

  1. publish to Rpubs and submit via CANVAS