R 단순선형회귀분석

1 개요[ | ]

R simple regression
R simple linear regression
R 회귀분석
R 단순회귀분석
R 단순선형회귀분석

2 예시 1: 키와 몸무게[ | ]

R
CPU
2.5s
MEM
95M
37.6s
Reload
Copy
df <- data.frame(
  height = c(1.47, 1.50, 1.52, 1.55, 1.57, 1.60, 1.63, 1.65, 1.68, 1.70, 1.73, 1.75, 1.78, 1.80, 1.83),
  mass = c(52.21, 53.12, 54.48, 55.84, 57.20, 58.57, 59.93, 61.29, 63.11, 64.47, 66.28, 68.10, 69.92, 72.19, 74.46)
)
model <- lm(mass ~ height, data=df)
summary(model)
Call:
lm(formula = mass ~ height, data = df)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.88171 -0.64484 -0.06993  0.34095  1.39385 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  -39.062      2.938  -13.29 6.05e-09 ***
height        61.272      1.776   34.50 3.60e-14 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.7591 on 13 degrees of freedom
Multiple R-squared:  0.9892,	Adjusted R-squared:  0.9884 
F-statistic:  1190 on 1 and 13 DF,  p-value: 3.604e-14
→ 회귀식 [math]\displaystyle{ y=61.272x-39.062 }[/math]
→ 결정계수 [math]\displaystyle{ R^2=0.9892 }[/math]

3 예시 2: 대학 불합격[ | ]

R
Reload
Copy
df <- data.frame(
  student = c(4000,10000,15000,12000,8000,16000,5000,7000,9000,10000),
  rejection = c(100,400,500,400,300,400,200,100,400,200)
)
model <- lm(rejection ~ student, data=df)
summary(model)
Loading
→ 회귀식 [math]\displaystyle{ y=0.028902x+22.543353 }[/math]
→ 결정계수 [math]\displaystyle{ R^2=0.6423 }[/math]

4 예시 3: 아이스티 주문[ | ]

R
Reload
Copy
df <- read.csv('https://raw.githubusercontent.com/jmnote/ds/main/simple-regression/iced-tea-orders.csv')
head(df)
Loading
Copy
model <- lm(order ~ high_temperature, data=df)
summary(model)
Loading
→ 회귀식 [math]\displaystyle{ y=3.7379x-36.3612 }[/math]
→ 결정계수 [math]\displaystyle{ R^2=0.8225 }[/math]

5 같이 보기[ | ]