############################################# # Another Baseball Examples # ############################################# Baseball = read.csv("RunsPerGame.csv",header=T) model1 = lm(R.G ~ AVG + OBP, data=Baseball) model2 = lm(R.G ~ SLG+ OBP,data=Baseball) summary(model1) summary(model2) confint(model2) ############################################# # Sales P1 and P2 Example # ############################################# SalesData = read.csv("PricesSales.csv",header=T) names(SalesData) attach(SalesData) modelP1 = lm(Sales~p1) # model with just p1 modelP2 = lm(Sales~p2) # model with just p2 modelP1P2 = lm(Sales~p1+p2) # model with p1 and p2 plot(modelP1P2$fitted,Sales,pch=19,col="green",xlab="y.hat(MLR:p1 and p2)",ylab="y=Sales") abline(0,1,col="blue",lwd=2) par(mfrow=c(1,3)) # Set up a plotting window with 3 plots in one row... plot(modelP1$fitted,Sales,pch=19,col="red",xlab="y.hat(SLR:p1)",ylab="y=Sales") abline(0,1,col="blue",lwd=2) plot(modelP2$fitted,Sales,pch=19,col="red",xlab="y.hat(SLR:p2)",ylab="y=Sales") abline(0,1,col="blue",lwd=2) plot(modelP1P2$fitted,Sales,pch=19,col="green",xlab="y.hat(MLR:p1 and p2)",ylab="y=Sales") abline(0,1,col="blue",lwd=2) ############################################# # Supervisor Example # ############################################# rm(list=ls()) # clean the workspace Data = read.csv("Supervisor.csv",header=T) attach(Data) pairs(Data,col="blue",pch=19) Fullmodel = lm(Y~X1+X2+X3+X4+X5+X6) summary(Fullmodel) names(Fullmodel) confint(Fullmodel) Garbage = matrix(rnorm(30*6),30,6) Garbagemodel = lm(Y~Garbage) summary(Garbagemodel) Reducedmodel = lm(Y~X1+X3) anova(Fullmodel,Reducedmodel) ## Performs the comparison between two models with the partial F-test Xfuture <- data.frame(X1=c(40,50,60,70),X3=c(40,50,60,70)) predict(Reducedmodel, Xfuture, interval = "prediction",se.fit=T,level=0.99)