๐ง๐ป ๋ฐ์ดํฐ๋ถ์์ ์์ด์ ๊ผญ ์๊ณ ๋์ด๊ฐ์ผ ํ ๊ฐ๋ ์ธ ๋ coefficients ์ข ๋ฅ Pearson๊ณผ Spearman์ ๋ํด ์์ธํ ์์๋ณด์
โซ ์ ๋ฒ coursera ๊ฐ์ข posting์์ ์์ฃผ ์ ๊น ๋ฐฐ์ ๋ ์ ์ด ์์๋ค
๐๐ป coefficients๋ฅผ ์ฌ์ฉํ๊ฒ ๋ ๋ฐฐ๊ฒฝ ๋ฐ ๋ ๊ฐ์ง ์ข ๋ฅ์ coefficients๋ฅผ ์์ธํ ์ดํด๋ณด๋ฉด
from covariance>
๐๐ป covariance๋ '1๊ฐ์ ๋ณ์ ๊ฐ์ด ๋ณํํ ๋ ๋ค๋ฅธ ๋ณ์๊ฐ ์ด๋ ํ ์ฐ๊ด์ฑ์ ๋ํ๋ด๋ฉฐ ๋ณํ๋ ์ง๋ฅผ ์ธก์ ํ๋ ๊ฒ'์ด๋ค
๐๐ป ๋ถ์ฐ = 'ํ ๊ฐ์ ๋ฐ์ดํฐ๊ฐ ํผ์ ธ ์๋ ์ ๋'
๐๐ป ๊ณต๋ถ์ฐ(๊ณตํต๋ ๋ถ์ฐ) = '๋ ๊ฐ์ ๋ฐ์ดํฐ๊ฐ ํผ์ ธ ์๋ ์ ๋(ํ ๊ฐ์ ๋ณ์๊ฐ ์๋ค๊ฐ๋ค ์์ง์ด๋ ๋์ ๋ค๋ฅธ ๋ณ์๊ฐ ์ด๋ ์ ๋๋ก ํผ์ ธ ์๋ ์ง ์ธก์ )'
- ์๋ ๊ทธ๋ฆผ๊ณผ ํจ๊ป -
โ covariance > 0 (positive covariance): ํ๋จ ์ผ์ชฝ ๊ทธ๋ฆผ์ ๋ณด๋ฉด x๊ฐ ๋์์ง๋ฉด y๊ฐ๋ ๊ฐ์ด ๋์์ง๋ ๊ฑธ ๋ณผ ์ ์๋ค
โก covariance < 0 (negative covariance): ํ๋จ ์ค๊ฐ ๊ทธ๋ฆผ์ ๋ณด๋ฉด x๊ฐ ๋์์ง๋ฉด y๊ฐ์ ๊ฐ์ํจ์ ํ์ธํ ์ ์๋ค
โข covariance โ 0: ํ๋จ ์ค๋ฅธ์ชฝ ๊ทธ๋ฆผ์ ๋ณด๋ฉด ๋ x์ y๋ณ์๊ฐ ๋๊ณ ๋ฎ์์ ๋ํ์ฌ ๊ด๋ จ ์๋ ๊ด๊ณ๋ฅผ ๋ณผ ์ ์๋ค
- covariance ์๋ฆฌ
โ๏ธ ์ค์ ๋ก ๊ณ์ฐํ๊ฑฐ๋ ์ฌ์ฉ๋์ง ์์!
→ variable scale์ ๋ฐ๋ผ covariance๊ฐ ๋ฌ๋ผ์ง๊ธฐ ๋๋ฌธ์ correlation์ ์ํ ์ผ์ข ์ stepping stone์ด๋ผ ์๊ฐํ๊ธฐ
โ๏ธ covariance ์($\bar{x}$, $\bar{y}$๋ ๊ฐ๊ฐ x์ y์ ํ๊ท )
${\huge{\sum(x-\bar{x})(y-\bar{y})\over n-1}}$
→ ์ ์์ ๋ถ์๋ฅผ ๋ณด๋ฉด x์ y์ ํ๊ท ์ ๊ธฐ์ค์ผ๋ก ์ด ๋ค ๊ฐ์ ์ฌ๋ถ๋ฉด์ผ๋ก ๋๋์์ ๋, ์ 1๊ณผ 3์ฌ๋ถ๋ฉด์ covariance ์์ ๊ฐ / ์ 2์ 4์ฌ๋ถ๋ฉด์ covariance ์์ ๊ฐ์ ๋ณด์ธ๋ค
→ ์ 1,3 ์ฌ๋ถ๋ฉด์ ์ง๋๋ ๊ฑด positive relationship / ์ 2,4 ์ฌ๋ถ๋ฉด์ ์ง๋๋ ๊ฑด negative relationship์ด๋ผ ํ ์ ์์
โ๏ธ covariance ๊ฒฐ๊ด๊ฐ์ ๋ถํธ๊ฐ ์๋ ๊ฐ ์์ฒด๋ ์ ์ฉํ์ง ์๋ค. ๊ฐ์ผ๋ก line์ ๊ธฐ์ธ๊ธฐ๊ฐ ์ด๋ ์ ๋๋ก steepํ ์ง๋ ์ ์ ์์ & ์ถ๊ฐ์ ์ผ๋ก ์ค์ ์ ๋ค์ด ์ค์ relationship line์ ์ด๋ ์ ๋๋ก ๊ฐ๊น์ด ์ง๋ ์ ์ ์๋ค
โ๏ธ ํ์ง๋ง ๊ธฐ์กด x์ y value์์ y value๋ง scale์ ๋์ด๋๋ผ๋ covariance ๊ฐ ์์ฒด๊ฐ ๋ฐ๋๋ ๊ฑธ ํ์ธํ ์ ์๋ค
(scale๋ง ๋ฐ๋์ด์ relationship line์ ๋๊ฐ์์๋ ๋ถ๊ตฌํ๊ณ )
∴ covariance values are sensitive to the scale of the data, and this makes them difficult to interpret
โ๏ธ ํด๊ฒฐ๋ฒ? correlation! ๐ฅ correlation์ ๊ณ์ฐํ๋ ์ด์์ผ๋ก covariance ๊ฐ๋ ์ด ์ฌ์ฉ๋๋ค
- variance-covariance matrix
a = b = np.arange(5, 50, 5)
c = d = np.arange(10,100,10)
fake_data = {"a": a, "b": b, "c": c, "d": d}
df = pd.DataFrame(fake_data)
df.cov()
→ ์๊ธฐ์์ ๊ณผ์ covariance๊ฐ์ variance๋ฅผ ๋ปํ๋ฉฐ, c์ d๋ก scale์ ๋์ด๋ฉด, ๋์ธ๋งํผ covariance๊ฐ์ด ์ฆ๊ฐํ์์ code๋ก ํ์ธ ๊ฐ๋ฅ!
๐ฎ ์ฐ๋ฆฌ๋ ์ด๋ ๊ฒ covariance matrix๋ฅผ ํตํด (2์ฐจ์ ์ด์์์์) ๋ฐ์ดํฐ์ ๋ถํฌ๋ฅผ ํ์
ํ ์ ์๋ค!
(covariance matrix → ๊ฐ vector์ variance์ covariance๋ฅผ ๊ฐ์ง๋ matrix)
๐ฎ ๊ฐ vector์ variance(์ฆ matrix์์์ ๋๊ฐ์ฑ๋ถ)๋ฅผ ํตํด ๊ฐ vector๋ณ๋ก ๋ฐ์ดํฐ๊ฐ ์ผ๋ง๋ ํฉ์ด์ ธ ์๋ ์ง์ ์ ๋๋ฅผ ์ ์ ์๋ค
๐ฎ covariance๋ฅผ ์ฝ๊ฒ ๊ตฌํ๊ธฐ ์ํด ๊ฐ vector๋ณ ํ๊ท ์ 0์ผ๋ก ๋ง์ถ์ด ํ๊ท ์ ์์ ์ ๊ฐ๋ค๋๊ณ ๊ณ์ฐํ๋ ๊ฒ ๋ ์ฝ๋ค
(๊ทธ๋ ๊ฒ ๋๋ฉด covariance๋ ๊ฐ ์ขํ๋ผ๋ฆฌ์ ๊ณฑ๋ง ํ๋ฉด ๋จ - product of coordinates)
+ using vectors - orthogonality>
๐ฎ 'orthogonality'๋ ๋ฒกํฐ๊ฐ ์๋ก ์์ง์ผ๋ก ์๋ ์ํ๋ฅผ ๋ปํ๋ค
๐ฎ ๋ฒกํฐ๋ค๋ผ๋ฆฌ๋ ์๋ก ์กฐ๊ธ์ด๋ผ๋ ์๊ด๊ด๊ณ๊ฐ ์์ (covariance ๊ฐ์ ํตํด ์ฆ๋ช )์ ์์๋ค. ์ด ๋ ๋ฒกํฐ๊ฐ ์๋ก ์์ง์ด๋ผ๋ฉด ์๊ด๊ด๊ณ๊ฐ ์ ํ ์๋ค๊ณ ํด์ ๊ฐ๋ฅ!
๐ฎ ๋ ๋ฒกํฐ๊ฐ ์๋ก ์์ง์ด๋ค = ๋ ๋ฒกํฐ์ ๋ด์ ๊ฐ์ด 0์ด๋ค
1> Pearson Correlation Coefficient(r)>
๐ฆ trend line์ data๊ฐ ๋ฐ์งํด ์๋ ์ ๋์ ๋ฐ๋ผ ํฌ๊ฒ weak, moderate, strong relationship์ผ๋ก ์ธ ๊ฐ์ง ๊ด๊ณ๋ก ๋ถ๋ฅํ ์ ์๋ค
๐ฆ ์ด ๋, weaker relationship์ผ ์๋ก correlation value๊ฐ ๊ฐ์, stronger์ผ์๋ก correlation value๊ฐ ์ฆ๊ฐํ๋ค
๐ฆ x value์ ๋งค์นญ๋๋ trend line์ y๊ฐ์ ์์ธกํ ๋ stronger relationship์ผ์๋ก ์์ธก๋๋ y๊ฐ ๋ฒ์๊ฐ ๋งค์ฐ ์ข๋ค
โ ์ด ๋, data์ ๊ฐฏ์๋ line์ slope์ correlation์ ์ธ๊ธฐ์ ์ํฅ์ ๋ฏธ์น์ง ์์ (๋ฐ์ดํฐ์ ํ๊ท , ๋ถ์ฐ์ ํฌ๊ธฐ์๋ ์ํฅ X)
๐ฆ * ์๋ก์ด data๊ฐ ์ฃผ์ด์ก์ ๋ ํด๋น paired value๋ฅผ line์ผ๋ก ์์ธกํ๋ confidence
→ โ p-value๊ฐ์ด ์์์๋ก ์ฃผ์ด์ง data point์ line์ผ๋ก ์์ธกํ๋ ์ค๋ช ๋ ฅ์ด ๋ ๊ฐํด์ง๋ค
→ โก๋ ๋ง์ data point๋ฅผ ๊ฐ์ง์๋ก ์ค๋ช ๋ ฅ์ด ๋ ์ข์์ง๋ค
๐ฆ ์ฌ๊ธฐ์ data point์ ์ข์ฐ๋๋ confidence๊ฐ ๋ ๋ณ์๊ฐ์ relationship ๊ด๋ จ ํฐ ์ํฅ์ ๋ฏธ์น๋ ์งํ๊ฐ ๋์ง๋ ์๋๋ค.
→ data point๊ฐ ๋งค์ฐ ๋ง์ confidence๊ฐ ๋๊ฒ ์ธก์ ์ด ๋์ด๋ correlation์ ์ํฅ์ ๋ฐ์ง ์๊ธฐ ๋๋ฌธ์
→ ์ฐ๋ฆฌ๊ฐ ์ํ๋ ๊ฒฐ์ ์ ์ธ ์งํ๋ correlation!
- x์ y์ ๋ ๊ฐ์ง ๋ณ์๋ง ์๋ค ๊ฐ์ ํ๊ณ gene ํน์ ํ๋ชฉ์ ๋ํ covariance ๊ณ์ฐ์์(ํ๋จ) -
๐ฆ x์ y ๊ฐ๊ฐ์ variance์ ๋ฃจํธ๋ฅผ ์์ด ๊ฒฐ๊ณผ๋ฅผ ์๋ก ๊ณฑํด์ ๋ถ๋ชจ๋ก ๋๋ ์ค ๊ฒฐ๊ณผ๊ฐ correlation value๊ฐ ๋๋ค
๐ฆ ํด์1> trend line์ data๊ฐ ๋ฐ์ง๋์ด ์์์๋ก covariance๊ฐ๊ณผ ๊ฐ vector์ variance ๋ฃจํธ๊ฐ์ ๊ณฑ์ด ๊ฑฐ์ ๊ฐ๊ฒ ๋๋ค
๐ฆ ํด์2> trend line์ผ๋ก๋ถํฐ data๊ฐ ์ ์ ๋ฉ์ด์ง์๋ก ๋น์ฐํ covariance๊ฐ๋ ๋จ์ด์ง๊ธฐ์ correlation๊ฐ๋ ๊ฐ์ํจ - 0์ผ๋ก ์๋ ด
vs. R^2(coefficient of determination)?
→ ์ฆ pearson correlation coefficient๋ relationship ๋ณ์์์ ๊ด๊ณ์ ์ ๋ strength๋ฅผ ๋ณด์ฌ์ค๋ค
Q. ๊ทธ๋ฌ๋ฉด R-Squared์ Pearson Correlation๊ณผ์ ์ฐจ์ด์ ?
โ ์ผ๋จ Pearson ๊ณ์๋ scale์ ์ํฅ์ ๋ฐ์ง ์๋๋ค. ์ค๋ก์ง ์ซ์๊ฐ์ ์๋์ ์ธ ์ฐจ์ด๋ก ์ธํด์ ๊ฒฐ์ ๋๋ ๊ณ์์ด๋ค. ๋ฐ๋ผ์ ์์์ ์ธ๊ธํ ๊ฒ์ฒ๋ผ data ์๊ฐ ์ ์ด์ confidence์์ ๋ฎ์ ์ฑ๋ฅ์ ๋ณด์์๋ Pearson ๊ณ์๋ -1์ด๋ 1์ ๊ฐ๊น์ด ์์น๋ฅผ ๋ณด์ผ ์ ์๋ค๋ ์ ์ด๋ค
โก coefficient of determination์, ์ฆ R^2๋ ์ผ๋ง๋ ์์ธก๋ value๊ฐ trend line ์์์์ y variance๋ฅผ ์ผ๋ง๋ ์ ์ค๋ช
ํ ์ ์๋ ์ง๋ฅผ ๋ณด์ฌ์ฃผ๋ ์งํ์ด๋ค.
→ ์ ๊ณฑ์ด ๋์๊ธฐ์ 1์ ๊ฐ๊น์ธ์๋ก model์ ๋ํด ๋์ ์ค๋ช
๋ ฅ์ ๋ณด์ฌ์ค๋ค๊ณ ํ ์ ์๋ค
→ scale์ ์ํฅ์ ๋ฐ์
โ ์ ๋ฆฌํ๋ฉด Pearson ๊ณ์๋ ์์ธก์ฉ์ด ์๋, ์ฃผ์ด์ง data์์ pattern์ด๋ relationship์ ์ฐพ์๋ผ ๋ ์ฐ์ด๋ ์ฉ๋์ด๋ฉฐ
โ
R^2๋ model์์ ์ฃผ์ด์ง prediction๊ณผ ์ค์ ์ฃผ์ด์ง observation์ variance๋ฅผ ์ผ๋ง๋ ์ ์ค๋ช
ํ ์ ์๋ ์ง ์ฐ์ด๋ ์ฉ๋์ด๋ค
(๋ scale์ ์ํฅ์ ๋ฐ๊ธฐ์ confidence๋ฉด์์๋ ์ ๋ขฐ๊ฐ ๊ฐ๋ ์งํ์ด๋ค)
+ ์ถ๊ฐ๋ก Pearson Corrleation Coefficient๋ฅผ ์ ๊ณฑํ๋ค๊ณ ํด์ R-Sqaured๊ฐ ํญ์ ๋๋ ๊ฑด ์๋๋ค!
(๋งค์ฐ ํน์ ํ ์ ํ๋ชจ๋ธ SLR์ ์ ์ธํ๊ณ ๋)
→ ์ ์ธ ๊ทธ๋ํ์์ ๋ณด๋ฏ์ด ์์ธก ๋ผ์ธ model๊ณผ ๋ง์ด ๋ฒ์ด๋ ์์์๋ (์ค๊ฐ๊ณผ ์ค๋ฅธ์ชฝ) ์๋ก ์ผ๋ ฌ๋ก ๋์ด๋์ด ์๋ data ๋๋ถ์ Pearson๊ฐ์ 1์ ๊ฐ๊น๊ฒ ๋์จ๋ค. ๋ฐ๋ผ์ ์ฃผ์ด์ง ๋ชจ๋ธ์ ๋ง๊ฒ ์ ์์ธกํ๋ ์ง ํ์ธํ ๋ฐฉ๋ฒ์ R^2๋ฅผ ์ด์ฉ
* R^2 ์์ธํ ๋ด์ฉ์ ์๋ ํฌ์คํ ์ฐธ์กฐ
2>Spearman Rank-Order Correlation Coefficient(ρ; rs)>
๐ค ๋ ๊ฐ์ rank ์์๋ฅผ ๊ฐ๊ณ ์๋ ordinal variable ์ฌ์ด(continuous & discrete ๋ชจ๋ ๊ฐ๋ฅ)์ ๊ด๊ณ relationship์ด ์ผ๋ง๋ weakํ๊ฑฐ๋ strongํ ์ง ๋ณด์ฌ์ฃผ๋ ์ฒ๋!
๐ค Pearson๊ณผ ๋ฌ๋ฆฌ ๋ถ์ฐ๊ณผ ๊ฐ์ ์์น๋ฅผ numeric data๋ฅผ ํตํด ๊ณ์ฐํ ์ ์๋ ํํ๊ฐ ์๋, data๊ฐ categorialํ ๋ ์ฐ์ด๋ ์์น์ด๋ค
๐ค ๋น๋ชจ์์ ๋ฐฉ๋ฒ
(๋ชจ์์ & ๋น๋ชจ์์ ์ฐจ์ด ํ๋จ ํฌ์คํ ์ฐธ์กฐ!)
๐ค'a nonparametric measure of rank correlation (statistical dependence between the rankings of two variables). It assesses how well the relationship between two variables can be described using a monotonic function.'
๐ค Pearson๊ณผ ๋ค๋ฅด๊ฒ linear function์ ๊ธฐ์ค์ผ๋ก ํ๊ฐํ์ง๋ง, Spearman์ monotonic function์ ๊ธฐ์ค์ผ๋ก ํ๊ฐ
(pearson๊ณผ ๋ฌ๋ฆฌ ์ ํ์ ์ธ ์๊ด๊ด๊ณ๊ฐ ์๋, ํ ๋ณ์๊ฐ ์ฆ๊ฐํ ๋ ๋ค๋ฅธ ๋ณ์๊ฐ ์ฆ๊ฐ/๊ฐ์ํ๋ ์ง์ ๋ํ ์ ์ฑ์ ๊ด๊ณ๋ฅผ ์๊ณ ์ ํ๋ ๊ฒ spearman)
๐ค The Spearman correlation btw 2 variables = The Pearson correlation btw the rank values of those 2 variables
๐ค ์ ๊ทธ๋ํ์์ ๋ณด์๋ค์ถ์ด monotnoic function์ ๋ฐ๋ฅด๋ฉด spearman ๊ณ์๋ 1์ ๋ฐ๋ฅธ๋ค. ์ ์ค๋ฅธ์ชฝ ๊ทธ๋ํ์ ๊ฐ์ด outlier๊ฐ ์กด์ฌํ ๊ฒฝ์ฐ pearson๋ณด๋ค spearman์ด outlier์ ๋ ์ํฅ์ ๋ฐ์(less sensitive) ๊ณ์๊ฐ์ด ๋ ๋์์ ์ ์ ์์
๊ณ์ฐ>
๐ค ์์์ ์๊ธฐํ๋ฏ์ด spearman ๊ณ์๋ ordinalํ variable์ ์์๋ฅผ ๋งค๊ฒจ์ ํด๋น ์์ R(X), R(Y)์ pearson ๊ณ์๋ก ์ฐ์ถํ ๊ฒ์ ๋งํ๋ค
๐ค For a sample of size n, the n raw scores $X_i, Y_i$ are converted to ranks $R(X_i), R(Y_i)$ and $r_s$ is computed as
- pearson ๊ณต์์ Rank๋ฅผ ๊ทธ๋๋ก ๋ฃ์ผ๋ฉด ๋จ -
๐ค (ํน์) ๋ง์ฝ ๋ชจ๋ n๊ฐ์ rank๊ฐ ๊ฐ๊ธฐ ๋ค๋ฅธ ์ ์๋ผ๋ฉด, ์๋์ ๊ฐ์ ๊ณต์์ผ๋ก $r_s$๋ฅผ ๊ตฌํ ์ ์๋ค
- $d_i$๋ $R(X_i) - R(Y_i)$๋ก ๊ฐ ๊ด์ธก์น์ ์ฐจ์ด / n์ ๊ด์ธก์น์ ๊ฐ์ -
interpretations & ์ ๋ฆฌ>
๐ค spearman ๊ณ์๊ฐ ๊ฑฐ์ 1์ ๊ฐ๊น๋ค๋ ๊ฒ์ ์์ผ๋ก ์ด๋ฃฌ $X_i, Y_i$์ ์ฐจ์ด๊ฐ ํญ์ ๊ฑฐ์ ๋๊ฐ์ ํธ๋ ๋๋ฅผ ๋ณด์ธ๋ค๋ ๊ฑธ ๋ปํ๋ค
๐ค ์ฆ, 1์ ๊ฐ๊น์ฐ๋ฉด ๋ ordinal ๋ณ์๊ฐ ์๋ก ๊ด๊ณ๊ฐ ์์์ ์ ์ ์๊ณ , 0์ ๊ฐ๊น์ฐ๋ฉด ๊ฑฐ์ ๊ด๊ณ๊ฐ ์์์, -1์ ๊ฐ๊น์ฐ๋ฉด ์๋ก negative monotnoic function์ ํํ๋ก, ์๋ก ๊ฐ๊ฐ (rank๊ฐ) ์ฆ๊ฐํ ๋ ๊ฐ์ํ๊ณ , ๋๋ ๊ฐ์ํ ๋ ์ฆ๊ฐํ๋ ๊ด๊ณ๋ฅผ ๋ณด์ธ๋ค๋ ๋ป์ด๋ค.
๐ spearman's correlation coefficient๋ฅผ ์ฐ์ถํ๊ธฐ ์ํด์๋..!
โ ์ฃผ์ด์ง sample data๋ ๋ชจ๋ random
โก monotonic ๊ด๊ณ๊ฐ ์กด์ฌํ๋ค๊ณ ๊ฐ์ ํ๊ณ (Ha) assumption test ์งํ
โข variable๋ค์ ์ ์ด๋ ordinalํ๊ฑฐ๋ continuous numerical
โฃ data๋ ์๋ก ์์ ๊ฐ์ง sample๋ค์ด์ด์ผ ํจ - ๊ทธ๋์ผ ๊ฐ ์๋ผ๋ฆฌ monotonic function์ ๋ฐ๋ฅด๋ ์ง ๋ณผ ์ ์์
โค data๋ผ๋ฆฌ ์๋ก independentํด์ผ ํจ
๐ค โ ์ฌ๊ธฐ์! pearson๊ณผ ๋ค๋ฅด๊ฒ ๋น๋ชจ์์ ์ธ ๋ฐฉ๋ฒ์ด๋ฏ๋ก data๋ ๊ตณ์ด ์ ๊ท๋ถํฌ์์ ๊ฐ์ ธ์ค์ง ์์๋ ๋๋ค โ
w/code
๐ง scipy.stats.spearmanr docu ๐ง
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html
scipy.stats.spearmanr(a, b=None, axis=0, nan_policy='propagate', alternative='two-sided')
'Calculate a Spearman correlation coefficient with associated p-value. The Spearman rank-order correlation coefficient is a nonparametric measure of the monotonicity of the relationship between two datasets. Unlike the Pearson correlation, the Spearman correlation does not assume that both datasets are normally distributed. Like other correlation coefficients, this one varies between -1 and +1 with 0 implying no correlation. Correlations of -1 or +1 imply an exact monotonic relationship. Positive correlations imply that as x increases, so does y. Negative correlations imply that as x increases, y decreases. The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Spearman correlation at least as extreme as the one computed from these datasets. The p-values are not entirely reliable but are probably reasonable for datasets larger than 500 or so.'
๐ฉ๐ฆฐ returns 1>correlation ๊ณ์ & 2>p-value
โซ H0 ๊ท๋ฌด๊ฐ์ค์ ๋ ordinal variable๊ฐ์ monotonic relation์ด ์กด์ฌํ์ง ์๋๋ค๋ ๊ฒ์ผ๋ก, p-value๊ฐ ์ผ๋ฐ์ ์ผ๋ก 0.05์ดํ์ด๋ฉด ๊ท๋ฌด๊ฐ์ค ๊ธฐ๊ฐ! - ์ฆ Ha ๋์๊ฐ์ค๋ก ์ธ์ด '๋ ordinal variable๊ฐ์ ๊ด๊ณ๊ฐ ์กด์ฌํ๋ค'๋ก ํต๊ณ์ ๊ฒ์ ์ ๋ด๋ฆด ์ ์๋ค!
โซ ์์
Q. ์๋๋ 1๋ฐ ์ด 35๋ช ํ์ ๊ฐ๊ฐ์ ์์ด์ ์ํ ๋ชจ์๊ณ ์ฌ ๋ฑ๊ธ์ด๋ค. ํ์๋ค์ ์์ด๋ฑ๊ธ๊ณผ ์ํ๋ฑ๊ธ์ด ์๋ก ์ ์๋ฏธํ ๊ด๊ณ์ฑ์ ๋ณด์ด๋ ์ง spearman correlation coefficients๋ฅผ ์ฐ์ถํด ๋ด ํต๊ณ์ ๊ฒ์ ์ ๋ด๋ฆฌ์. (๋จ, ๊ฐ ํ์๋ณ ๋ฑ๊ธ์ ์๋ก independentํ๋ค)
- (ํ๋จ) ํ์๋ณ ๋ฑ๊ธํ ์ผ๋ถ -
A.
import pandas as pd
English = [1, 5, 2, 3, 3, 5, 6, 6, 5, 4, 2, 4, 5, 3, 4, 5, 2, 3, 5, 4, 3, 4, 6, 5, 8, 6, 4, 7, 5, 4, 3, 4, 1, 3, 4]
Math = [2, 5, 6, 4, 3, 5, 4, 2, 4, 5, 3, 3, 5, 6, 4, 5, 6, 5, 6, 5, 7, 6, 5, 4, 5, 3, 5, 4, 2, 1, 1, 4, 3, 2, 2]
grade = pd.DataFrame({'English':English, 'Math': Math})
* ๊ฒ์ ๊ฒฐ๊ณผ>
stats.spearmanr(grade['English'].tolist(), grade['Math'].tolist())
#SpearmanrResult(correlation=0.03519639020891649, pvalue=0.8409139955046013)
* ๊ฒฐ๋ก > ์ญ์ ์์ด๋ฑ๊ธ๊ณผ ์ํ ๋ฑ๊ธ์ ๋๋ค์ผ๋ก 1~9์ฌ์ด์ ์ซ์๋ฅผ ์๋ฌด๋ ๊ฒ ์ ๋ ฅํ์๋๋ spearman๊ฐ์ด 0์ ๊ฐ๊น์ด 0.03์ผ๋ก monotonicํ function relationship์ด ์กด์ฌํ์ง ์์์ ํต๊ณ์ ์ผ๋ก ๊ฒ์ ํ ์ ์์๋ค! (pvalue๋ 0.05๋ณด๋ค ํจ์ฌ ํฐ ๊ฐ์ผ๋ก ๊ท๋ฌด๊ฐ์ค ๊ธฐ๊ฐ ์๋จ)
++ ์ถ๊ฐ์ ์ธ correlation ์ข ๋ฅ - kendall-rank & point-biserial correlation ์ถํ ํฌ์คํ ์ฐธ์กฐ! ++
* ์ถ์ฒ1) https://programmathically.com/covariance-and-correlation/
* ์ถ์ฒ2) covariance matrix https://www.youtube.com/watch?v=WBlnwvjfMtQ
* ์ถ์ฒ3) r^2 vs. Pearson ๊ณ์ https://towardsdatascience.com/r%C2%B2-or-r%C2%B2-when-to-use-what-4968eee68ed3
* ์ถ์ฒ4) spearman ์ค๋ช https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient
* ์ถ์ฒ5) spearman youtube https://www.youtube.com/watch?v=JwNwbu-g2m0
* ์ถ์ฒ6) pearson, spearman, r-squared ๋น๊ต, ์ค๋ช https://m.blog.naver.com/istech7/50153288534
* ์ถ์ฒ) ๊ฐ STATQUEST - correlation explained! ๐ฉ๐ฟ๐ https://www.youtube.com/watch?v=xZ_z8KWkhXE
* ์ถ์ฒ) ๊ฐ STATQUEST - covariance explained! ๐ป https://www.youtube.com/watch?v=qtaqvPAeEJY&t=435s
'Math & Linear Algebra > Concepts' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Odds Ratio & log(Odds Ratio) (0) | 2022.07.11 |
---|---|
eigenvalue & eigenvector (0) | 2022.05.14 |
linear & non-linear โ span, basis, rank, projection (0) | 2022.05.13 |
Cramer's Rule (+exercise) (0) | 2022.05.09 |
Basic Derivative - ๋ฏธ๋ถ ๊ธฐ์ด (0) | 2022.04.18 |
๋๊ธ