Rで観測された散布図と予測された散布図を描くにはどうすればよいですか? また、回帰直線も表示したいと思います。
library(car)
summary(Prestige)
head(Prestige)
testidx <- which(1:nrow(Prestige)%%4==0)
prestige_train <- Prestige[-testidx,]
prestige_test <- Prestige[testidx,]
model <- glm(prestige~., data=prestige_train)
# Use the model to predict the output of test data
prediction <- predict(model, newdata=prestige_test)
# Check for the correlation with actual result
plot(prediction, prestige_test$prestige)
編集:
abline(model)
上記の機能abline
は動作していないようです。線を引いていますが、間違っているようです。
ありがとう