This document contains a set of tasks that you need to do to complete the optional lab assignment. The lab assignment is focused on analyzing data related to the domestic politics and foreign policies of the United States since 1945. Successfully completing this assignment will require you to implement most of the techniques we’ve covered in the lab, including various descriptive statistics, creating new variables based on existing variables, creating numeric variables based on categoric variables and vice-versa, visualizing variables on their own and in terms of other variables, and statistically analyzing bivariate relationships.
Two things are important to note about this lab assignment. First, this lab is completely optional. However, if you complete the lab, I will replace your lowest grade of the semester with the grade you get on this lab if your grade on this lab is higher than your previous lowest lab grade. If your grade on this lab assign is worse than all of your other lab assignments, I will not replace your previous lowest grade with your grade on this lab assignment. Framed differently, completing this lab assignment can potentially raise your grade in the lab but it cannot hurt your grade.
Second, this is the only RStudio/RMarkdown file associated with the optional lab. The reason for this is that everything you need to know to complete the tasks in the assignment have been covered in the previous three lab assignments. Accordingly, there are no additional documents that provide you with information about the lab assignment and/or the code needed to complete the lab assignment.
Add your name and date in the lines underneath this document’s title.
You need to set your working directory in this section.
You’ll need to load the following packages to complete the lab assignment.
library("dplyr")
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library("tidyverse")
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ readr 2.1.5
## ✔ ggplot2 3.5.1 ✔ stringr 1.5.1
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library("openxlsx")
library("forcats")
library("corrr")
## Warning: package 'corrr' was built under R version 4.4.2
library("janitor")
## Warning: package 'janitor' was built under R version 4.4.2
##
## Attaching package: 'janitor'
##
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
You need to load the data set you’ll use for the lab assignment in this section.
You need to identify the names of the variables in the data set for the assignment in this section. You should consult the codebook in the “OptionalLabMaterials” folder for information about what the variables are measuring/capturing.
[1] "year" "rep.ideology" "dem.ideology"
[4] "polarization" "president.party" "divided"
[7] "war" "dissimilar.foreign.policy" "defense.burden"
[10] "gdp" "econ.percent.growth" "foreign.aid.percent"
You need to report a set of descriptive statistics in this section. First, identify the means of variables that identify 1) how much of its available economic resources the United States spends on its military; 2) how much of its available economic resources the United States spends on foreign aid; and 3) annual economic growth.
Second, you need to identify the median of variables that identify: 1) whether the United States had divided government and 2) whether the United States was involved in an interstate war.
2.[1] 0
Third, you need to identify the minimum, maximum, and range of variables that identify 1) the average ideology of Republican members of the House; 2) the average ideology of Democratic members of the House; and 3) the average polarization of the two parties in the House.
[1] 0.5081354(MAX) (MIN)[1] 0.2430265 (RANGE) [1] 0.2430265 0.5081354
(MAX) -0.2373247 (MIN) -.03945895 (RANGE) -.03945 -.2373
(MAX) .8922 (MIN) .5226 (RANGE) .5226 .8922
You need to create a set of graphs in this section. First, create a graph that plots the total number of years the United States was involved in an interstate war and the number of years that the United States was not involved in an interstate war. When making this graph, make sure to identify the total number of years the United States was and was not involved in an interstate war.
Years.At.War.Label 1 No war 56 | 2 War 24
Second, create a single graph that plots the percentage of years that the United States was involved in an interstate war and the percentage of years that the United States was not involved in an interstate war. This graph should identify the percentage of total years the United States was and was not involved in a war on the graph.
Third, you need to graph the distributions of variables that identify 1) how much of its available economic resources the United States spends on its military and 2) how much of its available economic resources the United States spends on foreign aid. Both of these distributions should be filled in with the color “red.”
Finally, all of the graphs in this section should look “clean” and professional. Specifically, they should 1) not have extraneous lines, colors, and/or components in the background and 2) have descriptive axis labels, not the names of the variables. Details about these points are provided in previous lab assignments.
You need to create a set of graphs that allow you to visualize bivariate relationships.
First, create a set of graphs that visualize 1) the average ideology of Republican members of the House over the years in the data set; 2) the average ideology of Democratic members of the House over the years in the data set; and 3) how much of its available economic resources the United States spends on foreign aid over annual economic growth.
Second, create a set of graphs that visualize 1) how much of its available economic resources the United States spends on foreign aid depending on whether or not the United States has a divided government; 2) annual economic growth depending on whether the president is a member of the Democratic Party or the Republican Party; and 3) how much of its available economic resources the United States spends on foreign aid depending on whether or not the United States is involved in an interstate war.
Third, create a contingency table between variables that identify whether or not the United States is involved in an interstate war and whether or not the United States has divided government.
Divided.Gov
Years.At.War 0 1
0 21 35
1 11 13
You need to statistically analyze a set of bivariate relationships in this section.
First, identify the bivariate correlation between variables that identify 1) how much of its available economic resources the United States spends on its military and how much of its available economic resources the United States spends on foreign aid; 2) how much of its available economic resources the United States spends on its military and how dissimilar the United States’ foreign policy preferences are from its neighbors and other major powers; and 3) polarization and economic growth.
defense.burden foreign.aid.percent
1 defense.burden NA -0.269
2 foreign.aid.percent -0.269 NA
defense.burden dissimilar.foreign.policy
1 defense.burden NA -0.558
2 dissimilar.foreign.policy -0.558 NA
polarization econ.percent.growth
1 polarization NA -0.151
2 econ.percent.growth -0.151 NA
Second, identify whether we observe systematically different patterns of 1) economic growth depending on whether the president is a democrat or a republican; 2) how dissimilar the United States’ foreign policy preferences are from its neighbors and other major powers depending on whether the president is a democrat or a republican; and 3) how much of its available economic resources the United States spends on its military depending on whether polarization is greater than average in the United States.
data: econ.percent.growth by Presidents.Choice t = -0.27867, df = 65.061, p-value = 0.7814 alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0 95 percent confidence interval: -1.2262493 0.9259384 sample estimates: mean in group 0 mean in group 1 2.792955 2.943111
data: dissimilar.foreign.policy by Presidents.Choice t = 0.75003, df = 65.278, p-value = 0.4559 alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0 95 percent confidence interval: -0.03316048 0.07305188 sample estimates: mean in group 0 mean in group 1 0.5071366 0.4871909
Third, identify whether the following things are related to one another: 1) whether the United States is involved in a war and whether the president is a democrat or a republican and 2) whether the United States has divided government and whether the United States is involved in an interstate war.
data: OptionalAssignmentData$Divided.Gov X-squared = 32, df = 79, p-value = 1
data: OptionalAssignmentData$Years.At.War and OptionalAssignmentData$Presidents.Choice X-squared = 0.059524, df = 1, p-value = 0.8073
Click the “Knit” button to publish your work as an html document. This document or file will appear in the folder specified by your working directory. You will need to upload both this RMarkdown file and the html file it produces to AsU Learn to get all of the points associated with this lab.