Loading...

Messages

Proposals

Stuck in your homework and missing deadline? Get urgent help in $10/Page with 24 hours deadline

Get Urgent Writing Help In Your Essays, Assignments, Homeworks, Dissertation, Thesis Or Coursework & Achieve A+ Grades.

Privacy Guaranteed - 100% Plagiarism Free Writing - Free Turnitin Report - Professional And Experienced Writers - 24/7 Online Support

Aeb3133

17/12/2020 Client: saad24vbs Deadline: 7 Days

--- title: "Lab 6" author: "Your name here" date: "Write the date here" output: pdf_document --- The function regsubsets() in the library `leaps` can be used for regression subset selection. Thereafter, one can view the ranked models according to different scoring criteria by plotting the results of regsubsets(). Before using the function for the first time you will need to install the `leaps` package. One way to do this is to type `install.packages("leaps")` in the console window. It is probably best not to put this command in your R Markdown file since you only need to run the command once (not every time you knit your document). Recall that in R Markdown we can display R code without running it by placing `eval=FALSE` at the top of the R code chunk. ```{r eval=FALSE} install.packages("leaps") ``` If you have installed the package correctly then the following commands should load in the `leaps` and `MASS` packages. ```{r} library(leaps) library(MASS) ``` IF YOU GET AN ERROR IN THE PREVIOUS R CODE CHUNK PLEASE REREAD THE ABOVE PARAGRAPHS. ## Example 1: Best-subsets Regression The `Boston` dataset within the `MASS` package contains information collected by the U.S Census Service concerning housing in the area of Boston Massachusetts. It was obtained from the StatLib archive (http://lib.stat.cmu.edu/datasets/boston), and has been used extensively throughout the literature to benchmark algorithms. There are 14 attributes in each case of the dataset. They are: * CRIM - per capita crime rate by town * ZN - proportion of residential land zoned for lots over 25,000 sq.ft. * INDUS - proportion of non-retail business acres per town. * CHAS - Charles River dummy variable (1 if tract bounds river; 0 otherwise) * NOX - nitric oxides concentration (parts per 10 million) * RM - average number of rooms per dwelling * AGE - proportion of owner-occupied units built prior to 1940 * DIS - weighted distances to five Boston employment centres * RAD - index of accessibility to radial highways * TAX - full-value property-tax rate per $10,000 * PTRATIO - pupil-teacher ratio by town * B - 1000(Bk - 0.63)^2 where Bk is the proportion of blacks by town * LSTAT - % lower status of the population * MEDV - Median value of owner-occupied homes in $1000's ```{r} summary(Boston) dim(Boston) ``` Use the median home value (`medv`) as the dependent variable and determine which of the five independent variables (`nox`, `rm`, `age`, `crim`, `tax`) should be included in the regression model using the`regsubsets` command to perform "Best-subsets Regression". ```{r} BSR=regsubsets(medv~nox+rm+age+crim+tax, data=Boston) ``` Once we have used the `regsubsets` command we can view a plot that shows us which variables are significant according to the adjusted R-square. ```{r} plot(BSR, scale="adjr2") ``` Here black indicates that a variable is included in the model, while white indicates that they are not. The model containing all variables minimizes the adjusted R-square criteria as can be determined by looking at the top row of the plot. We can see that the regression equation with the highest adjusted R-square includes every variable except `nox`. We can verify that the best number of variables is 4 by using the following code: ```{r} reg.summary=summary(BSR) which.max(reg.summary$adjr2) ``` The resulting best fit using 4 variables can be shown using the `coef` function: ```{r} coef(BSR,4) ``` The predict command is not set up to handle the `regsubsets` so we create a function that predicts for us. ```{r} predict.regsubsets = function(object, newdata, id, ...) { form = as.formula(object$call[[2]]) mat = model.matrix(form, newdata) coefi = coef(object, id) mat[, names(coefi)] %*% coefi } ``` Here we will make a prediction based on the original data set with the number of variables set to 4. ```{r} pred=predict.regsubsets(BSR,Boston, id=4) head(pred) ``` ## Example 2: One variable-at-a-time Models As you should recall from class going through every unique model can be computationally expensive. Therefore, we can consider some other methods that consider adding or subtracting one variable-at-a-time. The methods that consider one-variable-at-a-time are: * Backward elimination * Forward selection * Stepwise regression. The above three methods are useful when the number of dependent variables is large and it is not feasible to fit all possible models. In this case, it is more efficient to use a search algorithm (e.g., Forward selection, Backward elimination and Stepwise regression) to find the best model. The R function step() can be used to perform variable selection. To perform forward selection we need to begin by specifying a starting model and the range of models which we want to examine in the search. ```{r} null=lm(medv~1, data=Boston) null ``` ```{r} full=lm(medv~nox+rm+age+crim+tax, data=Boston) full ``` We can perform forward selection using the command: ```{r} step(null, scope=list(lower=null, upper=full), direction="forward") ``` This tells R to start with the null model and search through models lying in the range between the null and full model using the forward selection algorithm. According to this procedure, the best model is the one that includes the variables Taxes, Size, Lot and Baths. We can perform backward elimination on the same data set using the command: ```{r} step(full, data=Boston, direction="backward") ``` and stepwise regression using the command: ```{r} stepwise=step(null, scope = list(upper=full), data=Boston, direction="both") stepwise ``` All of the algorithms yield equivalent results in this simple example. Let's make a prediction based on the stepwise model. ```{r} pred_stepwise=predict(stepwise,Boston) head(pred_stepwise) ``` ## Problem 1: Carseat Sales Revisited Again Your challenge is to use the data from the inclass Kaggle challenge (https://www.kaggle.com/t/8f161e4d717f443a8bfecae2de5bf872). First read in the data and get rid of the observation IDs. ```{r} data1=read.csv("Carseats_training.csv") data1$ID=NULL ``` Now run the following command to perform best-subsets regression. ```{r} BSR1=regsubsets(Sales~., data=data1) ``` a. Make a plot of the results according to adjusted R-square. (5 points) ```{r} # Your code here ``` b. Find out how many variables are used in the best subset according to the adjusted R-square. (5 points) ```{r} # Your code here ``` c. State the coefficients of the model in the aforementioned best subset. (5 points) ```{r} # Your code here ``` d. Perform stepwise regression on this data. (5 points) ```{r} # Your code here ``` e. Compare the variables selected from stepwise regression versus the variables selected from the best subsets approach. Which model would you trust the most? Why? (5 points) *Your answer here.* f. Make predictions on your test set and upload the results to kaggle. (5 points) ```{r} test=read.csv("Carseats_testing.csv") test$Sales=rep(1,80) # Your code here ``` g. Report your RMSE as measured by Kaggle. (7 points) *Your answer here.* h. Is your submission submitted properly submitted to Kaggle? You will be graded based upon whether or not your name is on the leaderboard with a RMSE that is consistent with what you reported in the previous part. (7 points) ## Problem 2: Restaurant Revenue Prediction Revisited Your challenge is to use the data from the inclass Kaggle challenge (https://www.kaggle.com/t/b97c47b1cc7742b2b0920b078b04d88e) and make a submission. Read in the data. ```{r} data2=read.csv("RR_train.csv") ``` a. Fit a backward elimination model. (5 points) ```{r} # Your code here ``` b. Predict the test set using this model and upload to kaggle. (5 points) ```{r} # Your code here ``` c. What is your resulting RMSE from the previous part as reported by kaggle? (7 points) *Your answer here.* d. Did you make a submission properly to Kaggle? You will be graded based upon whether or not your name is on the leaderboard with a RMSE that is consistent with what you reported in the previous part. (7 points) e. Fit a model using best-subsets regression. (5 points) ```{r} # Your code here ``` f. Predict the test set using the model with the highest adjusted R-square and upload to kaggle. (8 points) ```{r} # test2$revenue=rep(1,37) # Your code here ``` g. What is your resulting RMSE from the previous part as reported by kaggle? (7 points) *Your answer here.* h. Did you make a submission properly to Kaggle? You will be graded based upon whether or not your name is on the leaderboard with a RMSE that is consistent with what you reported in the previous part. (7 points) ## Problem 3: Markdown Now you will modify your document so that it is in pristine format. Knit the document as a pdf. You will need to submit this file and the pdf you created. Submit these two files to blackboard. Partial credit will not be given for this problem. (5 points)


