简体   繁体   English

如何使用多个数据在 R 中训练线性回归模型

[英]How to use multiple data to train a linear regression model in R

I am building a linear regression model to predict 2015 values.我正在构建一个线性回归模型来预测 2015 年的值。 I have data from 2013 and 2014. My question is, how can I use both the data from 2013 and 2014 to train my linear regression model in R?我有 2013 年和 2014 年的数据。我的问题是,如何使用 2013 年和 2014 年的数据在 R 中训练我的线性回归模型? I have:我有:

model1 = lm(x ~ y, data = data2013)

model2 = lm(x ~ y, data = data2014)


predictions1 = predict(model1, testdata)

predictions2 = predict(model2, testdata)

I was wondering if I could build a more accurate model using all the data I have.我想知道是否可以使用我拥有的所有数据构建更准确的模型。 It would be something like this:它会是这样的:

model1&2 = lm(x ~ y, data = data2013 & 2014)

Thank you in advance,先感谢您,

If the columns are exactly the same, you should be able to do something like this:如果列完全相同,您应该能够执行以下操作:

data_2013_and_2014 <- rbind(data2013, data2014)
new_model <- lm(x ~ y, data = data_2013_and_2014)

Lookup ?rbind for more details.查找?rbind以获取更多详细信息。

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

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