nflcomb <- read.csv("http://www.stat.ufl.edu/~winner/sta4210/mydata/nfl_combine.csv", header=TRUE) attach(nflcomb); names(nflcomb) #### Obtain the Training and Validation Samples, generated in EXCEL #### Selects all rows where Sample is 1 or 2, and all columns #### nflcomb[rows,cols] nfl.train <- nflcomb[Sample==1,] nfl.valid <- nflcomb[Sample==2,] #### Fit the Regression model for the Training and Validation Samples train.mod <- lm(Weight ~ Height + ArmLng + HandLng, data=nfl.train) valid.mod <- lm(Weight ~ Height + ArmLng + HandLng, data=nfl.valid) summary(train.mod) summary(valid.mod) #### Compute the fitted values for Validation sample from Model fitted #### to Training Sample (Note that X1, X2, X3 are in Columns 4, 5, 6) #### and Y is in Column 7 #### Compute MSEP yhat.val <- predict(train.mod,nfl.valid[,4:6]) e.val <- nfl.valid[,7] - yhat.val (MSEP <- sum(e.val^2)/nrow(nfl.valid))