Get startedGet started for free

Linear regression

You can use the lm() function to perform simple linear regression. In this exercise, you will fit a model for age as a function of, or predicted by shuckedWeight. You will save the model results as an object and then display elements from this output object such as the coefficients.

You will also run a summary() of the model object and save that output in another object, which will contain elements related to the model fit such as r.squared and adj.r.squared. The abaloneKeep dataset has been loaded for you.

This exercise is part of the course

R For SAS Users

View Course

Exercise instructions

  • Use lm() to perform a simple linear regression of age by shucked weight. Save the output as lmshucked.
  • Display the coefficients element from lmshucked to get the intercept and slope model coefficients.
  • Run a summary() for lmshucked and save the output as smrylmshucked.
  • From the summary output object smrylmshucked, display the r.squared and adj.r.squared elements.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Run lm() of age by shuckedWeight, save output as lmshucked
lmshucked <- lm(___ ~ ___, data = ___)

# Display coefficients element from lmshucked
___

# Save summary() output of lmshucked as smrylmshucked
___

# Show r.squared and adj.r.squared elements of smrylmshucked
___
___
Edit and Run Code