शुरू करेंमुफ़्त में शुरू करें

Visualizing parallel slopes

The two plots in the previous exercise gave very different predictions: one gave a predicted response that increased linearly with a numeric variable; the other gave a fixed response for each category. The only sensible way to reconcile these two conflicting predictions is to incorporate both explanatory variables in the model at once.

When it comes to a linear regression model with a numeric and a categorical explanatory variable, ggplot2 doesn't have an easy, "out of the box" way to show the predictions. Fortunately, the moderndive package includes an extra geom, geom_parallel_slopes() to make it simple.

taiwan_real_estate is available; ggplot2 and moderndive are loaded.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Intermediate Regression in R

पाठ्यक्रम देखें

अभ्यास निर्देश

  • Using the taiwan_real_estate dataset, plot house prices versus the number of nearby convenience stores, colored by house age.
  • Make it a scatter plot.
  • Add parallel slopes, without a standard error ribbon.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Using taiwan_real_estate, plot price_twd_msq vs. n_convenience colored by house_age_years
___ +
  # Add a point layer
  ___ +
  # Add parallel slopes, no ribbon
  ___
कोड संपादित करें और चलाएँ