predict()

predict()

The predict() function will generate the prediction(s) from a model. 

Idea
Example 1:

# Calculate the predictions from the Gender model of Thumb
# Use the lm() function to specify the model
predict(lm(Thumb ~ Gender, data = Fingers))

# Alt: Save the model into an object first
# then specify the name of the object as the argument
# (this method will produce the same output as the method above)
gender_model <- lm(Thumb ~ Gender, data = Fingers)
predict(gender_model) 

Example output (truncated):

Output of 'predict' function for Sex model of Thumb

Idea
Example 2:

To see each prediction in context, you might consider saving the predictions into the data frame as a new column to see more closely what the predict() function is doing.

# Save the predictions back into the data frame
gender_model <- lm(Thumb ~ Gender, data = Fingers)​
Fingers$Thumb_predict <- predict(gender_model)
# Select a few rows and the relevant columns to compare
head(select(Fingers, Thumb, Gender, Thumb_predict))

Example output:


Output of a few rows of Thumb, Gender, and Thumb_predict