-1

I´m a begginer in R and programming and struggling in doing problably a simple task. I've made a code that creates a second model order and i want to input variables in this model and find the "Y value"

I´ve tried to use the predict function, but is actually pretty complex and I can't got anywhere.

I did this so far:

modFOI <- rsm(Rendimento~FO(x1,x2,x3,x4)+TWI(x1,x2,x3,x4)+PQ(x1,x2,x3,x4),data=CR) # com interações
summary(modFOI)
print(modFOI)

With that, i found the SO model, but now i want to create variables like x1,x2,x3 and input that in the model and find the Y. I also woud like to find the optimum Y

Z.Lin
  • 28,055
  • 6
  • 54
  • 94

2 Answers2

0

Simplest way to create a polynomial (2nd order) that I can think of is the following:

DF <- data.frame(x = runif(10,0,1),
                 y = runif(10,0,1) )
mod <- lm(DF$y ~ DF$x + I(DF$x^2))

predict(mod, new.data=data.frame(x=c(1,2,3,4,5)))

NB. when using predict the new.data must be in a data.frame format, and the variable must have the same name as the variable in the model (here, x)

Hope this helps

JMilner
  • 491
  • 4
  • 12
0

The optimum value is shown as the stationary point in the output of summary(modFOI). You may also run steepest(modFOI) to see a trace of the estimated values along the path of steepest ascent.

To predict, create a data frame with the desired sets of x values. For example,

testdat <- data.frame(x1 = -1:1, x2 = 0, x3 = 0, x4 = 1)

Then use the predict() function with this is newdata:

predict(modFOI, newdata = testdat)
Russ Lenth
  • 5,922
  • 2
  • 13
  • 21