Discussion work (30 mins):

Using the msleep dataset from the ggplot2 package, use the following code to fit linear models: one model on the original predictor, and one model with some predictors log-transformed.

  • ### Simple linear model on sleep_total on other predictors.
  • ### Removed taxonomy as number of levels is too large.
  • msleep_linear<-lm(sleep_total~vore+conservation+sleep_rem+sleep_cycle+brainwt+bodywt,data=msleep)
  • ### some predictors log-transformed
  • msleep_linear_log<-lm(sleep_total~vore+conservation+sleep_rem+sleep_cycle+log(brainwt)+log(bodywt),data=msleep)
  • perform diagnositics on the fitted models to determine how well the data fit the model assumptions. You may use the autoplot function from the ggfortify package to make some useful plots.