-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject_graph_sketches.Rmd
More file actions
147 lines (101 loc) · 2.93 KB
/
project_graph_sketches.Rmd
File metadata and controls
147 lines (101 loc) · 2.93 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
title: "Project graph sketches"
author: "J. Hamski"
date: "May 8, 2016"
output: html_document
---
```{r}
library(ggplot2)
library(dplyr)
library(tidyr)
```
```{r}
load("ConsumerExpectationsExplorer/data_demo.Rda")
load("ConsumerExpectationsExplorer/data_all.Rda")
load("ConsumerExpectationsExplorer/survey_microdata.Rda")
```
```{r}
library(ggbiplot)
```
```{r}
question.PCA <- unique(data.demo$Question)[1]
PCA.dataset <- data.demo %>%
unite(col = Survey, Question, Demographic) %>%
spread(key = Survey, value = results) %>%
select(-date) %>%
select(matches(question.PCA)) %>%
as.matrix() %>%
prcomp(tol = sqrt(.Machine$double.eps), scale = T)
```
```{r}
ggbiplot(PCA.dataset, obs.scale = 1, var.scale = 1, circle = TRUE)
```
```{r}
PCA.dataset2 <- data.all %>%
unite(col = Survey, Question, survey) %>%
spread(key = Survey, value = results) %>%
select(-date) %>%
as.matrix() %>%
prcomp()
```
```{r}
ggbiplot(PCA.dataset2, obs.scale = 1, var.scale = 1, circle = TRUE)
```
```{r}
require(caret)
trans = preProcess(PCA.dataset,
method=c("BoxCox", "center",
"scale", "pca"))
PC = predict(trans, PCA.dataset)
```
```{r}
ggbiplot(PC, obs.scale = 1, var.scale = 1, circle = TRUE)
```
```{r}
seasonal.decom.data <- data.all %>%
filter(Question == "Inflation expectations") %>%
filter(survey == "Median one-year ahead expected inflation rate") %>%
select(results)
seasonal.decom.data <- ts(seasonal.decom.data$results, deltat = 1/12)
```
```{r}
stl.series <- stl(seasonal.decom.data, s.window="periodic")
```
```{r}
library(caret)
```
```{r}
featurePlot(x = microdata[,c(78,85, 88)],
y = microdata[,162],
plot = "pairs",)
```
```{r}
source('project_theme.R')
```
Factor
```{r}
column.1 <- "`Financially better or worse off 12 months from now`"
ggplot(microdata) + geom_bar(aes_string(x = column.1), stat = "count") + project.theme()
```
Number
```{r}
column.2 <- "`Rate of inflation / deflation over next 12 months`"
ggplot(microdata, aes_string(x = column.2)) + geom_density() + xlim(-100, 100)
```
```{r}
q = quantile(as.matrix(select_(microdata, column.2)), na.rm = TRUE, probs = c(0.1, 0.9))
```
```{r}
ifelse(typeof(select_(microdata, column.1)[[1]]) == "double", "yes", "no")
```
All Repondents vs Demographic Comparisons
```{r}
survey.input = "Median one-year ahead expected inflation rate"
demo.input.question = "Median One Year Ahead Inflation Rate Expectation"
demo.input.demo = "Education High School or Less"
#values <- c("All Respondents" = "blue", demo.input.demo[1] = "red")
ggplot() +
geom_line(data = filter(data.all, survey == survey.input), aes(x = date, y = results, color = "All Respondents")) +
geom_line(data = filter(data.demo, Question == demo.input.question & Demographic == demo.input.demo), aes(x = date, y = results, color = as.character(demo.input.demo))) +
scale_color_manual(values = c("blue", "red"))
```