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.
Este exercício faz parte do curso
R For SAS Users
Instruções do exercício
- Use
lm()to perform a simple linear regression of age by shucked weight. Save the output aslmshucked. - Display the
coefficientselement fromlmshuckedto get the intercept and slope model coefficients. - Run a
summary()forlmshuckedand save the output assmrylmshucked. - From the summary output object
smrylmshucked, display ther.squaredandadj.r.squaredelements.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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
___
___