Polynomial regression models are built using the `lm`

function, as we saw earlier, with the option `poly`

.

- Read the hypothetical dataset into R by using
`data(OF)`

. - Plot
`Y`

against`X`

by using`plot(OF$X, OF$Y,"b",col="red",xlab="X", ylab="Y")`

. - Fit the polynomial regression models of orders 1, 2, 3, 6, and 9, and add their fitted lines against the covariates
`X`

with the following code:lines(OF$X,lm(Y~poly(X,1,raw=TRUE),data=OF)$fitted.values,"b",col="green") lines(OF$X,lm(Y~poly(X,2,raw=TRUE),data=OF)$fitted.values,"b",col="wheat") lines(OF$X,lm(Y~poly(X,3,raw=TRUE),data=OF)$fitted.values,"b",col="yellow") lines(OF$X,lm(Y~poly(X,6,raw=TRUE),data=OF)$fitted.values,"b",col="orange") lines(OF$X,lm(Y~poly(X,9,raw=TRUE),data=OF)$fitted.values,"b",col="black") ...

Start Free Trial

No credit card required