如何预测阶乘实验 (2^k) 中的中心点在 R 中的值?

How can I predict values in factorial experiments (2^k) with centre points in R?

如何使用带有 predict 函数的 FrF2 包或使用 broom 包预测 R 中心点阶乘实验中的值?

我的代码:

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)

由于中心点出现以下消息。

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

"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)

也就是说,R 无法预测这些值,因为您需要对曲线的外观做出额外的假设,以预测不在您的设计点上的点。

请注意,在计算方面,您可以通过添加 center 项来使软件运行。错误是因为该术语在回归中但不在数据集中。您可以添加一个带有 data$center <- FALSE 的点(因为 data 中的 none 个点位于中心),但这 不会 做正确的事情,因为它在预测非中心点时不会考虑潜在曲率,它会简单地预测一个扭曲的平面(即,与相互作用成线性),中心有一个凸点。

当然也相当于只用use.center=FALSE拟合模型,中心点不影响其他点的拟合

如果去掉中心值,可以在model <- lm(newplan, use.center = T) :

之后

1- 过滤 pvalues < 0.05

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

m_beta <- coe$estimate

2 - 做一个网格:

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:进行回归:

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

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

但我相信这只能解决或简化计算问题。我相信线性回归也应该重做。但是使用此代码,您可以探索并查看存在的其他错误。