Removing Outliers from a Regression Model.

Using the Faraway package and stackloss data. We were asked to identify the outliers and remove them. The outlier was in row 21. This is the code I wrote to remove the outlier, but it is not working, saying that stack.loss2 needs to be a data frame. Any helps, or hints will be greatly appreciated. If I attached my code incorrectly, please let me know so that I can fix it.

stack.loss2 <- data.frame(stackloss)
stackloss1 <- data.frame(stackloss)
stack.loss2 <- stack.loss[1:20,]
stackloss1 <- stackloss[1:20,]

mod2<- lm(stack.loss2 ~ stackloss1)
summary(mod2)

Hello!

Let's start with str(stackloss1). What does that say?

Secondly, lm() takes variable names, not data frames.

Something like lm(y~x, data = stackloss1)

2 Likes

Thank you for making me think! My code now works! You're awesome!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.