首页 文章

预测黄土()函数

提问于
浏览
0

我试图只预测两个值,模型是

data(mtcars) #is already available in R

m1 = loess(mtcars$mpg ~ mtcars$cyl + mtcars$disp)
# the prdedict function works well
y.predict <- predict(m1, data.frame(mtcars$cyl, mtcars$disp))

但它通过使用两个预测变量的所有存在值来估计模型m1

mtcars $ cyl和mtcars $ disp,我想要估算mtcars $ mpg的一个值 .

我试过了

new.data= data.frame(mtcars$cyl=c(2,3), mtcars$disp=c(200,1000))
y.predict <- predict(m1, new.data)

但它给了我以下警告信息:'newdata'有2行,但找到的变量有32行

感谢您的帮助

1 回答

  • 0

    这是符号的细微差别,请尝试这种方式:

    data(mtcars) #is already available in R
    attach(mtcars) # attach it to the environment so you can use column names directly
    m1 = loess(mpg ~ cyl + disp)
    # the prdedict function works well
    y.predict <- predict(m1, data.frame(cyl, disp))
    
    # add new data
    new.data = data.frame(cyl = c(6,8), disp = c(150,100))
    y.predict <- predict(m1, new.data)
    

相关问题