I am learning r and trying to understand one concept in building a model:

The data:

    Time Counts
1     0  126.6
2     1  101.8
3     2   71.6
etc...

The model:

Time2 <- Time^2
quadratic.model <-lm(Counts ~ Time + Time2)

The prediction:

timevalues <- seq(0, 30, 0.1)
predictedcounts <- predict(quadratic.model,list(Time=timevalues, Time2=timevalues^2))

I don't understand this part of the above function.

list(Time=timevalues, Time2=timevalues^2)

What exactly is the list doing? Is there a more intuitive way to accomplish the same thing?

有帮助吗?

解决方案

The list is specifying what values of Time and Time2 should be used for prediction. If you had different time values (say from a cross validation set) called TimeValuesB, then by setting list(Time = TimeValuesB, Time2 = TimeValuesB^2) you could obtain the predicted output for these new data values.

However, if you just want to obtain the predictions from the original data you can omit the list. So in your case

predictedcounts <- predict(quadratic.model)

should work just fine.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top