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

  • R Programming By Example
  • Omar Trejo Navarro
  • 267字
  • 2021-07-02 21:30:43

Setting up the data

As it's usual with data analysis, the first step is to understand the data we will be working with. In this case, the data is the same as in Chapter 2, Understanding Votes with Descriptive Statistics, and we have already understood some of its main characteristics. Mainly, we've understood that age, education, and race have considerable effects over the propensity to vote in favor of the UK leaving or remaining in the EU.

The focus of this chapter will be on using linear models to predict the Proportion and Vote variables, which contain the percentage of votes in favor of leaving the EU and whether the ward had more votes for "Leave" or "Remain", respectively. Both variables have similar information, the difference being that one is a numerical continuous variable with values between 0 and 1 (Proportion) and the other is a categorical variable with two categories (Vote with Leave and Remain categories).

We'll keep observations that contain complete cases in the data object, and observations that have missing values for the Proportion and Vote variables in the data_incomplete object (we'll make predictions over these in the latter part of this chapter). The functions prepare_data(), adjust_data(), and get_numerical_variables() come from Chapter 2, Understanding Votes with Descriptive Statistics, so you may want to take a look if you're not clear about what they do. Basically, they load the data with the adjusted version that we created by compressing the data spread among various variables regarding age, education, and race:

data <- adjust_data(prepare_data("./data_brexit_referendum.csv"))

data_incomplete     <- data[!complete.cases(data), ]
data                <- data[ complete.cases(data), ]
numerical_variables <- get_numerical_variable_names(data)
主站蜘蛛池模板: 九寨沟县| 广河县| 临清市| 松溪县| 长沙市| 游戏| 永嘉县| 思茅市| 玉门市| 祁连县| 南华县| 陆丰市| 濮阳县| 筠连县| 霞浦县| 卢湾区| 苏尼特左旗| 陇川县| 泸溪县| 青岛市| SHOW| 汉源县| 奉贤区| 阿瓦提县| 盐津县| 额尔古纳市| 怀仁县| 湘阴县| 万载县| 东丰县| 百色市| 盐池县| 巨野县| 文化| 咸丰县| 肃北| 綦江县| 晋州市| 建瓯市| 济南市| 云安县|