官术网_书友最值得收藏!

Checking linearity with scatter plots

A basic way of checking the linearity assumption is to make a scatter plot with the dependent variable in the y axis and an independent variable in the x axis. If the relation appears to be linear, the assumption is validated. In any interesting problem it's extremely hard to find a scatter plot that shows a very clear linear relation, and if it does happen we should be a little suspicious and careful with the data. To avoid reinventing the wheel, we will use the plot_scatterlot() function we created in Chapter 2, Understanding Votes with Descriptive Statistics:

plot_scatterplot(
    data = data,
    var_x = "Age_18to44",
    var_y = "Proportion",
    var_color = FALSE,
    regression = TRUE
)
plot_scatterplot(
    data = data,
    var_x = "Students",
    var_y = "Proportion",
    var_color = FALSE,
    regression = TRUE
)

As we can see, the scatter plot on the left shows a clear linear relation, as the percentage of people between 18 and 44 years of age (Age_18to44) increases, the proportion of people in favor of leaving the EU (Proportion) decreases. On the right hand, we see that the relation among the percentage of students in a ward (Students) and Proportion is clearly linear in the initial area (where Students is between 0 and 20), after that the relation too seems to be linear, but it is polluted by observations with very high percentage of students. However, we can still assume a linear relation between Students and Proportion.

When we're doing a Multiple Linear Regression as we're doing here, the assumption should be checked for the rest of the variables, which we omit here to preserve space, but we encourage you to do so. Keep in mind that it's very hard to find a linear relation in all of them, and this assumption is mostly an indicator of the predictive power of the variable in the regression. As long as the relation appears to be slightly linear, we should be all set.

主站蜘蛛池模板: 民勤县| 明光市| 扶沟县| 宁强县| 莲花县| 新密市| 通道| 邹平县| 灵武市| 姜堰市| 滕州市| 台南县| 九江县| 武冈市| 新巴尔虎右旗| 喜德县| 松桃| 中西区| 个旧市| 沙雅县| 潮安县| 黔西县| 八宿县| 固始县| 崇仁县| 邵武市| 丰城市| 克山县| 盈江县| 兖州市| 和平区| 苍梧县| 洮南市| 温宿县| 图们市| 屯留县| 贡嘎县| 井陉县| 三门县| 芒康县| 灵石县|