728x90

# 1. 상관분석이란?

gender <- c("F","F","F","M","M","M")

wei <- c(65,66,69,67,68,72)

hei <- c(171,172,176,173,177,178)

age <- c(23,24,38,43,40,42)

cor(hei,wei) # 0.9085505  상관계수

cov(hei,wei) # 6.5 공분산

cor(hei,wei,method="pearson") # 0.9085505 디폴트 피어슨 상관계수

cor(hei,wei,age) # 에러, 인수가 두개이므로 에러

cor(cbind(hei,wei,age)) # hei, wei, age 를 cbind로 묶어서 하나의 인수로 만들어 해결

cor.test(hei,wei)   # 상관계수 검정통계량(t검정) 관련 자료 생성 

s_cor_01(r)

cor.test(hei,wei) 를 하면 상관계수 관련 검정통계량이 출력됩니다.

s_cor_02(r)

health <- data.frame(wei,hei,age)   # 벡터 데이터들을 .data.frame 으로 전환
pairs(health)    # data.frame 에 있는 변수들의 쌍으로 plot 그래프 출력

s_cor_03(r)

 

pairs(mtcars)  : R설치할 때 기본으로 설치되는 mtcars 데이터의 각 변수들 상관도 출력

 

+ Recent posts