I tried to use lm() with poly() to calculate the best fit 2nd order polynomial curve. That ran fine, but when i used lines() to plot it, the curve looked weird, as if there were multiple curves drawn on the graph.
play <- filtered_file[filtered_file$`Rating to Use` == "A" & filtered_file$`INDUSTRY_GROUP/BCLASS2` == "Supranational", ]
play<- select(play,c(`Barclays New`,`Days_till_maturity` ) )
plot(play$`Barclays New` ~ play$`Days_till_maturity`)
linear <- lm( play$`Barclays New` ~ play$`Days_till_maturity`)
polynomial_2 <- lm( play$`Barclays New` ~ poly(play$`Days_till_maturity`,2, raw = TRUE) )
polynomial_3 <- lm( play$`Barclays New` ~ poly(play$`Days_till_maturity`,3, raw = TRUE) )
lines(play$`Days_till_maturity`, predict(linear), col = "blue" )
lines(play$`Days_till_maturity`, predict(polynomial_2), col = "red" )
lines(play$`Days_till_maturity`, predict(polynomial_3), col = "green" )
The graphs showed multiple straight blue lines (sorta overlapping each other), and many red curves