Q1: Ans: data <- read.table(\"http://fisher.stat.wmich.edu/joe/Stat2600/GA/xmaty.text\",sep=\" \",header=TRUE) attach(data) head(data) y <- data[,7] xmat <- data[,1:6] > head(data) x1 x2 x3 x4 x5 x6 y 1 38.7 13.5 70.2 62.6 60.8 58.6 -12.7 2 69.0 75.2 48.7 43.2 68.6 64.7 -36.4 3 55.1 76.5 51.5 67.5 58.5 87.9 -53.9 4 77.3 84.7 48.5 79.5 74.2 93.9 -56.5 5 62.4 27.3 112.8 63.0 55.9 73.9 -83.8 6 49.5 47.8 42.9 79.4 53.0 83.7 -20.2 Q2: Ans: lmbest2 <- function(y,xmat){ # This returns R-squared and sigmahat for all linear # models of size 2 (2 x\'s). The results are sorted on R-squared. p <- length(xmat[1,]) coll <- c() for(i in 1:(p-1)){ for(j in (i+1):p){ fit <- lm(y ~ xmat[,i] + xmat[,j]) sfit <- summary(fit) tmp <- c(i,j,sfit$sigma,sfit$r.squared) coll <- rbind(coll,tmp) } } ind <- order(coll[,4],decreasing=TRUE) collf <- coll[ind,] colnames(collf) <- c(\"i\",\"j\",\"sigmahat\",\"R-squared\") ic <- length(collf[,1]) rownames(collf) <- rep(\"Model\",ic) return(collf) } Q3: Ans: lmbest2(y,xmat) Top 3 models are: For better model we need lower sigmahat and higher R-squared. Model 1 has lowest sigmahat and highest R-squared followed by Model 2 then model 3. Hence among these three Model 1 is the best fit and Model 3 is the worst fit and model 2 is in between the other two models. From the value of R-squared = 0.479 we can say that there are other models which are better fit because for good fits R-squared should be close to 1. Hence I would like to choose another models with more variables involved. Solution Q1: Ans: data <- read.table(\"http://fisher.stat.wmich.edu/joe/Stat2600/GA/xmaty.text\",sep=\" \",header=TRUE) attach(data) head(data) y <- data[,7] xmat <- data[,1:6] > head(data) x1 x2 x3 x4 x5 x6 y 1 38.7 13.5 70.2 62.6 60.8 58.6 -12.7 2 69.0 75.2 48.7 43.2 68.6 64.7 -36.4 3 55.1 76.5 51.5 67.5 58.5 87.9 -53.9 4 77.3 84.7 48.5 79.5 74.2 93.9 -56.5 5 62.4 27.3 112.8 63.0 55.9 73.9 -83.8 6 49.5 47.8 42.9 79.4 53.0 83.7 -20.2 Q2: Ans: lmbest2 <- function(y,xmat){ # This returns R-squared and sigmahat for all linear # models of size 2 (2 x\'s). The results are sorted on R-squared. p <- length(xmat[1,]) coll <- c() for(i in 1:(p-1)){ for(j in (i+1):p){ fit <- lm(y ~ xmat[,i] + xmat[,j]) sfit <- summary(fit) tmp <- c(i,j,sfit$sigma,sfit$r.squared) coll <- rbind(coll,tmp) } } ind <- order(coll[,4],decreasing=TRUE) collf <- coll[ind,] colnames(collf) <- c(\"i\",\"j\",\"sigmahat\",\"R-squared\") ic <- length(collf[,1]) rownames(collf) <- rep(\"Model\",ic) return(collf) } Q3: Ans: lmbest2(y,xmat) Top 3 models are: For better model we need lower sigmahat and higher R-squared. Model 1 has lowest sigmahat and highest R-squared followed by Model 2 then model 3. Hence among these three Model 1 is the best fit and Model 3 is the worst fit and model 2 is in between the other two models. From the value of R-squared = 0.479 we can say that there are other models which are better fit because for good fits R-squared should be close to 1. Hence I would like to cho.
Q1: Ans: data <- read.table(\"http://fisher.stat.wmich.edu/joe/Stat2600/GA/xmaty.text\",sep=\" \",header=TRUE) attach(data) head(data) y <- data[,7] xmat <- data[,1:6] > head(data) x1 x2 x3 x4 x5 x6 y 1 38.7 13.5 70.2 62.6 60.8 58.6 -12.7 2 69.0 75.2 48.7 43.2 68.6 64.7 -36.4 3 55.1 76.5 51.5 67.5 58.5 87.9 -53.9 4 77.3 84.7 48.5 79.5 74.2 93.9 -56.5 5 62.4 27.3 112.8 63.0 55.9 73.9 -83.8 6 49.5 47.8 42.9 79.4 53.0 83.7 -20.2 Q2: Ans: lmbest2 <- function(y,xmat){ # This returns R-squared and sigmahat for all linear # models of size 2 (2 x\'s). The results are sorted on R-squared. p <- length(xmat[1,]) coll <- c() for(i in 1:(p-1)){ for(j in (i+1):p){ fit <- lm(y ~ xmat[,i] + xmat[,j]) sfit <- summary(fit) tmp <- c(i,j,sfit$sigma,sfit$r.squared) coll <- rbind(coll,tmp) } } ind <- order(coll[,4],decreasing=TRUE) collf <- coll[ind,] colnames(collf) <- c(\"i\",\"j\",\"sigmahat\",\"R-squared\") ic <- length(collf[,1]) rownames(collf) <- rep(\"Model\",ic) return(collf) } Q3: Ans: lmbest2(y,xmat) Top 3 models are: For better model we need lower sigmahat and higher R-squared. Model 1 has lowest sigmahat and highest R-squared followed by Model 2 then model 3. Hence among these three Model 1 is the best fit and Model 3 is the worst fit and model 2 is in between the other two models. From the value of R-squared = 0.479 we can say that there are other models which are better fit because for good fits R-squared should be close to 1. Hence I would like to choose another models with more variables involved. Solution Q1: Ans: data <- read.table(\"http://fisher.stat.wmich.edu/joe/Stat2600/GA/xmaty.text\",sep=\" \",header=TRUE) attach(data) head(data) y <- data[,7] xmat <- data[,1:6] > head(data) x1 x2 x3 x4 x5 x6 y 1 38.7 13.5 70.2 62.6 60.8 58.6 -12.7 2 69.0 75.2 48.7 43.2 68.6 64.7 -36.4 3 55.1 76.5 51.5 67.5 58.5 87.9 -53.9 4 77.3 84.7 48.5 79.5 74.2 93.9 -56.5 5 62.4 27.3 112.8 63.0 55.9 73.9 -83.8 6 49.5 47.8 42.9 79.4 53.0 83.7 -20.2 Q2: Ans: lmbest2 <- function(y,xmat){ # This returns R-squared and sigmahat for all linear # models of size 2 (2 x\'s). The results are sorted on R-squared. p <- length(xmat[1,]) coll <- c() for(i in 1:(p-1)){ for(j in (i+1):p){ fit <- lm(y ~ xmat[,i] + xmat[,j]) sfit <- summary(fit) tmp <- c(i,j,sfit$sigma,sfit$r.squared) coll <- rbind(coll,tmp) } } ind <- order(coll[,4],decreasing=TRUE) collf <- coll[ind,] colnames(collf) <- c(\"i\",\"j\",\"sigmahat\",\"R-squared\") ic <- length(collf[,1]) rownames(collf) <- rep(\"Model\",ic) return(collf) } Q3: Ans: lmbest2(y,xmat) Top 3 models are: For better model we need lower sigmahat and higher R-squared. Model 1 has lowest sigmahat and highest R-squared followed by Model 2 then model 3. Hence among these three Model 1 is the best fit and Model 3 is the worst fit and model 2 is in between the other two models. From the value of R-squared = 0.479 we can say that there are other models which are better fit because for good fits R-squared should be close to 1. Hence I would like to cho.