Hi, I have problem, I have a values I would like to draw, bot to make a plot I'm using predict() function to jet enought data to draw a line, bot I got error and I don't now why and what to do.
My code looks like this:
results = read.csv("results.csv")
avg_results = aggregate(time ~ size:type, data=results, FUN=mean)
avg_results$std = aggregate(time ~ size:type, data=results, FUN=sd)$time
fit0 = lm(subset(avg_results$time,avg_results$type == 0) ~ poly(subset(avg_results$size,avg_results$type == 0), 3, raw=TRUE)
x = seq(0, 900, length.out = 100)
approx_fun0 = data.frame(x)
approx_fun0$y = predict(fit0, approx_fun0)
And after running last line I've got:
Error in $<-.data.frame
(*tmp*
, y, value = c(1
= -0.311488153801186, :
replacement has 18 rows, data has 100
Error. I can just add, that subset(avg_results$time,avg_results$type == 0) has 18 rows, and fit0 equals:
Call:
lm(formula = subset(avg_results$time, avg_results$type == 0) ~ poly(subset(avg_results$size, avg_results$type == 0), 3,
raw = TRUE))Coefficients:>
(Intercept) poly(subset(avg_results$size, avg_results$type == >0), 3, raw = TRUE)1
-1.675e+00 1.878e-02
poly(subset(avg_results$size, avg_results$type == 0), 3, raw = TRUE)2 >poly(subset(avg_results$size, avg_results$type == 0), 3, raw = TRUE)3
-5.650e-05 5.070e-08
I would be very grateful if someone could tell me why precict() don't want to predict values, when has new x's and fit funtion (that looks like on the example in internet)