A dataset "women" in the datasets package in R gives the average heights (inches) and weights (pounds) for American women aged 30-39. Use the dataset to answer the following questions.
Fit a simple linear model weight=β0+β1*height 98JdQKvjtBAjnLcvJ5pzslA0ghcmVSImL2cJsFfdto predict the weight using height and report the fitted line.
Fit a polynomial model weight=β0+β1*height+β2*height2 vAAAAAElFTkSuQmCCto predict the weight and report the fitted line.
Draw a scatter plot of height and weight. Add the fitted lines from problem 1 and 2, respectively.

Respuesta :

Answer:

Step-by-step explanation:

Suppose the dataset "women" has 2 numeric columns namely "heights" and "weights".

By using function lm(formula, data) we can calculate the weight for the linear model

linmod = lm(weights ~ heights, data = women)

summary(linmod)

Similarly for the polynomial model

polymod = lm(women$weights ~ women$heights + I(women$heights^2))

summary(polymod)

To plot the fitted lines, we would need to calculate their y-values

plot(women$heights, women$weights, pch=16, col='black)

lines(women$heights, predict(linmod), col='blue')

lines(women$heights, predict(polymod), col='red')