This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
#Setup
getwd()
## [1] "C:/Users/홍지민/Desktop/24-1/데이터"
setwd("C:/Users/홍지민/Desktop/24-1/데이터")
orders <- read.csv("executive_orders.csv")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── 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(ggplot2)
library(dplyr)
#1
issue_factor <- list(
"1" = "Macroeconomics",
"2" = "Civil rights",
"3" = "Health",
"5" = "Labor",
"6" = "Education",
"7" = "Environment",
"8" = "Energy",
"9" = "Immigration",
"10" = "Transportation",
"12" = "Law and crime",
"13" = "Social welfare",
"14" = "Housing",
"15" = "Domestic commerce",
"16" = "Defense",
"17" = "Technology",
"19" = "International affairs",
"20" = "Government operations",
"21" = "Public lands"
)
order <- data.frame(majortopic = c("1", "2", "3", "5", "6", "7", "8", "9", "10", "12", "13", "14", "15", "16", "17", "19", "20", "21"))
order$issuename <- issue_factor[as.character(order$majortopic)]
ggplot(data = orders)
geom_line(mapping = aes(x = year, y = num_eo))
## mapping: x = ~year, y = ~num_eo
## geom_line: na.rm = FALSE, orientation = NA
## stat_identity: na.rm = FALSE
## position_identity
facet_wrap(~ issuename, nrow = 6, scales = "free")
## <ggproto object: Class FacetWrap, Facet, gg>
## compute_layout: function
## draw_back: function
## draw_front: function
## draw_labels: function
## draw_panels: function
## finish_data: function
## init_scales: function
## map_data: function
## params: list
## setup_data: function
## setup_params: function
## shrink: TRUE
## train_scales: function
## vars: function
## super: <ggproto object: Class FacetWrap, Facet, gg>
labs(y = "Number of Executive Orders")
## $y
## [1] "Number of Executive Orders"
##
## attr(,"class")
## [1] "labels"
When there is a big event like oil shock and IMF, the number of executive orders increases regardless of category.
#2
#mip_percent,
mod1 <- lm(num_eo ~ mip_percent, data = orders)
summary(mod1)
##
## Call:
## lm(formula = num_eo ~ mip_percent, data = orders)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.1805 -2.3886 -1.3886 0.5931 27.5033
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.3886 0.1387 17.215 < 2e-16 ***
## mip_percent 3.5439 1.2225 2.899 0.00382 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.953 on 1027 degrees of freedom
## Multiple R-squared: 0.008116, Adjusted R-squared: 0.00715
## F-statistic: 8.403 on 1 and 1027 DF, p-value: 0.003825
# the estimate value has positive value with 3.54
#3
ggplot(data = orders)
geom_point(mapping = aes(x = mip_percent, y = num_eo))
## mapping: x = ~mip_percent, y = ~num_eo
## geom_point: na.rm = FALSE
## stat_identity: na.rm = FALSE
## position_identity
geom_smooth(mapping = aes(x = mip_percent, y = num_eo), method = "lm", se = FALSE)
## mapping: x = ~mip_percent, y = ~num_eo
## geom_smooth: na.rm = FALSE, orientation = NA, se = FALSE
## stat_smooth: na.rm = FALSE, orientation = NA, se = FALSE, method = lm
## position_identity
summarize_mod1 <- summary(mod1)
coefficient_estimate <- coef(summarize_mod1)["mip_percent", "Estimate"]
standard_error <- coef(summarize_mod1)["mip_percent", "Std. Error"]
t_statistic <- coefficient_estimate / standard_error
critical_t_value <- qt(0.025, df = df.residual(mod1))
Since t_statistic is 2.8989 and critical value is -1.96, t value is bigger thus it can reject the hypothesis that was mip_percent is not related and leads to the decrease in num_eo in significance 0.05 level.
c(3.5439 - t_statistic * 1.2225, 3.5439 + t_statistic * 1.2225)
## [1] 0.0000338654 7.0877661346
which results in 0.0000338654 to 7.0877661346.