线性回归模型的R预测

时间:2023-01-18 19:55:34

I'm sure this is something that can be done, just not sure how! I have a dataset that is around 500 rows(csv) and it shows footballers match stas(e,g passes, shots on target)etc.I have some of their salaries(around 10) and I'n trying to predict their salaries using a linear regression equation.

我确信这是可以做到的,只是不确定如何!我有一个大约500行(csv)的数据集,它显示足球运动员匹配stas(e,g传球,击中目标)等。我有一些他们的薪水(大约10)我试图用他们的工资来预测他们的工资线性回归方程。

In the below, if Y is salaries, is there a way on R to essentially autopopulate? what the rest of the salaries might be based on the ten salaries I do have?

在下面,如果Y是工资,R上有没有办法基本上自动填充?剩下的工资可能基于我的十大工资?

lm(y ~ x1 + x2 +x3)

lm(y~x1 + x2 + x3)

Any help would be much appreciated.

任何帮助将非常感激。

2 个解决方案

#1


This is what the predict function does.

这就是预测功能的作用。

Note that you don't need to call predict.lm explicitly. Because the result of a call to lm is an object with class "lm", R "knows" to use predict.lm when you call predict on it.

请注意,您无需显式调用predict.lm。因为调用lm的结果是具有类“lm”的对象,所以当您在其上调用predict时,R“知道”使用predict.lm。

Eg:

lm1 <- lm(y ~ x1 + x2 +x3)
y.fitted <- predict(lm1)

#2


You should also be able to test the predictive accuracy of your model using cross validation with the function cv.lm in the DAAG library. With this function you create test data to test the model which is generated using training data.

您还应该能够使用DAAG库中的函数cv.lm进行交叉验证来测试模型的预测准确性。使用此功能,您可以创建测试数据以测试使用训练数据生成的模型。

#1


This is what the predict function does.

这就是预测功能的作用。

Note that you don't need to call predict.lm explicitly. Because the result of a call to lm is an object with class "lm", R "knows" to use predict.lm when you call predict on it.

请注意,您无需显式调用predict.lm。因为调用lm的结果是具有类“lm”的对象,所以当您在其上调用predict时,R“知道”使用predict.lm。

Eg:

lm1 <- lm(y ~ x1 + x2 +x3)
y.fitted <- predict(lm1)

#2


You should also be able to test the predictive accuracy of your model using cross validation with the function cv.lm in the DAAG library. With this function you create test data to test the model which is generated using training data.

您还应该能够使用DAAG库中的函数cv.lm进行交叉验证来测试模型的预测准确性。使用此功能,您可以创建测试数据以测试使用训练数据生成的模型。