San Diego State University – Department of Electrical and Computer Engineering
EE300 – Computational and Statistical Methods of Electrical Engineers
Fall 2018 – MATLAB Project
The following dataset was obtained from the Organization for Economic Cooperation and Development (OECD) website on the Gross Domestic Product (GDP) per capita and the Life Satisfaction Index (LSI) of the following countries:
Index | Country | GDP in | Life Satisfac- |
$1000 USD | tion Index (LSI) | ||
1. | Australia | 33.4 | 7.3 |
2. | Austria | 32.5 | 7 |
3. | Belgium | 30.0 | 6.9 |
4. | Canada | 29.9 | 7.3 |
5. | Chile | 16.6 | 6.7 |
6. | Czech Republic | 21.1 | 6.6 |
7. | Denmark | 29.0 | 7.5 |
8. | Estonia | 18.7 | 5.6 |
9. | Finland | 29.5 | 7.5 |
10. | France | 31.1 | 6.4 |
11. | Germany | 33.7 | 7 |
12. | Greece | 17.0 | 5.2 |
13. | Hungary | 16.8 | 5.3 |
14. | Iceland | 30.5 | 7.5 |
15. | Ireland | 25.4 | 7 |
16. | Israel | 24.0 | 7.2 |
17. | Italy | 26.1 | 5.9 |
18. | Japan | 28.6 | 5.9 |
19. | Korea | 21.7 | 5.9 |
20. | Latvia | 15.3 | 5.9 |
21. | Luxembourg | 41.3 | 6.9 |
22. | Mexico | 13.9 | 6.6 |
23. | Netherlands | 28.8 | 7.4 |
24. | New Zealand | 24.4 | 7.3 |
25. | Norway | 35.7 | 7.5 |
26. | Poland | 18.9 | 6 |
27. | Portugal | 20.5 | 5.2 |
28. | Slovak Republic | 20.2 | 6.1 |
29. | Slovenia | 20.5 | 5.8 |
30. | Spain | 23.1 | 6.4 |
31. | Sweden | 30.6 | 7.3 |
32. | Switzerland | 36.4 | 7.5 |
33. | Turkey | 17.1 | 5.5 |
34. | United Kingdom | 28.4 | 6.7 |
35. | United States | 44.0 | 6.9 |
36. | Brazil | 12.2 | 6.6 |
37. | Russia | 16.7 | 6 |
38. | South Africa | 10.9 | 4.8 |
You should define x as a vector recording the data for the GDP and y as a vector recording the life satisfaction index. You can save your data into a ‘mat’ file by the MATLAB function save(’data.mat’,’x’,’y’).
Next time when you retrieve the data, use the MATLAB function load(’data.mat’). Perform the following tasks:
1
- Find the (sample) means of the GDP and the LSI and store them as mX and mY .
Suggestion: You may wish to try the MATLAB functions mean(x) and mean(y).
- Find the (sample) standard deviation of the GDP and the LSI and store them as stdX and stdY .
Suggestion: You may wish to try the MATLAB functions std(x) and std(y).
- Find the range (i.e., the maximum and the minimum values) of the GDP.
Suggestion: You may wish to try the MATLAB functions max(x), min(x) and range(x).
- Divide the range into N = 8 equal-length segments (hereafter called “bins”) and for each bin, find its bound (aj,bj) as well as its center cj for j = 1,2,…,
Suggestion: It might be convenient to store aj’s in a vector a, bj’s in a vector b and cj’s in a vector c with an appropriate length.
- Sort the data and place each GDP value xi into that bin whose lower bound is less than or equal to xi and whose upper bound is greater than xi; thereafter, for each bin count the number of xi assigned to it (= nj).
- (2pt) Plot a histogram of the measured GDP using N = 8 bars.
Suggestion: You may wish to try the MATLAB functions hist(x,N) and bar(c,n).
- Produce a vector xa of the recorded GDP in which the numbers are arranged in ascending order.
- (2pt) Determine the median of the GDPs by writing a script that is usable for both odd and even number of samples. Print your result and compare it with the result obtained from the MATLAB function median(x).
- Define a random variable W as the GDP of a randomly selected country, and estimate (i.e., determine approximately) the probability mass function of this random variable, evaluated at the each of the bin centers cj.
- Estimate the (cumulative) probability distribution function of the same random variable W, evaluated at the same points (i.e., argument values) cj.
Suggestion: You may wish to try the MATLAB function cumsum(n)/sum(n).
- (2pt) Produce a plot of the cumulative probability distribution function (found above) as a function of its argument, in which the plot has a title, axes have a scale and a label, and the graph is piece-wise linear plot between points at the bin centers.
- (2pt) Illustrate the data in the table using a scatter plot with the horizontal axis representing the GDP and the vertical axis representing the LSI. From the plot, determine whether the GDP and the LSI have positive correlation, negative correlation or no correlation.
Suggestion: You may wish to try the MATLAB function scatter(x,y).
- Find the sample covariance of the GDP and the LSI and store it as covXY .
Suggestion: You may wish to try the MATLAB command n/(n − 1) ∗ mean((x − mx). ∗ (y − my)).
- (2pt) Find the correlation coefficient from the sample covariance and the standard deviations of the GDP and the LSI. Print the obtained correlation coefficient, and determine if the calculation confirms with your observation from the scatter plot.
Please turn in your MATLAB script in one section and the results/plots in another section. Deadline: Dec 17, 2018. Please place the hard copy under the door of E-408 office.
2