I have a set of data I'm analyzing in R with 2 explanatory variables (X1 and X2), and one response variable (Y).
X1<-c(1,2,2,4,5,8,5,4,3,2,1,0,1,2,3,4,6,6,5,4,3,2,1,0,1,1,3,4,3,6,5,5,3,2,1)
X2<-c(20,40,50,40,50,50,50,30,10,5,10,20,10,10,10,10,50,80,20,10,20,40,40,40,5,20,30,40,50,60,20,20,10,20,10)
Y<-c(70,140,200,240,250,250,250,230,160,105,60,20,60,110,160,210,250,250,250,210,170,140,90,40,55,120,180,240,250,250,250,220,160,120,60)
MyData<-data.frame(X1,X2,Y)
My goal is to calculate an equation that will allow me to predict Y based on future X1 and Y1 values. In the past I have used a linear regression like so:
MyFit<-lm(Y~X1+X2,data=MyData)
And then use this formula to predict Y
Y= coefficients(MyFit)[1]+coefficients(MyFit)[2]*X1+coefficients(MyFit)[3]*X2
In the above dummy set, Y is strongly driven by X1. But the issue with my real data is that at some point Y gets saturated, so that further increases in X1 do not bring about increases in Y (for this data the saturation value is 250, but the actual values begin to slow down and form a saturation curve as it approaches peak value, as opposed to an absolute saturation point). The result is that the linear model will always over-predict the peak Y values. This can be seen in a plot here:
plot(Y,type="l",ylim=c(0,350))
lines(X1,col='red')
lines(X2,col='blue')
lines(coefficients(MyFit)[1]+coefficients(MyFit)[2]*X1+coefficients(MyFit)[3]*X2,col='green')
How can I correct for this. Is it possible to do a multiple non-linear regression for this data? Or is there some other technique I can use here?
Y= coefficients(MyFit)[1]+coefficients(MyFit)[2]*X1+coefficients(MyFit)[3]*X2
simply usepredict(object = MyFit)
$\endgroup$ – Helix123 Mar 8 '16 at 17:27y
,x1
andx2
? $\endgroup$ – Roland Mar 9 '16 at 16:22