试图在R中建立一个线性回归模型
我掌握的数据如下:试图在R中建立一个线性回归模型,r,statistics,linear-regression,R,Statistics,Linear Regression,我掌握的数据如下: Geographic Area 2000 2001 2002 2003 2004 2005 Arizona 4779736 4780138 4798834 51689934 5052356 我希望年份是x轴,实际值是y轴 我试过: x <- seq(2000, 2005, by = 1) y <- seq(4533372,
Geographic Area 2000 2001 2002 2003 2004 2005
Arizona 4779736 4780138 4798834 51689934 5052356
我希望年份是x轴,实际值是y轴
我试过:
x <- seq(2000, 2005, by = 1)
y <- seq(4533372, 4671825, by 10000)
xMaurits Evers问了一个好问题。你想要这个模型吗?然后做:
dat <- data.frame("year" = c(2000, 2001, 2002, 2003, 2004),
"population" = c(4779736,4780138,4798834,5168993,5052356))
model <- lm(population ~ year, data = dat)
geom_smooth()
将线性回归模型拟合到数据中,插入回归线和功能区以显示置信区间
也许这就是你要找的
我不清楚你在问什么。您是想对数据进行建模(CIAndrews似乎已经理解了这一点),还是要绘制地理区域与年份的对比?您是否可以使用例如dput
以可复制的格式添加数据?当前数据集的列数多于数据。
library(ggplot2)
ggplot(aes(x = years, y = population), data = dat) +
geom_point() +
geom_smooth(method = "lm")