MSU

MSU密歇根州立大学 | PLS 202 Introduction to Data Analytics and the Social Sciences | R语言 Assignment2代写

PLS 202: Module 2 Assignment
Question 1

  1. Load the “Assignment2_SS25_data.rda” dataset using load function. When you did it correct, you
    will see anes_data appear in your environment.
  2. How many rows and columns are in the data?
  3. Print out all the variable names with one line of code.
  4. Print the first row in the dataset (hint: don’t forget commas!).
  5. Print the last 3 rows in the dataset
    Question 2
    The “lcself” variables means how the respondents place themselves in political ideology. Each value means
    1: very liberal, 2: somewhat liberal, 3: closer to liberals, 4: neither liberal nor conservative, 5: closer to
    conservatives, 6: somewhat conservative, and 7: very conservative.
  6. What is the mean of “lcself”? How would you explain the resulting value?
  7. Create a new dummy (binary) variable called “liberal”, for those who answered they are ideologically
    liberals. Assign 1 if “lcself” is less than or equal to 3 (1-3); and 0 if “lcself” is greater than 3 (4-7).
  8. What is the mean of “liberal”? What does it mean?
    Question 3
  9. Variables “ftdem” and “ftrep” are Feeling Thermometer toward Democratic and Republican Parties.
    It ranges from 0 to 100, where 100 means very warm and favorable feeling, while 0 is very cold and
    unfavorable. Create a new variable called “favor_rep”, by subtracting “ftdem” from “ftrep”. [Hint:
    you can just do ftrep- ftdem]
  10. Sort the dataset by the favor_rep, from the largest to smallest. Call this new object sorted_data.
  11. Print the first 5 rows of this new sorted_data, with only 2 columns: favor_rep, and lcself. Can you
    f
    ind one irregular observation from the 5 respondent? [Hint: A high value of ‘favor_rep’ means they
    extremely favor Republican Party over Democratic Party. On the contrary, ‘lcself’ is a 7-scale variable
    where 7 means very conservative and 1 means very liberal.]
    1
    Question 4
  12. The variable “profile_state” shows the residing state of each respondent. Create a new dataset which
    only contains observations from Michigan, and call it mi_data. (Hint: find the data that “profile_state”
    is equal to “MI”)
  13. Calculate the mean of “lcself” from the Michigan dataset. Does it different with the mean from the
    total dataset? How do you interpret the result?
  14. Draw a simple plot with the X variable ftdem and Y variable ftrep from the Michigan dataset. Give
    the appropriate labels for the title and axis. Can you find any trend?
    2