1
votes

How can I predict values in factorial experiments with centre points in R using FrF2 package with the predict function or using the broom package?

My code:

library(FrF2)
plan.person = FrF2(nfactors = 5, resolution = 5, replications = 2,
               ncenter = 1, randomize = FALSE,
               factor.names = list(
                 A = c(8, 5),
                 B = c(70, 30),
                 C = c(0.5, 0),
                 D = c(1000, 700),
                 E = c(70, 10)))

resp  <- c(84.55, 66.34, -1, 69.18, 73.01, 64.52, 0.73, 47.61, 68.18, 59.87, 
       26, 72.57, 78.08, 73.81, 26, 59.38, 71.41, 88.64, 64.92, 4, 68.81, 
       80, 69.66, -1.36, 54.50, 79.24, 78.53, -1, 72.63, 89.97, 87.98, 
       -11, 65.68, 82.46)

newplan <- add.response(design = plan.person, response = resp)

model <- lm(newplan, use.center = T)
# summary(model)

d <- within(newplan, {
  A <- as.numeric(as.character(A))
  B <- as.numeric(as.character(B))
  C <- as.numeric(as.character(C))
  D <- as.numeric(as.character(D))
  E <- as.numeric(as.character(E)) })

A = seq(5, 8, 1)
B = seq(30, 70, length.out = length(A))
C = seq(0, 0.5, length.out = length(A))
D = seq(700, 1000, length.out = length(A))
E = seq(10, 70, length.out = length(A))

data <- expand.grid(A = A, B = B,
                C = C, D = D,
                E = E)  

dados$p <- predict(model, newdata=data)

Because of the center point the following message appears.

Error in model.frame.default (Terms, newdata, na.action = na.action, xlev = object $ xlevels):    lengths of variables differ (found in 'center')

2

2 Answers

0
votes

If you remove the central value, you can this after model <- lm(newplan, use.center = T) :

1- Filter the pvalues < 0.05

coe <- broom::tidy(model) %>% 
  slice(-7) %>%   #remove center
  filter(p.value < 0.05)   

m_beta <- coe$estimate

2 - Do a grid:

A = seq(5, 8, 0.5)
B = seq(30, 70, length.out = length(A))

exp <- expand.grid(A = A, B = B) %>% 
  mutate(bo = as.numeric(1)) %>% 
  mutate(ult = A*B) %>% 
  select(bo, A, B, ult) %>% 
  as.matrix()

3: Do a Regression:

reg <- t(m_beta %*% t(exp)) 

exp <- cbind(exp, reg) %>% 
  as.data.frame() %>% 
  rename(reg = V5)

But I believe this only solves the computational problem or simplifies it. I believe linear regression should be redone as well. But with this code you can explore and see what other errors exist.

3
votes

"A two-level experiment with center points can detect, but not fit, quadratic effects." (https://www.itl.nist.gov/div898/handbook/pri/section3/pri336.htm)

That is, R can't predict these values because you need to make additional assumptions about what the curve looks like to predict points not at your design points.

Note that computationally, you can get the software to work by adding a center term. The error is because this term is in the regression but not in the data set. You could add one with data$center <- FALSE (because none of the points in data are at the center), but this will not do the right thing, as it will not take the potential curvature into account when predicting non-central points, it would simply predict a twisted plane (that is, linear with interactions) with a single bump at the center.

Of course, it's also equivalent to just fitting the model with use.center=FALSE, as the center point doesn't affect the fit of the other points.