#1. data x <- c(0.7, 1.7, 2.7, 3.6, 4.6, 5.6, 6.7, 7.7, 8.7, 9.7, 10.7, 11.7, 12.7, 40.0, 42.0, 44.0, 46.0, 48.1, 50.1, 52.0, 58.0, 60.5, 64.2, 65.0, 66.6, 68.2); y3 <- c(9.334871, 9.473416, 9.614335, 9.742939, 9.887201, 10.020116, 10.184169, 10.320339, 10.457563, 10.597603, 10.735707, 10.882608, 11.012444, 19.321751, 19.528083, 19.735207, 19.952787, 20.167201, 20.381614, 20.579535, 21.206282, 23.570176, 23.966017, 24.048484, 24.213417, 24.378351) plot(x, y3); #2. squares and cubics of x x2 = x*x; x3 = x*x*x; #3. linear model, quadratic and cubic model fmY3 = lm(y3 ~ x); fmY3qu = lm(y3 ~ x + x2); fmY3cub = lm(y3 ~ x + x2 + x3); #4. parameters of the models fmY3 fmY3qu fmY3cub #5. residuals max(abs(residuals(fmY3))) max(abs(residuals(fmY3qu))) max(abs(residuals(fmY3cub))) #6. plot everything plot(x, y3) abline(fmY3, col="red") lines(x, fitted(fmY3qu), col='blue') lines(x, fitted(fmY3cub), col='green')