#Board question: fit curves ---- x = c(1,2,4) y = c(3,1,4) degs = c(1,2) #the degrees of the polynomials to fit n = length(x) # Set the plot limits and plot xlim = c(0,5) ylim = c(0,5) plot(x, y, col = "magenta", pch = 16, cex=1.2,xlim=xlim, ylim=ylim) ###fitting models to the data xplot = seq(xlim[1],xlim[2],length.out = 1000) for(j in 1:length(degs)){ #Sys.sleep(1) deg = degs[j] fit = lm(y ~ poly(x, deg, raw = TRUE)) print(summary(fit)) print(paste("R squared: ", summary(fit)$r.squared)) lines(xplot, predict(fit, newdata=data.frame(x=xplot)), col=j, lwd=3) } legend(4,2,degs,col=1:length(degs), lty=1,lwd=3)