PLS 202_ Module 2 Assignment (1)
.pdf
keyboard_arrow_up
School
Michigan State University *
*We aren’t endorsed by this school
Course
202
Subject
Political Science
Date
Apr 28, 2024
Type
Pages
5
Uploaded by ChancellorYakMaster1066
2/4/24, 6:21 PM
PLS 202: Module 2 Assignment
file:///C:/Users/ryank/Downloads/assignment2_blank.html
1/5
PLS 202: Module 2 Assignment
Download the assignment2_data.Rdata file from D2L and load the file into your R environment. It is a dataset with
three variables: country
, dem1999
, dem2016
which gives the country’s democracy score (how democratic it is) for
the year 1999, and dem2016
which gives the same for the year 2016. Feel free to use slides, readings, or the
internet to help with the assignment.
Each question is worth 2 points. Please make sure to submit your homework in PDF format, including all your code
and output. Failure to do so will result in a deduction of 2 points.
load('assignment2_data.RData')
Question 1
1. What were the mean democracy scores in 1999 and 2016? (Hint: don’t forget to tell R about missing
values?)
mean(polity$dem1999, na.rm = TRUE)
## [1] 5.172185
mean(polity$dem2016, na.rm = TRUE)
## [1] 5.948718
2. What about the minimum and maximum values from each year?
min(polity$dem1999, na.rm=TRUE)
## [1] 0
min(polity$dem2016, na.rm=TRUE)
## [1] 0
max(polity$dem1999, na.rm=TRUE)
## [1] 10
max(polity$dem2016, na.rm=TRUE)
2/4/24, 6:21 PM
PLS 202: Module 2 Assignment
file:///C:/Users/ryank/Downloads/assignment2_blank.html
2/5
## [1] 10
3. Print the first row in the polity dataset (hint: don’t forget commas!).
head(polity, n=1)
## country dem1999 dem2016
## 1 Afghanistan 0 1
Question 2
1. List the countries that had a democracy rating of 3 in 2016 (hint: there are 5) (another hint: R is funky and
will give you some rows that are all <NA>
, you can ignore these).
ifelse(polity$dem2016 == 3, polity$country, NA )
## [1] NA NA "Algeria" NA NA ## [6] NA NA NA NA NA ## [11] "Bangladesh" NA NA NA NA ## [16] NA NA NA NA NA ## [21] NA NA "Cambodia" NA NA ## [26] NA NA NA NA NA ## [31] NA NA NA NA NA ## [36] NA NA NA NA NA ## [41] "Djibouti" NA NA NA NA ## [46] NA NA NA NA "Fiji" ## [51] NA NA NA NA NA ## [56] NA NA NA NA NA ## [61] NA NA NA NA NA ## [66] NA NA NA NA NA ## [71] NA NA NA NA NA ## [76] NA NA NA NA NA ## [81] NA NA NA NA NA ## [86] NA NA NA NA NA ## [91] NA NA NA NA NA ## [96] NA NA NA NA NA ## [101] NA NA NA NA NA ## [106] NA NA NA NA NA ## [111] NA NA NA NA NA ## [116] NA NA NA NA NA ## [121] NA NA NA NA NA ## [126] NA NA NA NA NA ## [131] NA NA NA NA NA ## [136] NA NA NA NA NA ## [141] NA NA NA NA NA ## [146] NA NA NA NA NA ## [151] NA NA NA NA NA ## [156] NA NA NA NA NA
2/4/24, 6:21 PM
PLS 202: Module 2 Assignment
file:///C:/Users/ryank/Downloads/assignment2_blank.html
3/5
2. Did any of these countries also have a democracy rating of 3 in 1999? Which ones?
ifelse(polity$dem2016==3 & polity$dem1999==3, polity$country, NA)
## [1] NA NA NA NA NA NA ## [7] NA NA NA NA NA NA ## [13] NA NA NA NA NA NA ## [19] NA NA NA NA "Cambodia" NA ## [25] NA NA NA NA NA NA ## [31] NA NA NA NA NA NA ## [37] NA NA NA NA "Djibouti" NA ## [43] NA NA NA NA NA NA ## [49] NA NA NA NA NA NA ## [55] NA NA NA NA NA NA ## [61] NA NA NA NA NA NA ## [67] NA NA NA NA NA NA ## [73] NA NA NA NA NA NA ## [79] NA NA NA NA NA NA ## [85] NA NA NA NA NA NA ## [91] NA NA NA NA NA NA ## [97] NA NA NA NA NA NA ## [103] NA NA NA NA NA NA ## [109] NA NA NA NA NA NA ## [115] NA NA NA NA NA NA ## [121] NA NA NA NA NA NA ## [127] NA NA NA NA NA NA ## [133] NA NA NA NA NA NA ## [139] NA NA NA NA NA NA ## [145] NA NA NA NA NA NA ## [151] NA NA NA NA NA NA ## [157] NA NA NA NA
#Cambodia and Djibouti
3. What was Peru’s democracy score in 2016?
polity[polity$country == "Peru", c("dem2016")]
## [1] 9
Question 3
1. Create a new dataset which only contains observations from Somalia, call it somalia_data
.
somalia_data<-polity[polity$country == "Somalia", ]
2. Print the new dataset, did Somalia’s democracy score change from 1999 to 2016?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help