-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabWEek6.Rmd
More file actions
92 lines (74 loc) · 2.55 KB
/
Copy pathLabWEek6.Rmd
File metadata and controls
92 lines (74 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
title: "LabWeek6"
output: html_document
date: "2026-02-26"
---
```{r}
library(tidyverse)
setwd("~/Desktop/Oxford/QStep")
```
```{r}
lijphart <- read.csv("lijphart_data.csv")
```
```{r}
ggplot(data = lijphart) +
geom_boxplot(mapping = aes(x = "1990", y = womens_parl_representation_1990)) +
geom_boxplot(mapping = aes(x = "2010", y = womens_parl_representation_2010)) +
xlab("Year") + ylab("Percentage of women in national parliaments")
median(lijphart$womens_parl_representation_1990)
median(lijphart$womens_parl_representation_2010)
var(lijphart$womens_parl_representation_1990, na.rm = TRUE)
var(lijphart$womens_parl_representation_2010, na.rm = TRUE)
```
This shows a higher median of women in parliament in 2010, and a higher dispersion in 1990.
Testing the median and variance numerically shows that the graphical observations line up.
```{r}
sd(lijphart$womens_parl_representation_1990)
sqrt(var(lijphart$womens_parl_representation_1990))
sd(lijphart$womens_parl_representation_2010)
sqrt(var(lijphart$womens_parl_representation_2010))
```
```{r}
cov(lijphart$exec_parties_1945_2010,
lijphart$cpi_1981_2009, use = "complete.obs")
cor(lijphart$exec_parties_1945_2010,
lijphart$womens_parl_representation_2010)
```
covariance is hard to interpret -> use correlation coefficient which is constrained between -1 and +1
```{r}
lijphart %>%
select(exec_parties_1945_2010,
womens_parl_representation_1990,
womens_parl_representation_2010,
cpi_1981_2009,
incarceration_2010) %>%
cor(use = "pairwise.complete.obs") %>%
round(3)
```
Bivarate linear regression
```{r}
ggplot(data = lijphart) +
geom_point(mapping = aes(x = exec_parties_1945_2010,
y = womens_parl_representation_2010)) +
xlab("Consensus Democracy (Executives-Party Dimension)") +
ylab("Percentage of Women in Parliament") +
geom_smooth(method="lm", mapping = aes(x = exec_parties_1945_2010,
y = womens_parl_representation_2010), se = FALSE)
```
```{r}
lm(data = lijphart, womens_parl_representation_2010 ~ exec_parties_1945_2010)
lm(lijphart$womens_parl_representation_2010 ~ lijphart$exec_parties_1945_2010)
my_model <- lm(data = lijphart,
womens_parl_representation_2010 ~ exec_parties_1945_2010)
summary(my_model)
```
```{r}
install.packages("stargazer")
library(stargazer)
model_unemployment <- lm(data = lijphart,
unemployment_1991_2009 ~ exec_parties_1945_2010)
stargazer(model_unemployment, type = "text")
stargazer(model_unemployment, out = "unemployment_regression.html")
```
R^2 tells how good a model is. higher = better
R^s shows difference between predicted and actual data