일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- 유주
- t test
- repeated measures ANOVA
- 풍백
- 후한서
- 낙랑군
- 한서지리지
- linear regression
- 한서
- categorical variable
- 통계
- 단군
- 선형회귀분석
- R
- 패수
- 통계학
- 고구려
- spss
- ANOVA
- 신라
- 지리지
- 태그를 입력해 주세요.
- 독사방여기요
- 기자조선
- post hoc test
- 창평
- 히스토그램
- 기자
- 우분투
- Histogram
- Today
- Total
獨斷論
통계 R의 명령어 입문 (5): 상관관계(Correlation) 계산 본문
R에서 제공하는 상관관계(correlation)은 아래 세가지이다.
- Pearson's product moment correlation coefficient
- Kendall's tau rank correlation coefficient
- Spearman's rank correlation coefficient(Spearman's rho statistic)
위 세 가지 상관관계를 구하기 위해서 우선 변수 x와 y에 데이터를 입력한다.
> x = rnorm(100, 50, 10) # 평균이 50이고 표준편차가 10인 100개의 정규분포를 갖는 난수발생
> y = rnorm(100, 75, 20) # 평균이 75리고 표준편차가 20인 100개의 정규분포를 갖는 난수발생
두 데이터를 한번 그래프로 나타내면 아래와 같다.
> plot(x,y)
Pearson's correlation은 아래와 같이 구한다.
> cor.test(x, y, method = 'pearson')
Pearson's product-moment correlation
data: x and y
t = -0.1398, df = 98, p-value = 0.8891
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.2099602 0.1828007
sample estimates:
cor
-0.01412461
Pearson correlation은 단순히 cor(x,y)라고 치면 correlation coefficients만 보여주기도 한다.
아래에 Kendall's tau rank correlation coefficient와 Spearman's rank correlation coefficient를 구하는 방법을 보여주었다. cor.test()의 method의 값을 각각 kendal와 spearman으로 바꿔주기만 하면 된다.
> cor.test(x, y, method = 'spearman')
Spearman's rank correlation rho
data: x and y
S = 163714, p-value = 0.8617
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
0.01761776>
> cor.test(x, y, method = 'kendal')
Kendall's rank correlation tau
data: x and y
z = 0.2263, p-value = 0.8209
alternative hypothesis: true tau is not equal to 0
sample estimates:
tau
0.01535354
난수발생으로 만들어진 두 데이터 x와 y에 대해서 상관관계가 없음을 보여준다.