【发布时间】:2021-09-16 08:04:38
【问题描述】:
我正在尝试计算每类花瓣长度和宽度的残差矩阵 (2*ng),其条件是 R 上 Iris 数据集的萼片长度和宽度(ng = gth 类中的观察数)。我需要为每个班级将残差绘制为双变量图上的点。
我有以下代码,但觉得这不是正确的方法。任何帮助将不胜感激,谢谢!
fit = lm(data = iris, Petal.Length + Petal.Width ~ Sepal.Length + Sepal.Width)
iris$predicted = predict(fit)
iris$residuals = residuals(fit)
iris %>% select(predicted, residuals) %>% head()
ggplot(iris, aes(x=Sepal.Length, y=Petal.Length)) + geom_point() + geom_point(aes(y=predicted), shape = 1) + theme_bw()
ggplot(iris, aes(x=Sepal.Length, y=Petal.Width)) + geom_point() + geom_point(aes(y=predicted), shape = 1) + theme_bw()
ggplot(iris, aes(x=Sepal.Width, y=Petal.Length)) + geom_point() + geom_point(aes(y=predicted), shape = 1) + theme_bw()
ggplot(iris, aes(x=Sepal.Width, y=Petal.Width)) + geom_point() + geom_point(aes(y=predicted), shape = 1) + theme_bw()
【问题讨论】:
标签: r