Operation Management Case/ Statistics

profileAnnie.steller
VS_case.r

library(MASS) data("Boston") colnames(Boston) model_full <- lm(medv~., data = Boston) summary(model_full) model_1 <- lm(medv~crim+zn, data = Boston) # Manually select summary(model_full) summary(model_1) AIC(model_full); BIC(model_full) AIC(model_1); BIC(model_1) # Best Subset install.packages('leaps') library(leaps) # regsubsets only takes data frame as input subset_result <- regsubsets(medv~., data=Boston, nbest=2, nvmax = 14) summary(subset_result) plot(subset_result) # Backward Elimination nullmodel <- lm(medv~1, data=Boston) summary(model_full) # has fitted: model_full <- lm(medv~., data=Boston) model_step_b <- step(model_full, direction='backward') # Forward Selection model_step_f <- step(nullmodel, scope=list(lower=nullmodel, upper=model_full), direction='forward') # Stepwise Selection model_step_s <- step(nullmodel, scope = list(lower=nullmodel, upper=model_full), direction='both')