[R] Pearson correlation

 피어슨 상관 계수는 두 변수 간의 선형 관계를 정량화하는 데 널리 사용되는 척도이다. 

계산은 간단하지만 잘못된 결론을 내리지 않기 위해서는 신중한 해석이 필요하다.

적절하게 사용할 시 강점:

✔️ 선형 관계의 강도와 방향을 정량화하여 데이터의 패턴을 식별하는 데 도움이 됨.

✔️ 계산 효율적이어서 작은 데이터 세트와 큰 데이터 세트 모두에 적합함.


고려 사항:

❌ 선형 관계만 평가하고 비선형 또는 복잡한 연관성을 포착하지 못한다.

❌ 이상치를 왜곡하여 오해의 소지가 있는 결론을 초래할 수 있다.

❌ 변수가 적절한 분산과 정규 분포 데이터를 가지고 연속적이어야 한다.

❌ 인과관계와 상관관계를 구분하지 않고 있어 잘못된 추론을 초래할 수 있다.

❌ 범위 제한에 민감한 제한된 데이터 범위는 실제 상관 관계를 과소평가할 수 있다.


아래 시각화는 쌍을 이루는 데이터 포인트의 몇 가지 예를 제시한다. 상단 행은 선형 관계의 다양한 강도를 보여주는 반면, 중간 행과 하단 행은 피어슨 상관관계가 부적절한 경우를 강조한다. 예를 들어, 중간 도표에서는 한 변수의 분산이 0이기 때문에 상관관계가 정의되지 않는다. 


출처:

en.wikipedia.org/wiki/Pearson_c...


🔹 R: 상관 계산에 cor()를 사용하고 가설 테스트에 cor.test()를 사용한다. 선형성을 시각적으로 평가하고 이상치를 검출하기 위한 산점도와 회귀선에 대한 레버리지 ggplot2.

파이썬에서 🔹: numpy.corrcoef() 또는 pandas를 활용하세요. 계산을 위한 DataFrame.corr()입니다. 매트플롭과 시본을 사용하여 산점도와 히트맵을 만들어 관계를 탐색하고 비선형성 또는 이상치를 찾는다.


피어슨 계수를 해석하기 전에 정규성, 선형성 및 이상치의 부재와 같은 가정에 대해 항상 데이터 세트를 검사한다. 시각적 및 탐색적 분석과 상관관계를 결합하면 정확하고 신뢰할 수 있는 통찰력을 보장한다.


#datavis #datastructure #Rpackage #Data #pythonlearning #tidyverse #Python #ggplot2 #RStats


The Pearson correlation coefficient is a widely used measure to quantify the linear relationship between two variables. While it is straightforward to calculate, it requires careful interpretation to avoid drawing incorrect conclusions.


Strengths of proper use:


✔️ It quantifies the strength and direction of linear relationships, helping identify patterns in data.

✔️ It is computationally efficient, making it suitable for both small and large data sets.


Challenges and considerations:


❌ It only assesses linear relationships and fails to capture nonlinear or complex associations.

❌ Outliers can distort results, leading to misleading conclusions.

❌ Requires the variables to be continuous, with adequate variance and normally distributed data.

❌ Does not distinguish between causation and correlation, which can lead to incorrect inferences.

❌ Sensitive to range restriction; a limited data range can underestimate the true correlation.


The visualization below presents several examples of paired data points. The top row demonstrates varying strengths of linear relationships, while the middle and bottom rows highlight cases where Pearson correlation is inadequate. For example, in the middle plot, the correlation is undefined because the variance of one variable is zero. Source:

en.wikipedia.org/wiki/Pearson_c…


🔹 In R: Use cor() for correlation computation and cor.test() for hypothesis testing. Leverage ggplot2 for scatter plots and regression lines to visually assess the linearity and detect outliers.

🔹 In Python: Utilize numpy.corrcoef() or pandas.DataFrame.corr() for calculations. Use matplotlib and seaborn to create scatter plots and heatmaps to explore relationships and spot nonlinearity or outliers.


Always inspect the data set for assumptions like normality, linearity, and the absence of outliers before interpreting Pearson’s coefficient. Combining correlation with visual and exploratory analysis ensures accurate and reliable insights.


If you’re interested in learning more, consider joining my online course on Statistical Methods in R. Click this link for detailed information: statisticsglobe.com/online-course-…


#datavis #datastructure #Rpackage #Data #pythonlearning #tidyverse #Python #ggplot2 #RStats

댓글

가장 많이 본 글