##
## 4 6 8
## 11 7 14
##
## 4 6 8
## 0.34375 0.21875 0.43750
##
## 4 6 8
## 34.375 21.875 43.750
##
## 0 1
## 4 3 8
## 6 4 3
## 8 12 2
##
## automatic manual
## 4 3 8
## 6 4 3
## 8 12 2
mtcars$tm = ifelse(mtcars$am==0, 'automatic', 'manual')
result = table(mtcars$cyl, mtcars$tm)
result##
## automatic manual
## 4 3 8
## 6 4 3
## 8 12 2
##
## automatic manual Sum
## 4 3 8 11
## 6 4 3 7
## 8 12 2 14
## Sum 19 13 32
## tm
## cyl automatic manual
## 4 3 8
## 6 4 3
## 8 12 2
## tm
## cyl automatic manual
## 4 0.09375 0.25000
## 6 0.12500 0.09375
## 8 0.37500 0.06250
## tm
## cyl automatic manual
## 4 9.375 25.000
## 6 12.500 9.375
## 8 37.500 6.250
## tm
## cyl automatic manual Sum
## 4 9.375 25.000 34.375
## 6 12.500 9.375 21.875
## 8 37.500 6.250 43.750
## Sum 59.375 40.625 100.000
##
## automatic manual
## 4 3 8
## 6 4 3
## 8 12 2
## Warning in chisq.test(result): Chi-squared approximation may be incorrect
##
## Pearson's Chi-squared test
##
## data: result
## X-squared = 8.7407, df = 2, p-value = 0.01265
##
## Fisher's Exact Test for Count Data
##
## data: result
## p-value = 0.009105
## alternative hypothesis: two.sided
두 개의 범주형 변수사이의 독립성 검정은 카이제곱검정 또는 피셔검정을 이용합니다. 하지만 한 변수가 순위가 있는 ordinal 변수인 경우 trend를 보려면 Cochran-Armitage Trend test를 시행합니다.
acs 데이터의 고혈압(HBP)과 흡연(smoking)과의 관계를 알아봅시다. 함수 round(x,y)의 경우, x는 반올림하려는 숫자, y는 반올림하려는 소수점 자리수 입니다.
##
## Ex-smoker Never Smoker
## No 81 99 176
## Yes 123 233 145
##
## Ex-smoker Never Smoker
## No 9.45 11.55 20.54
## Yes 14.35 27.19 16.92
## Factor w/ 3 levels "Never","Ex-smoker",..: 3 1 1 1 3 1 2 2 1 3 ...
##
## Never Ex-smoker Smoker
## No 99 81 176
## Yes 233 123 145
##
## Chi-squared Test for Trend in Proportions
##
## data: result[2, ] out of colSums(result) ,
## using scores: 1 2 3
## X-squared = 41.967, df = 1, p-value = 9.282e-11
plot(t(result),col=c("deepskyblue","brown2"),main="Hypertension and Smoking",
ylab="Hypertension",xlab="Smoking")
## [1] NA
## [1] 185.2002
##
## Descriptive Statistics by 'Dx'
## ___________________________________________________
## NSTEMI STEMI Unstable Angina p
## (N=153) (N=304) (N=400)
## ---------------------------------------------------
## TC 193.7 ± 53.6 183.2 ± 43.4 183.5 ± 48.3 0.057
## ---------------------------------------------------
## NSTEMI STEMI Unstable Angina
## 193.7257 183.2020 183.4801
## Dx TC
## 1 NSTEMI 193.7257
## 2 STEMI 183.2020
## 3 Unstable Angina 183.4801
## Dx TC.1 TC.2
## 1 NSTEMI 193.72568 53.61899
## 2 STEMI 183.20204 43.38024
## 3 Unstable Angina 183.48010 48.34923
## Dx TC.1 TC.2
## 1 NSTEMI 193.72568 53.61899
## 2 STEMI 183.20204 43.38024
## 3 Unstable Angina 183.48010 48.34923
## Dx TC.1 TC.2 TG.1 TG.2 HDLC.1 HDLC.2
## 1 NSTEMI 193.72568 53.61899 130.12162 88.54968 38.93919 11.87189
## 2 STEMI 183.42594 43.28396 106.65529 72.29184 38.45734 11.01411
## 3 Unstable Angina 183.35857 48.35118 136.80563 101.17377 37.81330 10.85066
## LDLC.1 LDLC.2
## 1 126.09459 44.73373
## 2 116.92491 39.37014
## 3 112.87724 40.38533
##
## Descriptive Statistics stratified by 'sex' and 'Dx'
## ____________________________________________________________________________________________________
## Male Female
## ------------------------------------------------ -----------------------------------------------
## NSTEMI STEMI Unstable Angina p NSTEMI STEMI Unstable Angina p
## (N=103) (N=220) (N=247) (N=50) (N=84) (N=153)
## ----------------------------------------------------------------------------------------------------
## TC 192.6 ± 54.3 184.1 ± 42.6 178.7 ± 44.6 0.036 196.3 ± 52.7 180.7 ± 45.7 191.1 ± 53.1 0.192
## TG 138.0 ± 100.2 104.3 ± 65.5 144.3 ± 114.2 0.000 112.5 ± 51.1 112.3 ± 87.2 126.3 ± 76.0 0.316
## ----------------------------------------------------------------------------------------------------