forked from dtkaplan/CompactInference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
130-Outside-of-the-normal.Rmd
62 lines (53 loc) · 2.06 KB
/
130-Outside-of-the-normal.Rmd
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
# Outside of the normal
```{r include=FALSE}
SDSdata::sds_setup()
knitr::opts_knit$set('bookdown.internal.label' = FALSE)
```
About ranks, transformations, ...
Hooker and Yule paper, 1906
```{r}
load("data/Wheat_export.rda")
cor(export ~ price, data = Wheat_export)
cor(export ~ production, data = Wheat_export)
cor(rank(export) ~ rank(price), data = Wheat_export )
cor(rank(export) ~ rank(production), data = Wheat_export )
cor(diff(export) ~ diff(price), data = Wheat_export)
cor(diff(export) ~ diff(production), data = Wheat_export)
gf_point(export ~ price, data = Wheat_export)
gf_point(export ~ production, data = Wheat_export)
plot(diff(export) ~ diff(price), data = Wheat_export)
plot(diff(export) ~ diff(production), data = Wheat_export)
lm(diff(export) ~ diff(production) + diff(price), data = Wheat_export) %>%
summary()
plot(rank(diff(export)) ~ rank(diff(price)), data = Wheat_export)
plot(rank(diff(export)) ~ rank(diff(production)), data = Wheat_export)
```
They computed indices, which seem to be the standardized annual differences.
```{r}
Indices <-
with(Wheat_export,
data.frame(export = diff(export),
price = diff(price),
production = diff(production))) %>%
mutate(export = (export - mean(export))/sd(export),
price = (price - mean(price))/sd(price),
production =
(production - mean(production))/sd(production))
gf_point(export ~ price, data = Indices)
gf_point(export ~ production, data = Indices)
summary(lm(export ~ price + production, data = Indices))
```
What if we do it with log proportional change ...
```{r}
Deltas <- with(Wheat_export,
data.frame(delta_export = diff(log(export)),
delta_price = diff(log(price)),
delta_production = diff(log(production))
)
)
cor(delta_export ~ delta_price, data = Deltas)
cor(delta_export ~ delta_production, data = Deltas)
gf_point(delta_export ~ delta_price, data = Deltas)
gf_point(delta_export ~ delta_production, data = Deltas)
summary(lm(delta_export ~ delta_price + delta_production, data = Deltas))
```