Homework 5

Basic Introduction to Coding and R Script

10 Points

This homework is due four (4) days after your registered lab section before

11:55pm. Please read and follow the directions. If you have any questions,

contact your TA or attend office hours.

This week you will be creating code within R Script. Follow all instructions

carefully.

Start by opening Rstudio and then creating a new RScript.

For the following assignment, write all your code within the editor/script window.

This editor/script window is the one you will turn in once finished with your

assignment.

Imagine you’re in an economics class here at Davis, and you have been talking

about the correlation between country GDP (Gross Domestic Product) and child

illiteracy rates. You’re interested in the topic so you start doing some of your own

research and calculations.

1. You find that world GDP is 88 billion and US GDP is 21 billion. Create and

assign the variables “WorldGDP” and “USGDP” to the values above. Now

create an equation (using the variables you created) in which you find the

proportion of US GDP in relation to the world’s GDP – assign the outcome

of this equation to the variable “USOutputPercentage”

2. After doing this calculation, you realized you mistook trillions for billions

and your variables are off. To fix this, reassign the two variables (on two

new lines!), WorldGDP and USGDP to the correct values, 88 trillion and

21 trillion respectively. Notice that value of USOutputPercentage won’t

change since the USGDP and WorldGDP are going up by equal

proportions.

3. You find that the five countries with the highest GDP are as follows (all in

trillions): US – 21 China – 15 Japan – 5 Germany – 4 India – 3

a. Create a variable “Largest5” and assign it to the GDPs of the five

countries above (using condensed values such as 21 instead of

21,000,000,000,000 is advised)

b. You are interested in what the largest five economies would look

like if they all grew by 3.6% next year. Create an equation that uses

the “Largest5” variable to answer that question. In the code for this

equation, add your name and lab time into a comment.

In doing all your research, you find a dataset that has the GDP of multiple

countries along with their corresponding child illiteracy rates

“GDPChildIlliteracyF19.” Download this dataset.

1. Start by loading the dataset into R.

2. You’re interested in the child illiteracy rates for each continent. Subset the

data by Continent (North America, South America, Africa, Asia, Australia, and

Europe) and then find the mean of the child illiteracy rate for each of the 6

continents.

3. You want to learn more about Asia illiteracy rates. Start by creating a boxplot

of the child illiteracy rates in Asia (Hint: use the Asia subset you created in

#2)

4. Create a histogram of child illiteracy rates in Asia, specifically the child

illiteracy data. Label the x-axis "Child Illiteracy", the y-axis "Frequency", and

the main title "Asia Child Illiteracy Rates Histogram"

5. Plot the Asia data with Child Illiteracy on the x-axis and GDP on the y-axis

(use the function: plot). After you have your plotted data, run a linear

regression on the data (use the function: lm)

6. Add the line of best fit to your plot (use the function: abline)

What you need to submit for this assignment:

1. The RScript file that contains all the code that you used to complete this

assignment. Save as RScript_LASTNAME

2. The boxplot. Save as boxplot (PDF)

3. The histogram with labels and title. Save as histogram (PDF)

4. The Asia Child Illiteracy plot with the line of best fit. Save as Plot (PDF)

Upload these 4 items to Canvas.

版权所有：留学生作业网 2018 All Rights Reserved 联系方式：QQ:99515681 电子信箱：99515681@qq.com

免责声明：本站部分内容从网络整理而来，只供参考！如有版权问题可联系本站删除。