Amta - Final - Notes.r: ### Step Wise AIC Regression
Amta - Final - Notes.r: ### Step Wise AIC Regression
Amta - Final - Notes.r: ### Step Wise AIC Regression
R
Admin
df = mtcars
##
## Call:
## lm(formula = .outcome ~ wt + qsec + am, data = dat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.4811 -1.5555 -0.7257 1.4110 4.6610
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.6178 6.9596 1.382 0.177915
## wt -3.9165 0.7112 -5.507 6.95e-06 ***
## qsec 1.2259 0.2887 4.247 0.000216 ***
## am 2.9358 1.4109 2.081 0.046716 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.459 on 28 degrees of freedom
## Multiple R-squared: 0.8497, Adjusted R-squared: 0.8336
## F-statistic: 52.75 on 3 and 28 DF, p-value: 1.21e-11
## [1] 163.7098
AIC(step.fit$finalModel) #154.1
## [1] 154.1194
df = Carseats
head(df)
# step 1: releveling DV
class(df$ShelveLoc)
## [1] "factor"
contrasts(df$ShelveLoc)
## Good Medium
## Bad 0 0
## Good 1 0
## Medium 0 1
summary(mlog.fit)
## Call:
## multinom(formula = ShelveLoc ~ ., data = df)
##
## Coefficients:
## (Intercept) Sales CompPrice Income Advertising
## Good -38.91396 4.903290 -0.4661398 -0.07635094 -0.5378368
## Medium -12.17893 1.950679 -0.1776329 -0.04191173 -0.2420112
## Population Price Age Education UrbanYes USYes
## Good -0.002085516 0.4818368 0.2371202 0.03187005 -1.6010195 0.5957802
## Medium -0.001034355 0.1882456 0.1010462 0.04009025 -0.6622705 0.4524779
##
## Std. Errors:
## (Intercept) Sales CompPrice Income Advertising
## Good 0.4927225 0.3419561 0.05210688 0.013054261 0.08636365
## Medium 2.0688642 0.2155638 0.02577319 0.008188235 0.04814687
## Population Price Age Education UrbanYes USYes
## Good 0.002381584 0.03919383 0.02364099 0.11858296 0.7821109 1.0365972
## Medium 0.001202848 0.02286454 0.01503519 0.06840688 0.4096022 0.5265365
##
## Residual Deviance: 302.6034
## AIC: 346.6034
## Good Medium
## (Intercept) -38.913962021 -12.178929923
## Sales 4.903289749 1.950678641
## CompPrice -0.466139802 -0.177632921
## Income -0.076350942 -0.041911735
## Advertising -0.537836790 -0.242011158
## Population -0.002085516 -0.001034355
## Price 0.481836809 0.188245600
## Age 0.237120207 0.101046165
## Education 0.031870046 0.040090249
## UrbanYes -1.601019544 -0.662270549
## USYes 0.595780229 0.452477868
ans = data.frame(ans)
ans$exp.Good = exp(ans$Good)
ans$exp.Medium = exp(ans$Medium)
ans
ans = round(ans, 2)
ans
# step 4: interpretation:
# exp.Medium for Sales = 7.03. It means all else constant, for unit increase
sales the odds of shifting Shelf location from
# Bad location to medium location increases by 7.03 times