Applied Sciences

Architecture and Design

Biology

Business & Finance

Chemistry

Computer Science

Geography

Geology

Education

Engineering

English

Environmental science

Spanish

Government

History

Human Resource Management

Information Systems

Law

Literature

Mathematics

Nursing

Physics

Political Science

Psychology

Reading

Science

Social Science

Home

Blog

Archive

Contact

google+twitterfacebook

Copyright © 2019 HomeworkMarket.com

Homework is Completed By:

Writer Writer Name Amount Client Comments & Rating
Instant Homework Helper

ONLINE

Instant Homework Helper

$36

She helped me in last minute in a very reasonable price. She is a lifesaver, I got A+ grade in my homework, I will surely hire her again for my next assignments, Thumbs Up!

Order & Get This Solution Within 3 Hours in $25/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 3 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 6 Hours in $20/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 6 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 12 Hours in $15/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 12 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

6 writers have sent their proposals to do this homework:

Best Coursework Help
Helping Hand
Homework Guru
Top Essay Tutor
University Coursework Help
Writer Writer Name Offer Chat
Best Coursework Help

ONLINE

Best Coursework Help

I am an Academic writer with 10 years of experience. As an Academic writer, my aim is to generate unique content without Plagiarism as per the client’s requirements.

$35 Chat With Writer
Helping Hand

