代做Assignment 3代做留学生R程序

- 首页 >> Database作业

Assignment 3

Instructions

For Part 1, you will use R and the dataset assignnment3.csv. Make sure you include library(tidyverse) when you start your session!

The dataset you will be working with is a cross-section of countries (unit of analysis, or rows, are a country) with data from the World Bank. The variables in the dataset are as follows:

• cerealcrops: the metric tons of cereal crops the country produced (tons of corn, rice, oats, wheat, ect.)

• primeduc: the percentage of persons over 15 who have primary school as their highest educational attainment (note, a country that is high on this dimension means most adults have not completed high school, whereas a country that is low is one where most adults have completed a level of school higher than primary.)

• gdp: the most recent gross domestic product of the country

• smoke: the percentage of the adult population that reports smoking tobacco products.

• infmort: the rate of infant mortality per 1,000 births.

• lifeexp: the life expectancy of women in the country

• pop: the total population count

• urbpop: the percentage of the population that lives in urban areas.

• continent: the continent the country is in.

• democ: a binary measure of whether the country is a democracy.

For R related questions:

• You do not need to copy and paste every plot into your answer document - I will know what the plots look like, you can instead just copy and paste your script. in the end, and if anything seems off, I will check your code for partial credit.

• Be sure to provide complete comments on what you see: if you see a histogram, comment on the shape, if you run a regression, tell me what the direction of the relationship is, what it means in substantive terms, and whether it is statistically significant.

• Reach out with any questions!

For Part 2, you are given a set of cases to examine to select case studies. You will not need to run any R code for Part 2!

Part 1

Question 1

A. Provide a five number summary of infant mortality

summary(df$infmort)

What is the median, mean, and interquartile range of infant mortality? What do these metrics help us describe?

B. Make a histogram of the relationship

ggplot(df, aes(infmort)) +

geom_histogram()

Describe the shape and spread of the distribution. Based on your answer in Part A, are you surprised by the shape, or does it seem consistent with the central tendency and spread that you found earlier?

C. Your friend says that there must be a problem with the data, since the Central Limit Theorem implies the shape should be a symmetric and unimodal bell curve. How would you respond to them?

Question 2

You theorize that democracies are more responsive to needs of the people they govern, therefore, the life expectancy in democratic states should be longer than in autocratic ones.

A. By adapting what you did in Assignment 2 to find difference in means, find the difference in means for life expectancy between democracies and non democracies (using the variable democ). Be sure to do a t-test, and describe the substantive and statistical signifigance of what you see.

B. Now, suppose we run a regression instead to evaluate our hypothesis. Run the regression

m = lm(lifeexp ~ democ, data = df)

summary(m)

Interpret the regression results in the same way (describing substantive and statistical significance). Does the difference in means test match the regression test?

Question 3

Below are four regressions where life expectancy is the dependent variable and the independent variables are: primeduc (percentage of adults who have only completed primary school, nothing beyond), urbpop (percentage of persons living in cities), smoke (percentage of adults that smoke), and pop (total population).

For each plot, comment on i.) the direction of the relationship ii.) the strength of the relationship and iii.) whether the plots show any signs that linear regression may be inappropriate.

A. IV Primary education

ggplot(df, aes(primeduc, lifeexp)) +

geom_point() +

geom_smooth(method = 'lm')

B. IV Urban population

ggplot(df, aes(urbpop, lifeexp)) +

geom_point() +

geom_smooth(method = 'lm')

C. IV Smoking

ggplot(df, aes(smoke, lifeexp)) +

geom_point() +

geom_smooth(method = 'lm')

D. IV population

ggplot(df, aes(pop, lifeexp)) +

geom_point() +

geom_smooth(method = 'lm')

Question 4

Suppose you have a theory that countries that grow cereal crops (grains, including rice, wheat, corn, oats) have better economies. Use the data on cerealcrops and gdp to make a scatter plot of the relationship. The code below will also include a regression line through the points and will label the name of the country that corresponds to each point.

ggplot(df, aes(cerealcrops, gdp, label = country)) +

geom_point() +

geom_smooth(method = 'lm') + geom_text(vjust = -1, hjust = 0.5)

A. Do any of the points look like outliers? Why or why not?

B. If any points look like outliers, are the residuals positive or negative in each case? What would a positive or negative residual mean?

Question 5

A. Show the correlation between smoking and infant mortality. Comment on the sign and strength of the relationship.

cor(df$smoke, df$infmort)

