# We Helped With This R Studio Economics Homework: Have A Similar One?

SOLVED
Category Economics R | R Studio Graduate Solved Economics Rstudio Homework

## Short Assignment Requirements

EXERCISE 3Purpose: To learn how to use the â€œValidation Setâ€ approach to test the performance of a Cross-Validated Lasso model versus a full regression model versus a best subset regression model. We will be using R for this exercise. Your starter R program is EX3_Lasso.R and can be found on Canvas. Use set.seed = (1) to determine the 50% random split of the data into the training and test data sets. In addition to the hints that I provide to you in the program, I would suggest that you look at Labs 1 and 2 in Chapter 6 of the downloadable pdf file of the book An Introduction to Statistical Learning with Applications in R by James, et al.This exercise is due Tuesday, February 19 on CANVAS.a) Provide a L1 Norm graph of the Lasso regression coefficients as the L1 Norm decreases. What is this graph showing?b) Provide a Cross-Validation graph of Lambda. What is this graph showing?c) The input variables chosen by the best Lasso on the training data set are _______________________________________________________________.d) Test MSE for Best Lasso = _________________.The first four parts should be directly derivable from the EX3_Lasso.R program that I have provided. The following parts are going to require some programming ingenuity on your part. I had to fumble around a little bit to get things to work but the following parts are definitely doable.e) Test MSE for OLS using the full set of inputs = _________________.f) Use the â€œregsubsetsâ€ routine to determine the 8 best inputs for a linear regression using the training data set. These variables are ___________________________ _________________________________________________________________.g) Test MSE for Best Subset regression = ___________________.h) Which technique provided the best test (Validation set) results? We you surprised?i) Report the R code that you used to generate the answers to the above sections.

## Assignment Code

``````
#
install.packages("ISLR")
library(ISLR)
attach(Hitters)
names(Hitters)
dim(Hitters)
sum(is.na(Hitters\$Salary))
Hitters=na.omit(Hitters)
dim(Hitters)
sum(is.na(Hitters))

library(glmnet)
grid=10^seq(10,-2,length=100)
x=model.matrix(Salary~.,Hitters)[,-1]
y=Hitters\$Salary
set.seed(1)
train=sample(1:nrow(x), nrow(x)/2)
test=(-train)
y.test=y[test]

# The Lasso

lasso.mod=glmnet(x[train,],y[train],alpha=1,lambda=grid)
plot(lasso.mod)
set.seed(1)
cv.out=cv.glmnet(x[train,],y[train],alpha=1)
plot(cv.out)
bestlam=cv.out\$lambda.min
bestlam
lasso.pred=predict(lasso.mod,s=bestlam,newx=x[test,])
mean((lasso.pred-y.test)^2)
out=glmnet(x,y,alpha=1,lambda=grid)
lasso.coef=predict(out,type="coefficients",s=bestlam)[1:20,]
lasso.coef
lasso.coef[lasso.coef!=0]

# OLS on full model

# OLS on Best Subset Model derived from Training data set with 8 inputs
library(leaps)

``````

## Assignment Description

ECO 6380                                                                                           Prof. Tom Fomby

Predictive Analytics for Economists                                                  Spring 2019

EXERCISE 4

Purpose: To learn how to use R to “validate” Principal Component (PC) regressions.

First we will use 10-fold cross-validation to determine the optimal number of Principal Components to use in the PC regression and then apply it to the test data set while collecting the test MSE, test RMSE, and test MAE.  Then we will do the same for the full OLS Boston Housing regression.  The program to use for this exercise is EX4.R.  The data we are going to be using is the Boston Housing data.  In the PC model we will be constructing PCs from the standardized versions of all of the input variables except for the indicator variable CHAS.  In PC analysis we usually use only numeric inputs not categorical ones.  Essentially in this exercise, all you have to do is run the R program and cut and paste output.  This exercise is due Tuesday, February 19 on CANVAS.

a)   Based upon the entire Boston Housing data set, report the Importance of Principal Components table.  (Be sure you take the time to understand the contents of this table.)

b)  The percentage of the total variation explained by the first four components is ______________%.

c)   Report the Skree plot based on the entire Boston Housing data set.  Which row of the Importance of Principal Components table is being used to form the plot?  _________.

d)  Using the entire Boston Housing data set, report the 10-fold Cross-Validation graph of RMSEP versus Number of Components.  What is the meaning of this graph?  At what number of components is the majority of the reduction in RMSEP attained.

e)   Report the TEST 10-fold Cross-Validation graph of RMSEP versus the Number of Components.  Is there much difference in this RMSEP graph and the one we obtained using the entire Boston Housing data set?  Explain your answer.

f)   Report the following TEST data set numbers for PC4:

C4MSE = _______________.

C4RMSE = ______________.

C4MAE = _______________.

g)  Report the following TEST data set numbers for PC5:

C5MSE = _______________.

C5RMSE = ______________.

C5MAE = _______________.

h)  Report the following TEST data set numbers for full OLS:

C4MSE = _______________.

C4RMSE = ______________.

C4MAE = _______________.

i)    What is your conclusion about the relative merits of the PC regressions and full OLS based on the results of the Validation Data Set experience?  Do the results make sense?  Explain your answer.

Is it free to get my assignment evaluated?

Yes. No hidden fees. You pay for the solution only, and all the explanations about how to run it are included in the price. It takes up to 24 hours to get a quote from an expert. In some cases, we can help you faster if an expert is available, but you should always order in advance to avoid the risks. You can place a new order here.

How much does it cost?

The cost depends on many factors: how far away the deadline is, how hard/big the task is, if it is code only or a report, etc. We try to give rough estimates here, but it is just for orientation (in USD):

 Regular homework \$20 - \$150 Advanced homework \$100 - \$300 Group project or a report \$200 - \$500 Mid-term or final project \$200 - \$800 Live exam help \$100 - \$300 Full thesis \$1000 - \$3000

How do I pay?

Credit card or PayPal. You don't need to create/have a Payal account in order to pay by a credit card. Paypal offers you "buyer's protection" in case of any issues.

Why do I need to pay in advance?

We have no way to request money after we send you the solution. PayPal works as a middleman, which protects you in case of any disputes, so you should feel safe paying using PayPal.

Do you do essays?

No, unless it is a data analysis essay or report. This is because essays are very personal and it is easy to see when they are written by another person. This is not the case with math and programming.

Why there are no discounts?

It is because we don't want to lie - in such services no discount can be set in advance because we set the price knowing that there is a discount. For example, if we wanted to ask for \$100, we could tell that the price is \$200 and because you are special, we can do a 50% discount. It is the way all scam websites operate. We set honest prices instead, so there is no need for fake discounts.

Do you do live tutoring?

No, it is simply not how we operate. How often do you meet a great programmer who is also a great speaker? Rarely. It is why we encourage our experts to write down explanations instead of having a live call. It is often enough to get you started - analyzing and running the solutions is a big part of learning.

What happens if I am not satisfied with the solution?

Another expert will review the task, and if your claim is reasonable - we refund the payment and often block the freelancer from our platform. Because we are so harsh with our experts - the ones working with us are very trustworthy to deliver high-quality assignment solutions on time.

Customer Feedback

"Thanks for explanations after the assignment was already completed... Emily is such a nice tutor! "

Order #13073

Find Us On