Untitled

 avatar
unknown
plain_text
a month ago
1.5 kB
6
Indexable
install.packages("wooldridge")
install.packages("lmtest")
install.packages("car")
install.packages("ggplot2")

library("wooldridge")
data("hprice2")
head(hprice2)
names(hprice2)
str(hprice2)
summary(hprice2)

hprice2$lprice <- log(hprice2$price)
hprice2$lnox <- log(hprice2$nox)
hprice2$ldist <- log(hprice2$dist)

model1 <- lm(lprice ~ lnox + ldist + rooms, data= hprice2)
summary(model1)

model2 <- lm(lprice ~ lnox + ldist + rooms + crime, data = hprice2)
summary((model2))

library("ggplot2")

plot(model1$fitted.values, model1$residuals, xlab = "fitted values", ylab = "residuals", main= "model 1 residual plot")
abline(h=0, col= "red")

plot(model2$fitted.values, model2$residuals, xlab = "fitted values", ylab = "residuals", main= "model 2 residual plot")
abline(h=0, col= "red")

plot(hprice2$nox, hprice2$price, xlab = "Nitrogen Oxide (NOx)", ylab = "Housing price", main= "regression plot: price vs nox", 
     pch= 19, col="blue")

model_price_nox <- lm(price ~ nox, data- hprice2)
abline(model_price_nox, col="red, lwd= 2")
summary(model_price_nox)

plot(hprice2$ldist, hprice2$lprice, xlab= "log(distance)", ylab= "log(price)", main= "resgression plot: log(price) vs 
     log(distance)", pch= 19, col="green")

plot(hprice2$rooms, hprice2$price, xlab= "number of rooms", ylab= "house price", main= "regression plot: price vs room"
     , pch= 19, col="purple")

model_price_rooms<- lm(price~rooms, data= hprice2)
abline(model_price_rooms, col="red", lwd=2)
summary(model_price_rooms)

Editor is loading...
Leave a Comment