ONLINE

Helping Hand

I am an Academic writer with 10 years of experience. As an Academic writer, my aim is to generate unique content without Plagiarism as per the client’s requirements.

$35 Chat With Writer
Homework Guru

ONLINE

Homework Guru

Hi dear, I am ready to do your homework in a reasonable price and in a timely manner.

$37 Chat With Writer
Top Essay Tutor

ONLINE

Top Essay Tutor

I have more than 12 years of experience in managing online classes, exams, and quizzes on different websites like; Connect, McGraw-Hill, and Blackboard. I always provide a guarantee to my clients for their grades.

$40 Chat With Writer
University Coursework Help

ONLINE

University Coursework Help

Hi dear, I am ready to do your homework in a reasonable price.

$37 Chat With Writer

Let our expert academic writers to help you in achieving a+ grades in your homework, assignment, quiz or exam.

Similar Homework Questions

Privilege power and difference 3rd edition pdf - Acts chapter 3 questions and answers - V shaped valley diagram - Homeschool speech and debate - Pharmacology case study-ReWk2 - The three main monetary policy tools are - Garbage record book entries example - Celf p2 age range - Juegan ustedes al baloncesto en la universidad - How to make sieve analysis graph - The boy in the striped pajamas chapter 13 - Solar Energy Commercialization - Cjjs - Quiz - How to write article critique apa style - Knight company reports the following costs and expenses in may - Neonatal abstinence syndrome nursing diagnosis - American Higher Education - Review writing - Anu supersearch - Camhs crisis team oxford - Work vs displacement graph - Do not go gentle into that good night figurative language - Van der westen speedster - Columbia southern university tax form - Frequency division multiplexing advantages and disadvantages - Graen and uhl bien 1995 - Border crossings catherine cucinella pdf - Time warner cable mission statement and goals - Reading books is better than watching tv - Technical English 7 - Turn the other cheek poe - What other symbols represent human sexuality reproduction and fertility - Help Part 2 - Live wire hot rod shop follows the revenue recognition principle - Research Paper- project charter process. - Week 6 discussion responses - Comparing data distributions worksheet - Respond to 2 Colleagues 1 paragraph each Wk7D2 - How to prove a parallelogram in coordinate geometry - It's 7 o clock in the morning song - Origins reflection powerpoint - Information taken from an existing classified - Hunger games victors interview - LEGAL Forum Week 1# - Honey and mumford learning style - Stonham aspal primary school - C226 task 2 - Morrisons cooked meat counter - Job hazard analysis for welding - How to rotate a triangle 90 degrees around the origin - The tendency to revert to a fixed (or modal) action pattern is called instinctive drift. - Psychology - The following are all methods of analyzing capital investments except - Vocal techniques gcse music - Research Paper- infotech in global enconomy - How pearl button was kidnapped sparknotes - Cisco aci interview questions and answers pdf - Etruscan artisans particularly excelled at which of the following - Https qbo intuit com redir testdrive - Tooth decay science fair project hypothesis - Billy elliot practice essay questions - Thermoplastic composites manufacturing process - Colgate max fresh global brand roll out case solution - Folding screen with indian wedding and flying pole - Tae10 training package introductory sections - Character analysis of edie in how i met my husband - Some question in economic - Acid base titration experiment - Personal development blueprint - Wacc market value of equity - Amy, age 19 and single, has $8,050 of wages, $800 of interest, and $350 of self-employment income. - Healthcare reimbursement - Accounting Information Systems - Curvilinear motion examples in sport - Prefatory parts of a report - Meezan bank car financing - Reserved for hifsa - Xe full electron configuration - Nathan price poisonwood bible - Solahart hot water not working - Graphpad prism 5 serial number - Productivity is monitoring performance, comparing it with goals, and taking corrective action. - Project implementation plan template word - Information security policy - Marketing - Answer to Peer, 2 references APA, less 5 % similarities - Overpaid rent refund victoria - Boston college eagle one card - Warnerwoods company - 1.1 3 quiz what is a function apex answers - Viscously damped free vibration - .I need 300 words on "The Effective Use of the Audit Risk Model at the Account Level - Is neon metal nonmetal or metalloid - Iturralde v hilo medical center usa summary - Cj industries and heavey pumps case study - Factors that led to the great depression - I need help with a writing assignment in Managerial 301 - 3 minutes presentation ppt - Informative speech about air pollution