1 개요[ | ]
- R multiple regression, R linear regression
- R 다중회귀분석, R 선형회귀분석
2 예시 1: 광고 기억률[ | ]
R
CPU
2.6s
MEM
96M
4.0s
Reload
Copy
df = data.frame(
radio_ads = c(3,4,9,4,5,5,2,6,5,3),
tv_ads = c(1,3,4,1,4,1,4,2,4,2),
retention = c(5,1,6,2,8,3,4,9,7,4)
)
model = lm(retention ~ radio_ads + tv_ads, data=df)
summary( model )
Call: lm(formula = retention ~ radio_ads + tv_ads, data = df) Residuals: Min 1Q Median 3Q Max -3.826 -1.596 -0.117 1.564 3.752 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.3670 2.4409 0.560 0.593 radio_ads 0.4725 0.4517 1.046 0.330 tv_ads 0.5229 0.6543 0.799 0.450 Residual standard error: 2.552 on 7 degrees of freedom Multiple R-squared: 0.2517, Adjusted R-squared: 0.03786 F-statistic: 1.177 on 2 and 7 DF, p-value: 0.3625
- → 회귀식 [math]\displaystyle{ y = 0.4725 x_1 - 0.5229 x_2 + 1.3670 }[/math]
- → 결정계수 [math]\displaystyle{ R^2 = 0.2517 }[/math]
3 예시 2: 빵집 매출[ | ]
R
Reload
Copy
df = read.csv('https://raw.githubusercontent.com/jmnote/zdata/master/multiple-regression/bakery-sales.csv')
head(df)
Loading
Copy
lm1 = lm(sales ~ floor_space + distance_to_station, data=df)
summary(lm1)
Loading
- → 회귀식 [math]\displaystyle{ y = 41.51348 x_1 - 0.34088 x_2 + 65.32392 }[/math]
- → 결정계수 [math]\displaystyle{ R^2 = 0.9452 }[/math]
4 예시 3: mtcars[ | ]
R
Reload
Copy
head(mtcars)
Loading
Copy
model = lm(mpg ~ ., data=mtcars)
summary(model)
Loading
5 예시 4: Boston[ | ]
R
Reload
Copy
library(MASS) # Boston
head(Boston)
Loading
Copy
model = lm(medv ~ ., data=Boston)
summary(model)
Loading
6 같이 보기[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.