# NOT RUN {
library(crmReg)
data(topgear)
# fit Cellwise Robust M-regression:
crmfit <- crm(formula = MPG ~ ., data = topgear)
# estimated regression coefficients and detected casewise outliers:
print(crmfit$coefficients)
print(rownames(topgear)[which(crmfit$casewiseoutliers)])
# fitted response values (MPG) versus true response values:
plot(topgear$MPG, crmfit$fitted.values, xlab = "True MPG", ylab = "Fitted MPG")
abline(a = 0, b = 1)
# residuals:
plot(crmfit$residuals, ylab = "Residuals")
text(x = which(crmfit$residuals > 30), y = crmfit$residuals[which(crmfit$residuals > 30)],
labels = rownames(topgear)[which(crmfit$residuals > 30)], pos = 2)
print(cbind.data.frame(car = rownames(topgear),
MPG = topgear$MPG)[which(crmfit$residuals > 30), ])
# cellwise heatmap of casewise outliers:
cellwiseheatmap(cellwiseoutliers = crmfit$cellwiseoutliers[which(crmfit$casewiseoutliers), ],
data = round(topgear[which(crmfit$casewiseoutliers), -7], 2),
col.scale.factor = 1/4)
# check the plotted heatmap!
# }
Run the code above in your browser using DataLab