首页 > 解决方案 > 你如何绘制线性回归线?

问题描述

如何使用基数 R 将线性回归线拟合到散点图?假设您已经拥有线性模型的摘要信息。

a我已经有一个比较和的散点图ix,我正在尝试将回归线lm.a和添加lm.b到图中。我应该使用ab线还是其他东西?

a <- c(21, 23, 25, 27, 29)
ix <- c(100, 300, 500, 600, 750)
ib <- c(0, 1, 0, 1, 1)
x <- data.frame(a, ix, ib)

lm.a <- with(x, lm(a ~ ix + ib + ix*ib))
summary(lm.a)
n1 <- lm.a$coefficients[1]
n2 <- lm.a$coefficients[2]
n3 <- lm.a$coefficients[3]
n4 <- lm.a$coefficients[4]

标签: r

解决方案


你几乎明白了,这是一个你可以适应的工作示例:

height <- c(176, 154, 138, 196, 132, 176, 181, 169, 150, 175)
bodymass <- c(82, 49, 53, 112, 47, 69, 77, 71, 62, 78)

plot(bodymass, height)+
  abline(lm(height ~ bodymass)) # Missing lm here

在此处输入图像描述


推荐阅读