我試圖為每一類花瓣的長度和寬度計算一個殘差矩陣(2*ng),以R上的Iris資料集的萼片長度和寬度為條件(ng=第1類中的觀測值數量)。我需要將每個類別的殘差繪制成雙變數圖上的點。
我有以下代碼,但我覺得這不是正確的方法。希望得到任何幫助,謝謝!
我有以下代碼,但感覺這不是正確的方法。
fit = lm(data = iris, Petal. 長度 花瓣.寬度~萼片.長度 萼片.寬度)
iris$predicted = predict(fit)
iris$residuals = residuals(fit)
iris %>% select(predicted, residuals) %> % head()
ggplot(iris, aes(x=Sepal. 長度, y=Petal. operator"> geom_point(aes(y=predicted)。 形狀= 1) theme_bw()
ggplot(iris, aes(x=Sepal。 長度, y=花瓣。 operator"> geom_point(aes(y=predicted)。 形狀= 1) theme_bw()
ggplot(iris, aes(x=Sepal. 寬度, y=Petal. operator"> geom_point(aes(y=predicted)。 形狀= 1) theme_bw()
ggplot(iris, aes(x=Sepal. 寬度, y=Petal. operator"> geom_point(aes(y=predicted)。 形狀= 1) theme_bw()
uj5u.com熱心網友回復:
從你的描述和代碼中不太清楚你想如何繪制你的殘差。如果你想將預測值和實際值可視化,你只需選擇你需要的變數:
library(ggplot2)
library(tidyr)
iris %>% select(Sepal.Length,Species, Petal. 長度,預測) %>%。
pivot_longer(-c(Sepal. 長度,物種)) %>%
ggplot(aes(x =萼片。 長度,y=價值。 shape=name))
geom_point()
facet_wrap(~Species)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/306855.html
標籤:
上一篇:用SQL查找表內連續出現的次數

