Mgt 819 homework - suppose we want to create a pivot table


Read ISL p.43-51, the Lab section of chapter 1. This is a good getting-started guide to R. To follow along you will need to download the data sets from Data Sets and Figures from the ISL website (https://www-bcf.usc.edu/~gareth/ISL/data.html).

Return to the R script file provided for Lecture 1 and review the code.

2. Answer Q8 of ISL Chapter 2. You can skip part c(vi).

3. Q9 of ISL Chapter 2.

4. Q10 of ISL Chapter 2.

5. (Pivot tables in R) "UC Salary 2014.xlsx" contains 2014 salary information for UC Irvine and Riverside, and it is extracted from https://ucpay.globl.org/.

a) Read the data into R and report the variables in the dataset.

Suppose we want to create a pivot table for the median gross salary for various combinations of campus and titles that include the term "PROF-HCOMP". In other words:

While Excel's native pivot table can compute the average salary for each campus-title combination, it cannot do the same for statistics like the median. R on the other hand can do it using any statistic. We will create the table above using the following steps.

b) Create a new dataset in R by selecting the rows of the salary table that contain the term "PROF-HCOMP" in the TITLE field. Note that "HS CLIN PROF-HCOMP" also contains the term, for example. The command grep("PROF-HCOMP", X) will return TRUE for each entry in the variable X that contains the term, and FALSE otherwise. How would you use it to create the new dataset?

c) The TITLE field of the subsetted data contains only titles with the terms "PROF-HCOMP". Yet if you type in "levels(newdata$TITLE)" you will still get a list of all the original titles. What happens if you reset the factor levels of TITLE by entering "newdata$TITLE = factor(newdata$TITLE)"?

d) Create the pivot table above using the aggregate() function introduced in the lecture on hierarchical clustering. To report median salary by campus-title combination, simply enter "aggregate(GROSS~CAMPUS+TITLE, newdata, median)". You can replace the median function with any other statistic e.g. mean().

6. (Based on DMBI p190, problem 9.4) The file Modified Corolla.xlsx contains data on used Toyota Corollas on sale during late summer of 2004 in the Netherlands. The data is a version of the example we studied in class. It has 1,436 observations containing attributes such as Price, Age, Kilometers, HP, and other specifications. The goal is to predict the price of a used Corolla based on its specifications using a regression tree.

a) Read the file into R as the dataset "car". Use the is.factor() function to check if Fuel_Type is stored as a categorical variable. If it is not, tell R that it should be treated as such using the command "car$Fuel_Type = factor(car$Fuel_Type)".

b) Split the dataset 80/20 into training/validation.

b) Fit a regression tree to the output variable Price and all other input variables. Use the minimum error tree to score the test data, and draw the tree. What are the two most important variables for predicting the car's price? What is the RMS error for the test set?

c) Fit a linear regression model to the same training set, and use Best Subset search to find the best subset of variables for a given subset size. Based on the adjusted R2 output you should see that 15 to 17 variables are best. Recall that neither measure depends on the validation set. Hence use the validation RMS error to choose between these models. Which variables are dropped by the chosen model? Are they used in the regression tree? Compare the test RMS error of the chosen model to the test error of the tree.

Hint: Everything you need for this question is in the script files for the lectures on linear regression and regression trees. Consult also ISL sections 3.6.2-3.6.3 and 8.3.2.

Attachment:- Assignment.rar

Request for Solution File

Ask an Expert for Answer!!
Basic Statistics: Mgt 819 homework - suppose we want to create a pivot table
Reference No:- TGS01606069

Expected delivery within 24 Hours