I'm trying to plot the original date with the predictions of the best models using curve()
because I'm working with polynomial models, but I keep getting this error:
Error in curve(predict(best_models\[\[i\]\]$best_model, newdata =
data.frame(get(normalized_columns\[i\]))), :
'expr' must be a function, or a call or an expression containing 'x
This is the part of the code that it is generating the error:
par(mfrow=c(2, 3))
for (i in 1:6) {
curve(predict(best_models[[i]]$best_model,
newdata=data.frame(get(normalized_columns[i]))),
from=min(filtered_resp_data[[normalized_columns[i]]]),
to=max(filtered_resp_data[[normalized_columns[i]]]),
col="blue", lwd=2,
xlab=normalized_columns[i], ylab="xxx",
main=paste("Real Data vs. Best Model (Degree",
best_models[[i]]$best_degree, ")"))
}
x
somewhere, e.g.curve(1 + 2*x + 3*x^2)
.predict
withcurve
the proper idiom iscurve(predict(fit, newdata = data.frame(nameofyourpredictor = x))
. Note how thex
is supplied and matches the requirement of there being anx
as part of the expression passed tocurve
.setNames(data.frame(x), variablecontainingthename)
.