I have taken a sample dataset consisting Responsibility , Trainees supervising and salary where salary can be generated from Responsibility and Trainee values , I have generated the model formula using multiple regression .
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)
Its working fine! But When I am trying to predict Salary from available values of trainee and responsibility values .. its creating a data frame with more than one values.
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)
When T=100, r=100 , predicted_salary should be 500 , but Its giving output like :
[ 1 ] 300 500 900 400 300 700