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 #### nfl.samp obtains a sample of 168 integers from 1:335 w/out replacement #### Selects all rows where id is either in nfl.samp (train) or not (valid) #### Selects all columns: nflcomb[rows,cols] set.seed(9876) #### Will produce same sample in future runs nfl.samp <- sample(1:length(Weight),168,replace=FALSE) nfl.train <- nflcomb[nfl.samp,] nfl.valid <- nflcomb[-nfl.samp,] #### 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))