使用多项式模型预测R中的值

时间:2014-10-02 16:25:10

标签: r lm

我想用已经存在的多项式模型(度数10)预测值。我使用以下代码:

data <- read.table(text = "
       F        dF
      31  4.200637
      62  4.449955
     125  7.432887
     250  8.965772
     500  8.152466
    1000  9.284801
    2000 16.239006
    4000 23.171764
    8000 50.992621
   11700 81.379936", header = TRUE)

model <- lm(data$dF ~ poly(data$F, 10, raw=TRUE))
values <- data.frame(F=c(0:20000))
values$dF <- predict(model, newdata=values)

Error in `$<-.data.frame`(`*tmp*`, "dF", value = c(3.76985761737494, 5.14982737187282,  : 
#  replacement has 10 rows, data has 20001
#In addition: Warning messages:
#1: 'newdata' had 20001 rows but variables found have 10 rows 
#2: In predict.lm(model, newdata = values) :
#  prediction from a rank-deficient fit may be misleading

我做错了什么?非常感谢您的提示!

0 个答案:

没有答案