0

I am trying to use predict function in RStudio on some new data. However I keep getting an error, "Error in qr.solve(qr.R(qrX)[p1, p1]) : singular matrix 'a' in solve". Where is my mistake? Should I have a simpler model?

lm.price.new <- lm(price ~ bedrooms * bathrooms * sqft_living * sqft_lot * floors *
                     waterfront * view * condition * grade, data = kc_house_data)
summary(lm.price.new)

new.house <- data.frame(bedrooms = 4, bathrooms = 2, sqft_living = 2560, sqft_lot = 7650, 
                        floors = 1.5, waterfront = 1, view = 3, condition = 5,
                        grade = 10)
predict(lm.price.new, newdata = new.house, interval = "predict")
1
  • Probably replace the * with + Commented Feb 24 at 5:30

1 Answer 1

1

I changed the model to not include cross effects as that was what was causing the singularities. Here is what I changed.

lm.price.new1 <- lm(price ~ bedrooms + bathrooms + sqft_living + sqft_lot + floors +
                     waterfront + view + condition + grade, data = kc_house_data)
Sign up to request clarification or add additional context in comments.

1 Comment

I expect that there is strong collinearity between your predictors. You should look into that. You might be better suited with a LASSO model.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.