我试着只预测两个值,模型是
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和mtcar$disp,我只想估计mtcar$mpg的一个值。
我试过了
new.data= data.frame(mtcars$cyl=c(2,3), mtcars$disp=c(200,1000))
y.predict <- predict(m1, new.data)但它给出了以下警告消息:'newdata‘有2行,但找到的变量有32行
感谢您的帮助
发布于 2016-11-11 07:12:04
这是符号中的细微差别,可以这样尝试:
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)https://stackoverflow.com/questions/39439043
复制相似问题