Loading the Data

setwd("~/Documents/R Files/Homework 5")
districts <- read_csv("district_info.csv", skip=1)

2) Select some variables of interest and see if there is any obvious correlations using the COR command

variables <- districts[, c("DPETECOP",
                           "DPETRSKP",
                           "DPETLEPP",
                           "DPETSPEP")]

cor(variables, use = "complete.obs")
          DPETECOP   DPETRSKP   DPETLEPP    DPETSPEP
DPETECOP 1.0000000 0.60577456  0.4506561  0.05043960
DPETRSKP 0.6057746 1.00000000  0.5798253  0.09820012
DPETLEPP 0.4506561 0.57982535  1.0000000 -0.26397594
DPETSPEP 0.0504396 0.09820012 -0.2639759  1.00000000

3) Examine the same variables visually using the PAIRS command

pairs(variables,
      main = "Relationships Between Selected District Variables")

4) 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(districts$DPETECOP,
         districts$DPETRSKP,
         method = "spearman",
         exact = FALSE)

    Spearman's rank correlation rho

data:  districts$DPETECOP and districts$DPETRSKP
S = 110249731, p-value < 2.2e-16
alternative hypothesis: true rho is not equal to 0
sample estimates:
      rho 
0.6247434 

5) Explain your findings and justify your choice in selecting the correlation method

After reviewing the correlation matrix and pairs plot, the strongest relationship was between the percentage of economically disadvantaged students (DPETECOP) and the percentage of at-risk students (DPETRSKP). I used Spearman’s rank correlation because both variables are percentages and the relationship was not perfectly linear. The Spearman correlation was approximately 0.625, with a p-value of less than 2.2e-16, showing a statistically significant moderate positive relationship. This means that districts with higher percentages of economically disadvantaged students also tend to have higher percentages of students classified as at risk. However, this correlation does not prove that economic disadvantage causes at-risk classification.