geom_smooth()中的模型拟合可能存在秩不足导致预测结果具有误导性。

3

我使用ggplot2绘制我的数据,出现了错误提示"prediction from a rank-deficient fit may be misleading"。请看这里:

# Data.
temp <- structure(list(x = c(-62135599651, -62135599057, -62135598463,  -62135597869, -62135597275, -62135596681, -62135596087, -62135595493,  -62135594899, -62135594305), y = c(0.1, 0.2, 0.4, 0.3, 0.5, 0.5,  0.9, 0.9, 0.8, 1)), class = "data.frame", row.names = c(NA, -10L))
# Plot.
ggplot(temp, aes(x, y)) +
  geom_point() +
  geom_smooth(method= "lm")

在这张图中,geom_smooth()线看起来不对(正如错误信息所提示的):

Plot

有一个类似的问题,但缺少可重现的示例且没有答案。我应该怎么做呢?

编辑

对于那些想要进一步了解如何在统计上解决此问题的人,请参见我在此处的问题。

1个回答

3

你遇到了一个数值精度舍入问题。

通过减去 mean(x),你可以将 x 居中。

ggplot(temp, aes(x, y)) +
  geom_point() + 
  geom_smooth(method= "lm", formula = y ~ I(x-mean(x)))

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接