我已经采用了一个样本数据集,其中包括责任,受训人员监督和工资,其中薪资可以从责任和受训者的价值中生成,我已经使用多元回归生成了模型公式。
responsibility<-c(2,3,4,1,2,3)
trainee<-c(1,3,7,2,1,5)
salary<-c(7,15,29,8,7,21)
#creating the data frame to be fed into the regresion model
data1<-data.frame(responsibility,trainee,salary)
#creating the relation model between salary and responsibility & trainee
model<-lm(salary~responsibility+trainee,data=data1)
工作正常!但是,当我试图从受训者和责任值的可用值预测薪水时,它会创建一个包含多个值的数据框。
intercept<-coef(model)[1]
resp<-coef(model)[2]
train<-coef(model)[3]
# r is responsibity , t is trainee value for finding the new salary...
predicted_salary=intercept+(resp*r)+(trainee*t)
print(predicted_salary)
当T = 100,r = 100时,predict_salary应为500,但它的输出如下:
[1] 300 500 900 400 300 700