Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I solved (a),(b) but struggling with (c), (d), (e) in R. Could you explain it in R please? Data: y

Hello, I solved (a),(b) but struggling with (c), (d), (e) in R. Could you explain it in R please?

Data:

y<-runif(1000,min=0, max=23) x1<-runif(1000, min=-3, max=5) x2<-runif(1000, min=-3, max=5) x3<-runif(1000, min=-3, max=5) x4<-runif(1000, min=-3, max=5) x5<-runif(1000, min=-3, max=5) x6<-runif(1000, min=-3, max=5) x7<-runif(1000, min=-3, max=5) x8<-runif(1000, min=-3, max=5) x9<-runif(1000, min=-3, max=5) x10<-runif(1000, min=-3, max=5) df.train<-data.frame(y,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10)

(a) Split the data into a training set with 900 observations and a test set with the remaining observations.

my solution:

to <- sample(1:nrow(df.train), 900) train<-df.train[to,] test<-df.train[-to,]

(b) Build a random forest with the training data; call it rf

my solution

library(randomForest) rf <- randomForest(y~.,data=train, importance = TRUE)

(c) Now let's explicitly test how important each predictor is using the permutation idea. Use a for loop so that the i th time through the loop, you permute the values of the i th predictor, rebuild the random forest, predict on the test set and record the MSE. Call the vector of MSEs mse.perm.

(d) Repeat part (c) but instead of permuting the i th predictor on the i th iteration, simply remove it from the data frame, rebuild the random forest, predict on the test set and calculate the MSE. Call this vector of MSEs mse.loo and create the same plot as above. Do these MSEs look more like those in part (b) or more like those in part (c)? Which would you trust more?

(e) Explore the original data and see if you can determine what might be causing the difference you see. Pay close attention to those variables that are receiving the most different importance scores.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

A First Course in Differential Equations with Modeling Applications

Authors: Dennis G. Zill

11th edition

1305965728, 978-1305965720

More Books

Students also viewed these Mathematics questions

Question

What is cultural tourism and why is it growing?

Answered: 1 week ago

Question

Define the term utility software and give two examples.

Answered: 1 week ago