Sei sulla pagina 1di 2

# Multiple regression example using OmniPower energy bar sales data

# Variables in the data set are:

# Sales - number of OmniPower bars sold in a month

# Price - price per bar in cents

# Promotion - monthly budget for in-store prmotional expenses

# import the data set

energy.data <- read.csv("OmniPower.csv",header=T)

# take a look at the data

summary(energy.data)

plot(energy.data)

cor(energy.data)

# set up the regression model

energy.model <- lm( Sales ~ Price + Promotion, data = energy.data)

energy.model

# run ANOVA to find SSR and SST

anova(energy.model)

SST=28153486+11319245+12620947

SSR=28153486+11319245

SSR/SST

# run summary of model results

summary(energy.model)

# plot residuals against fitted y-values

plot(energy.model$fitted.values,energy.model$residuals, xlab="Predicted Sales", ylab="Residuals")


abline(h=0)

# plot residuals against price

plot(energy.data$Price,energy.model$residuals, xlab="Price", ylab="Residuals")

abline(h=0)

# plot residuals against promotion

plot(energy.data$Promotion,energy.model$residuals, xlab="Promotion", ylab="Residuals")

abline(h=0)

# save standardized residuals

energy.st.res <- rstandard(energy.model)

# QQ plot for standardized residuals

qqnorm(energy.st.res, ylab="Standardized Residuals", xlab="Normal Scores")

qqline(energy.st.res)

# produce Cook's Distance values for the model

cooks.distance(energy.model)

# produce summary of diagnostic output

plot(energy.model)

Potrebbero piacerti anche