- Joined
- Jan 13, 2019
- Posts
- 1,593
- Solutions
- 5
- Reaction
- 9,207
- Points
- 1,433
ano po kaya error mga lods okay naman sa pag process ko ng code pero pag dating dito nagka error, baka may nakaka alam, maraming salamat agad. R language po yan
Code:
#Extract elements
res1 <- resid(model1)
fit1 <- fitted(model1)
res2 <- resid(model2)
fit2 <- fitted(model2)
#Calculate axis range
resRange <- c(-1, 1) * max(abs(res1), abs(res2))
fitRange <- range(fit1, fit2)
#Create plot for model1> add points for model2
plot(fit1, res1, xlim = fitRange, ylim = resRange, col = "red", pch = 16, main = "Residuals vs Fitted Values", xlab = "Fitted Values", ylab = "Residuals")
points(fit2, res2, col = "blue", pch = 16)
#Add reference and smooth lines
abline(h = 0, lty = 2)
lines(loess.smooth(fit1, res1), col = "red")
lines(loess.smooth(fit2, res2), col = "blue")
legend("bottom left", c("mpg ~ wt", "mpg ~ wt + hp"), fill = c("red", "blue"))