0

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

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

用英语讲:

可变长度不同(为 'I (inputs [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)')
4

1 回答 1

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
于 2016-09-05T13:16:48.967 回答