Graphics Reference
In-Depth Information
Call:
lm(formula = heightIn ~ ageYear, data = data)
Coefficients:
(Intercept)
ageYear
30.658
2.301
attr(, "split_type" )
[ 1 ] "data.frame"
attr(, "split_labels" )
sex
1
f
2
m
Now that we have the list of model objects, we can run predictvals() to get predicted values
from each model, using the ldply() function:
predvals <- ldply(models, . fun = predictvals, xvar = "ageYear" , yvar = "heightIn" )
predvals
sex ageYear heightIn
f 11.58000 57.96250
f 11.63980 58.03478
f 11.69960 58.10707
...
m 17.38040 70.64912
m 17.44020 70.78671
m 17.50000 70.92430
Finally, we can plot the data with the predicted values ( Figure 5-24 ):
ggplot(heightweight, aes(x = ageYear, y = heightIn, colour = sex)) +
geom_point() + geom_line(data = predvals)
Search WWH ::




Custom Search