Requirement:
4) Scroll down to lines 37, and change the code based on the model you specified (only one independent variable-- AgeOfHouse).
fit <- lm(charges ~ bmi, data = mydata)
Notes:
• You will need to add a new column (AgeOfHouse=2019- yr_built) in the dataset and save your changes before running the script
My entire code:
rm(list = ls());
mydata <- read.csv("kc_house_data (1).csv",header=TRUE)
sink("RegressionOutput.txt", append=FALSE, split=TRUE)
pdf("rplot.pdf")
plot(charges ~ bmi, data = mydata)
mydata$AgeOfHouse <- 2019-yr_built
fit <- lm(charges ~ AgeOfHouse, data = mydata)
summary(fit)
mydata$charges.fit <- predict(fit)
plot(charges ~ charges.fit, data = mydata)
pairs(charges~ bmi + age + male + children + smoker, data = mydata)
res <- cor(mydata)
round(res, 2)
mfit <- lm(charges~ bmi + age + male + children + smoker, data = mydata)
summary(mfit)
mydata$charges.mfit <- predict(mfit)
plot(charges ~ charges.mfit, data = mydata)
dev.off()
sink();