DiceKriging /全二阶多项式

时间:2016-08-31 14:31:17

标签: r kriging

使用完整的二阶多边形(2D)运行DiceKriging(在R中)时会出现以下消息:

  

model.frame.default(object,data,xlev = xlev)中的错误:
  Variablenlängensindunterschiedlich(gefundenfür'I(inputs [,1] ^ 2)')

英文:

  

可变长度不同(找到'I(输入[1] ^ 2)')

脚本:

#Modeling

    xa<-c(1,2,3,4,5,6)
    xb<-c(1,2,3,4,5,6)
    inputs<-expand.grid(xa,xb)
    output<-c(1,4,7,18,23,35,1,4,9,18,23,35,1,4,7,18,1,35,1,4,7,18,35,35,1,4,7,18,23,35,1,4,7,18,23,35)
    m2 <- km(formula = ~.^2 + I(inputs[,1]^2) + I(inputs[,2]^2), design = data.frame(x = inputs), response = output)

#prediction

    x11 <- seq(1,6, by = 0.1)
    x22 <- seq(1,6, by = 0.1)
    DESIGNX <- expand.grid(x11, x22)
    newdata <- data.frame(x = DESIGNX)
    DESIGNY <- predict(m2, newdata, "UK")$mean

#Error in model.frame.default(object, data, xlev = xlev) : 
 # variable lengths differ (found for 'I(inputs[, 1]^2)')

1 个答案:

答案 0 :(得分:1)

当你使用design = data.frame(x = inputs)时,这将创建一个列名为x.Var1和x.Var2的data.frame。在公式中使用这些名称可以解决问题:

m2 <- km(formula = ~.^2 + I(x.Var1^2) + I(x.Var2^2), design = data.frame(x = inputs), response = output)

最好定义自己的名字,并在newdata中重复使用相同的名称:

design <- data.frame(inputs); names(design) <- c("x1", "x2")
m2 <- km(formula = ~.^2 + I(x1^2) + I(x2^2), design = design, response = output)

newdata <- data.frame(DESIGNX); names(newdata) <- names(design)
DESIGNY <- predict(m2, newdata, "UK")$mean