admin管理员组

文章数量:1279116

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")

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")
Share Improve this question edited Feb 24 at 5:19 Jan 9,3386 gold badges20 silver badges33 bronze badges asked Feb 24 at 4:34 stella1897stella1897 574 bronze badges 1
  • Probably replace the * with + – Edward Commented Feb 24 at 5:30
Add a comment  | 

1 Answer 1

Reset to default 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)

本文标签: rSingular Matrix 39a39 in solveStack Overflow