繁体   English   中英

试图在R中建立线性回归模型

[英]Trying to make a linear regression model in R

我的数据如下:

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)

如何绘制年份和总人口?

莫里斯·埃弗斯(Maurits Evers)提出了一个很好的问题。 你要模特吗? 然后做:

dat <- data.frame("year" = c(2000, 2001, 2002, 2003, 2004),
                   "population" = c(4779736,4780138,4798834,5168993,5052356))

model <- lm(population ~ year, data = dat)

但是,您需要绘图,并且ggplot2有解决方案:

library(ggplot2)

ggplot(aes(x = years, y = population), data = dat) +
  geom_point() +
  geom_smooth(method = "lm")

geom_smooth()使线性回归模型适合您的数据,插入回归线,并插入功能区以显示置信区间。

也许这就是您要寻找的。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM