과제

데이터 ‘heart.csv’ 를 활용해 Biking과 smoking이 the percentage of people with heart disease 에 영향을 미치는지 유의수준 5%로 검정하세요. 데이터 description: observations on the percentage of people biking to work each day, the percentage of people smoking, and the percentage of people with heart disease 분석절차 1) 데이터 불러오기 2) 독립변수와 종속변수는 무엇인가? 각 변수의 타입은 무엇인가? 3) 독립변수를 factor화 하고 str 함수로 level 살펴보기 4) 어떤 회귀 모델을 생성해야 하는가? 5) 회귀 모델에 대한 결과 해석하기 ○ 독립변수와 종속변수 간 관계가 통계적으로 유의한가? ○ 종속변수와 관련성이 있는 변수는 무엇인가?

1. 데이터 불러오기

library(dbplyr)
dat <- read.csv("C:/Users/33sun/Documents/dataset/heart.csv")
dat <- dat %>% dplyr::select(-X)

2. 독립변수와 종속변수는 무엇인가? 각 변수의 타입은 무엇인가?

str(dat)
## 'data.frame':    498 obs. of  3 variables:
##  $ biking       : num  30.8 65.13 1.96 44.8 69.43 ...
##  $ smoking      : num  10.9 2.22 17.59 2.8 15.97 ...
##  $ heart.disease: num  11.77 2.85 17.18 6.82 4.06 ...

독립변수: biking, smoking 종속변수: heart.disease 각 변수의 타입: 전부 숫자형

3. 독립변수를 factor화 하고 str 함수로 level 살펴보기

dat$biking <- as.factor(dat$biking)
dat$smoking <- as.factor(dat$smoking)
str(dat)
## 'data.frame':    498 obs. of  3 variables:
##  $ biking       : Factor w/ 498 levels "1.119154122",..: 212 428 7 303 454 356 329 28 431 245 ...
##  $ smoking      : Factor w/ 498 levels "0.525849993",..: 163 26 294 35 253 486 138 190 178 388 ...
##  $ heart.disease: num  11.77 2.85 17.18 6.82 4.06 ...
dat$biking <- as.numeric(dat$biking)
dat$smoking <- as.numeric(dat$smoking)
str(dat)
## 'data.frame':    498 obs. of  3 variables:
##  $ biking       : num  212 428 7 303 454 356 329 28 431 245 ...
##  $ smoking      : num  163 26 294 35 253 486 138 190 178 388 ...
##  $ heart.disease: num  11.77 2.85 17.18 6.82 4.06 ...

4. 어떤 회귀 모델을 생성해야 하는가?

종속 변수가 심장병의 비율에 대한 연속성을 가짐으로 선형 회귀 모델을 생성해야한다.

model <- lm(heart.disease ~ biking + smoking, data = dat)
summary(model)
## 
## Call:
## lm(formula = heart.disease ~ biking + smoking, data = dat)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.15036 -0.42391 -0.00533  0.43546  1.97057 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 15.0737981  0.0815594  184.82   <2e-16 ***
## biking      -0.0298076  0.0002149 -138.71   <2e-16 ***
## smoking      0.0101713  0.0002149   47.33   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6894 on 495 degrees of freedom
## Multiple R-squared:  0.9774, Adjusted R-squared:  0.9773 
## F-statistic: 1.068e+04 on 2 and 495 DF,  p-value: < 2.2e-16
library('car')
## 필요한 패키지를 로딩중입니다: carData
vif(model)
##   biking  smoking 
## 1.000081 1.000081

5. 회귀 모델에 대한 결과 해석하기

○ 독립변수와 종속변수 간 관계가 통계적으로 유의한가? ○ 종속변수와 관련성이 있는 변수는 무엇인가?

두 변수 모두 p value가 < 2e-16 이므로 통계적으로 유의하다고 볼 수 있다. Biking 변수는 계수가 -0.20 이므로 심장병 발생률과 부정적인 상관관계를 이룬다고 볼 수 있다. 즉, biking이 증가 할때 심장병 발생률은 떨어진다. 반대로 smoking 변수는 계수가 0.178 이므로 심장병 발생률과 긍정적인 상관관계를 이룬다고 볼 수 있다. 즉, smoking이 증가 할때 심장병 발생률도 역시 증가한다.