# Help with R Programming

Page 1 of 1

## 1 Replies - 498 Views - Last Post: 18 June 2017 - 02:22 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=404679&amp;s=33644836861a896f033638719be6ec7e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 program94

Reputation: 0
• Posts: 42
• Joined: 19-April 14

# Help with R Programming

Posted 18 June 2017 - 12:45 PM

I am working with the auto data in the ISLR library in R

1) Test on the test data using the predict function. Find the correlation between the predicted values and the mpg values in the test data. Comment on the results. Calculate the mse on the test results. Compare this to the mse for the training data

```

pred <- predict(lmlinreg, newdata = test)
cor(pred, test\$mpg)

```

Error: Error in predict.lm(lmlinreg, newdata = test) : object 'test' not found

Is This A Good Question/Topic? 0

## Replies To: Help with R Programming

### #2 program94

Reputation: 0
• Posts: 42
• Joined: 19-April 14

## Re: Help with R Programming

Posted 18 June 2017 - 02:22 PM

1 7. Create a second linear model with log(mpg) predicted by horsepower. Compare the summary statistic R^2 of the two models
```
lmlinreg1 <- lm(log(mpg) ~ horsepower, data = Auto)
summary(lmlinreg1)

```

I think I did 1 right but if you think I didnt please let me know

2 Plot the function with an abline(). Comment on how well the line fits the data.

```
plot.new()
plot(Auto\$mpg, Auto\$horsepower)
abline(reg = lmlinreg1, col = "red")

```

It is not right

3 Predict on the test data using lm2. Compare the correlation of the predictions with lm1. Calculate the MSE for the test data on lm2 and compare to lm1.