과제 1

데이터 불러오기

dat <- mtcars

독립, 중속 변수: 독립 - 자동차 중량, 중속 - 연료 효율

선형회귀 모형 생성하여 model 객체에 담기

model <- lm(wt ~ mpg, data = dat)
# ‘종속변수 ~ 독립변수’와 같은 식으로 작성

결과 출력

summary(model)
## 
## Call:
## lm(formula = wt ~ mpg, data = dat)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.6516 -0.3490 -0.1381  0.3190  1.3684 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.04726    0.30869  19.590  < 2e-16 ***
## mpg         -0.14086    0.01474  -9.559 1.29e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4945 on 30 degrees of freedom
## Multiple R-squared:  0.7528, Adjusted R-squared:  0.7446 
## F-statistic: 91.38 on 1 and 30 DF,  p-value: 1.294e-10

산점도와 회귀선 그리기

plot(dat$hp, dat$mpg, main = "Scatterplot of wt vs mpg with Regression Line",
     xlab = "Weight (wt)", ylab = "Miles per Gallon (mpg)") # 산점도 
abline(model, col = "red") 

# 회귀선 추가

선형회귀 모형 출력하고 결과 해석 (summary 함수)à두 변수 간 관계가 통계적으로 유의한가? 관계가 어떠한가? 통계적으로 유의

과제 2

데이터 불러오기

dat1 <- ToothGrowth

독립, 중속 변수: 독립 - 오렌지 주스(OJ)와 비타민C (VC)를 다양한 농도(dos), 중속 - 치아 모세포(odontoblast)의 길 이(len)

선형회귀 모형 생성하여 model 객체에 담기

model <- lm(dose ~ len, data = dat1)

결과 출력

summary(model)
## 
## Call:
## lm(formula = dose ~ len, data = dat1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.84396 -0.19433  0.00986  0.27939  0.85401 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.074854   0.130597  -0.573    0.569    
## len          0.065992   0.006438  10.250 1.23e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3783 on 58 degrees of freedom
## Multiple R-squared:  0.6443, Adjusted R-squared:  0.6382 
## F-statistic: 105.1 on 1 and 58 DF,  p-value: 1.233e-14

산점도와 회귀선 그리기

plot(dat$hp, dat$mpg, main = "Scatterplot of dose vs len with Regression Line",
     xlab = "Dose of Orange juice/vitamin (dose)", ylab = "Length of Teeth (len))") # 산점도 

abline(model, col = "red") 

# 회귀선 추가

선형회귀 모형 출력하고 결과 해석 (summary 함수) 두 변수 간 관계가 통계적으로 유의한가? 관계가 어떠한가? 통계적으로 유의