B. Generate a scatter plot of the relationship - does it match the correlation? Describe what you see in the plot, does it match what you would have assumed?

ggplot(df, aes(smoke, infmort)) +

geom_point()

C. Suppose we want to run a regression. What are the advantages of running a regression versus correlation?

D. Now let’s run the regression. What do the results tell you? If 10 percent more persons aged over 15 began smoking, what would happen to infant mortality?

m = lm(infmort ~ smoke, data = df)

summary(m)

E. Applying the regression mistakes discussed in lecture and the Wheelen reading, what may be explaining the relationship? Discuss at least 2 that may and one that does not not apply.

F. Now, let’s generate a plot highlighting points by country. What does this show? What concept from lecture does this remind you of?

ggplot(df, aes(smoke, infmort, color = continent)) +

geom_point(size = 1.5)

G. Run the following regression including what continent the country is from as a control variable. Comment on the sign, strength, statistical, and practical significance of the estimated relationship between smoking and infant mortality when adjusting estimates for what continent the country is in. Does this change the answer? Use what you see from the plot in part F to to explain what you found.

m = lm(infmort ~ smoke + continent, data = df)

summary(m)

Part 2

You don’t need to use R for this part!

Suppose you have collected data on 25 countries (called “case1” “case2” etc.). These counties are displayed in Table 1. For each country, you have data on per capita income, the percent of the population who are high school graduates, and the percent of the eligible adult population that turned out to vote in the last national election. You also have information about how tough it is for voters to register in each country — an ordinal scale ranging from very low (easy to register) to very high (hard to register). (Assume this is a reliable and valid measure based on whether there is same day voter registration, poll taxes, accessible polling places etc.).

Summary statistics for each variable are also provided below.

HS Grad Summary

## Min. 1st Qu. Median Mean 3rd Qu. Max.

## 31.00 42.00 59.00 57.24 70.00 86.00

Income Summary

## Min. 1st Qu. Median Mean 3rd Qu. Max.

## 5626 15189 20740 25192 32047 49754

Turnout Summary

## Min. 1st Qu. Median Mean 3rd Qu. Max.

## 44.00 60.00 68.00 69.96 83.00 90.00

Regisration Requirement Summary

##

## high low medium very high very low

## 5 6 12 1 1

Table 1: Candidate Cases

Case

Percap_I

HSgrad

RegReq

Turnout

case1

15189

60

high

44

case2

44090

31

medium

68

case3

29709

79

low

85

case4

15697

63

low

74

case5

14224

32

high

51

case6

29713

50

medium

64

case7

17636

64

medium

57

case8

32047

35

medium

65

case9

38800

70

high

52

case10

31003

74

low

83

case11

19584

42

medium

58

case12

13875

49

high

87

case13

20740

86

medium

90

case14

45726

76

very low

90

case15

18718

47

medium

69

case16

24416

59

medium

73

case17

43115

78

medium

77

case18

7922

53

low

66

case19

42669

69

medium

90

case20

14047

54

very high

56

case21

49754

84

medium

84

case22

27160

40

high

63

case23

15889

70

low

63

case24

5626

32

low

80

case25

12455

34

medium

60

Assume we have elected to conduct case studies to test our hypothesis, and that the 25 counties we have here are the population of counties within a given state.

A. Say we want to test a hypothesis: higher levels of income and education lead to greater voter turnout. What other functions could case studies serve besides testing a hypothesis?

B. If you want to choose a “deviant’ ’ case, assuming our hypothesis is that higher levels of income and education lead to greater voter turnout. What may you choose and why?

C. Name a case selection (you only need to provide 1 county) that may be seen as “cherry picking’ ’ to support the income and education hypothesis discussed thus far - why would cherry picking be concerning?

D. Several scholars have argued that less restrictive (low to medium) voter registration is a necessary condition for high voter turnout. Are there any cases in your data set that would provide evidence against this argument?

E. Suppose we want to examine the effect of only education on turnout. Pick a set of 3 cases that would be a good choice for causal inference. What kind of a sampling strategy would this be?

F. Name three cases that would be bad to choose due to selection on the dependent variable. Why would this be a problem?

G.Your friend wants to test the theory that income predicts turnout. They run a regression of turnout on income and produces the following plot. They say Case 17 is the clear choice to test the hypothesis, and should be the only one that is sampled. What would we call this sampling approach, and what are the drawbabcks if our goal is hypothesis testing? When may we want to use the sampling approach that they proposed?




站长地图