0

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

The data in "play"

THE GRAPH

chung
  • 1
  • 1
  • 1
    Without a reproducible example it is hard to tell. However, multiple blue lines indicate that there are multiple models being fitted. Typically this crops up when data are grouped and a model is fitted per group. – RDavey Sep 10 '19 at 07:57
  • Hi @RDavey , i just edited the post, you can see the graph, and the data i used – chung Sep 10 '19 at 12:26

0 Answers0