【发布时间】:2015-12-04 12:34:56
【问题描述】:
考虑到预测函数及其 R 平方值,我有一个基本问题。
data<- datasets::faithful
# Linear model
model<- lm (eruptions~., data=data)
summary (model)[[9]] # R squared ajusted
# Creating test data to predict eruption values using the previous model
test.data<- data.frame(waiting= rnorm (80, mean = 70, sd = 14 ))
pred<- predict (model, test.data) # Predict eruptions based and the previou model
# New dataset with predicted values
newdata<- data.frame (eruptions = model.pred, waiting = test.data)
# Linear model to predicted values
new.model<- lm (eruptions~., data = newdata)
summary (new.model)[[9]] ## R-squared from predicted values
具有预测值的数据集的 R-squared 为 1。很明显,如果预测值基于 predict 函数中使用的相同变量,则 R-squared 测量的拟合是完美的 (=1)。但是,我的兴趣是衡量我的模型在 测试其他数据集方面的性能有多好,例如代码中的 test.data。我是否正确使用了预测功能?
提前致谢
【问题讨论】: