3. In this question we will experiment with Pearson's correlation coefficient. First, load the dataset states_data.csv...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
3. In this question we will experiment with Pearson's correlation coefficient. First, load the dataset states_data.csv as well as pandas, numpy, and matplotlib. Throughout this ques- tion, we will use the variables prcapinc, the mean income per capita in each state, and vep12_turnout, the percentage voter turnout in the 2012 presidential election in the data. (a) Write a python function called my standardize that takes as input a numpy array and returns an array containing the standardized version of all the values in the input array. To do so recall that: np. mean will return the mean of an array, and np. std will return the standard deviation of an array. (b) Using the standardization function you just wrote, write a python function called my_corr that takes as input two equally sized numpy arrays and output the Pearson correlation between them. You can use the function test_corr included in the code for this assign- ment to test whether the function you wrote works. If running: test-corr() outputs True, then it does, if it outputs False, then it does not. In this case go back to your code and debug it until it works. (c) Using the standardization function you just wrote, standardize the variables prcapinc, and vep12_turnout. Create scatterplots with prcapinc on the x-axis and vep12_turnout on the y-axis for both the standardized and unstandardized versions of these variables. (d) What do you observe in the scatterplots from the previous questions? Are the variables easier to compare once standardized? Briefly explain your answer. (e) Using your function, compute the correlation between the variables. Interpret this cor- relation and describe its implications. 3. In this question we will experiment with Pearson's correlation coefficient. First, load the dataset states_data.csv as well as pandas, numpy, and matplotlib. Throughout this ques- tion, we will use the variables prcapinc, the mean income per capita in each state, and vep12_turnout, the percentage voter turnout in the 2012 presidential election in the data. (a) Write a python function called my standardize that takes as input a numpy array and returns an array containing the standardized version of all the values in the input array. To do so recall that: np. mean will return the mean of an array, and np. std will return the standard deviation of an array. (b) Using the standardization function you just wrote, write a python function called my_corr that takes as input two equally sized numpy arrays and output the Pearson correlation between them. You can use the function test_corr included in the code for this assign- ment to test whether the function you wrote works. If running: test-corr() outputs True, then it does, if it outputs False, then it does not. In this case go back to your code and debug it until it works. (c) Using the standardization function you just wrote, standardize the variables prcapinc, and vep12_turnout. Create scatterplots with prcapinc on the x-axis and vep12_turnout on the y-axis for both the standardized and unstandardized versions of these variables. (d) What do you observe in the scatterplots from the previous questions? Are the variables easier to compare once standardized? Briefly explain your answer. (e) Using your function, compute the correlation between the variables. Interpret this cor- relation and describe its implications.
Expert Answer:
Answer rating: 100% (QA)
Answer Below is the Python code that addresses the requirements import pandas as pd import numpy as ... View the full answer
Related Book For
Posted Date:
Students also viewed these databases questions
-
Jessica lives with her parents and attends the local state college. The local state college is operated by the state government, and tuition is free. Jobs that pay $10 an hour are available to high...
-
Discuss how servant leader could exhibit a high level of emotional intelligence and why exhibiting a high level of emotional intelligence is a desirable leadership competency.
-
Consider the cash flows in Table P6.7 for the following investment projects (MARR = 15%). Determine the annual equivalent worth for each project at i = 15% and determine the acceptability of each...
-
What is one purpose of the linear correlation coefficient?
-
In this chapter, we use the metaphor of a cookie cutter and cookies that are made from the cookie cutter to describe classes and objects. In this metaphor, are objects the cookie cutter, or the...
-
The composite post in Figure 1.49 has the same properties and dimensions as in Problem 1.13, except that there is a gap = 0.1 mm between the top of thecover plate on the post and the upper support....
-
Auditors typically will find the items lettered AF in a client-prepared bank reconciliation. Required : Assume these facts: On October 11, the auditor received a cutoff bank statement dated October...
-
14. We run a CFD simulation with Ansys Fluent and Figure 3 shows the residuals of the three equations (at the left-hand top) during iterations. a) If the simulation stops after 50 iterations, what is...
-
Dwight Donovan, the president of Donovan Enterprises, is considering two investment opportunities. Because of limited resources, he will be able to invest in only one of them. Project A is to...
-
b) Compute (f-)(23), where f-1 is the inverse of f. 12
-
(a) Appraise Netflixs long-term solvency and asset management ratios over the last three years. The presentation of the answer should be well-organised, impactful and should not exceed 400 words. (b)...
-
Why have some major Australian banks been engaging in share buybacks in the past year? Your answer should explain the meaning of share buybacks and outline their rationale in terms of capital...
-
Imagine that you work in web media, and your company publishes news and analysis. Success is measured by the amount of time visitors stay on the site consuming content (longer time is better). Two...
-
Proponents argue that HFT aids our markets by providing increased. What is one counter-argument to this claim? If we desire to thwart HFT, what is one legislative move that we can do to get them out...
-
CMC Plc. is a manufacturing organisation in the construction industry. While there is boom in this line of business, some product portfolios have not been doing well and CMC is no exception. The...
-
Hailu Sherwin paperboard company expects to sell 600 units in January ,700 units in February and 1200 units in march. January's beginning inventory is 800 units. expected sales for the whole year is...
-
Write a program to move a signed number from smaller register to bigger register. Hint: movzx ax, bl Topic: Data Related Operators and Directives in assembly language
-
Assuming that labor is mobile, is it true that wages always must be equal across the sectors in the specific-factors model?
-
After German reunification and the disintegration of communist rule in Eastern Europe, most countries in that region sought to join the European Union (EU), including the Economic and Monetary Union...
-
This exercise considers how the FX market will respond to changes in monetary policy. For these questions, define the exchange rate as British pounds () per euro, E / . Use the FX and money market...
-
Can the displacement of a persons trip be zero, yet the distance involved in the trip is nonzero? How about the reverse situation? Explain.
-
Speed is the magnitude of velocity. Is average speed the magnitude of average velocity? Explain.
-
The average velocity of a jogger on a straight track is computed to be +5 km/h. Is it possible for the joggers instantaneous velocity to be negative at any time during the jog? Explain.
Study smarter with the SolutionInn App