iris 데이터프레임에서 petal.width로 petal.length를 예측하는 선형회귀모형

네이버 지식인에서 나온 질문 이다.  



R프로그래밍 질문입니다.

iris 데이터프레임에서 petal.width로 petal.length를 예측하는 선형회귀모형은 어떻게 만드나요..?

산점도는 또 어떤 식으로 해야하는지 궁금합니다!



아래와 같이 정리 하였다. 
# 선형회귀 분석
fit <- lm(Petal.Length ~ Petal.Width, data = iris)

# fitting 화 결과
fit
## 
## Call:
## lm(formula = Petal.Length ~ Petal.Width, data = iris)
## 
## Coefficients:
## (Intercept)  Petal.Width  
##       1.084        2.230
# fitting 요약 
summary(fit)
## 
## Call:
## lm(formula = Petal.Length ~ Petal.Width, data = iris)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.33542 -0.30347 -0.02955  0.25776  1.39453 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.08356    0.07297   14.85   <2e-16 ***
## Petal.Width  2.22994    0.05140   43.39   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4782 on 148 degrees of freedom
## Multiple R-squared:  0.9271, Adjusted R-squared:  0.9266 
## F-statistic:  1882 on 1 and 148 DF,  p-value: < 2.2e-16
# ggplot 으로 그래프 그리기
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)

iris %>% 
  ggplot(aes(Petal.Width, Petal.Length)) +
  geom_point() +
  geom_smooth()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'


petal.length를 예측 한다면, petal.length가 종속 변수 입니다. petal.width는 독립 변수 이다. 즉 독립 변수가지고 종속 변수를 예측 한다. 


그리고,  ggplot 으로 산점도를 그릴 수 있고,   geom_smoth를 그리면 예측 곡선도 같이 그린다. 



댓글 없음:

댓글 쓰기

공무 스케줄 AI Agem에 대한 생각

     지금 상황이 아비 규환이다.  어느 부서든 회사가 인수 합병되고 나서  투자를 기획하는 경영기획이 특히 않이 정신이 없고, 우리부서도 전부 미국 필리 조선소로 인원이 나가 있어,  사실상 10년 이상 고기량자는 거의 없다.   우리부서에 남아...