Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need it in matlab. I know I haven't included the external files, but would appreciate a general code. Exercise 1 - US Presidential Election of
Need it in matlab. I know I haven't included the external files, but would appreciate a general code.
Exercise 1 - US Presidential Election of 1992 The file US-election-counties.csv contains, at the county level, demographic data and voting results for the 1992 presidential election in the US. A description of the variables for this data set is given in the file US-election-counties-var-explained.txt. In 1992, Ross Perot was an independent candidate in addition to the two main political parties (Democrats and Republicans). a) The population of the US in 1990 was estimated at 249.62 million. Verify that the counties present in this data set cover more than 99% of the US population. b) The state names are abbreviated with only two letters in the data set. With the help of the file US-states-abbrev.txt, add a variable that displays the full name of the state. c) Generate a table that displays, for every state, the median value of the percentage of votes at the county level, for each party. The table should look like this (use the full name for states): state Alabama Arizona | democrat republican 42.9 46.3 Perot 10.5 Wyoming d) Create a function plot.linreg(T, party, var) that has three inputs: the table T of the imported data set, a string variable party that represents the percentage of votes received by the party and another string variable var that represents a demographic variable of the data set. This function will create a scatter plot of the two variables party and var with the linear regression line. You will indicate in the plot title the values of the intercept, slope and unadjusted R. For example, the call plot linreg(T,"democrats","black") should produce a figure similar to Figure 1. e) Using plot_linreg(), create a figure with 15 subplots. The subplots will be organized in three rows, one for each political party and five columns. The column will represent the following variables: crime, income, college, white and black. f) Explore the dataset and describe (preferably with a figure) something you find interesting, that has not been covered in this exercise it could be trends, unexpected distribution, etc.). Exercise 1 - US Presidential Election of 1992 The file US-election-counties.csv contains, at the county level, demographic data and voting results for the 1992 presidential election in the US. A description of the variables for this data set is given in the file US-election-counties-var-explained.txt. In 1992, Ross Perot was an independent candidate in addition to the two main political parties (Democrats and Republicans). a) The population of the US in 1990 was estimated at 249.62 million. Verify that the counties present in this data set cover more than 99% of the US population. b) The state names are abbreviated with only two letters in the data set. With the help of the file US-states-abbrev.txt, add a variable that displays the full name of the state. c) Generate a table that displays, for every state, the median value of the percentage of votes at the county level, for each party. The table should look like this (use the full name for states): state Alabama Arizona | democrat republican 42.9 46.3 Perot 10.5 Wyoming d) Create a function plot.linreg(T, party, var) that has three inputs: the table T of the imported data set, a string variable party that represents the percentage of votes received by the party and another string variable var that represents a demographic variable of the data set. This function will create a scatter plot of the two variables party and var with the linear regression line. You will indicate in the plot title the values of the intercept, slope and unadjusted R. For example, the call plot linreg(T,"democrats","black") should produce a figure similar to Figure 1. e) Using plot_linreg(), create a figure with 15 subplots. The subplots will be organized in three rows, one for each political party and five columns. The column will represent the following variables: crime, income, college, white and black. f) Explore the dataset and describe (preferably with a figure) something you find interesting, that has not been covered in this exercise it could be trends, unexpected distribution, etc.)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started