-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcrypto.R
50 lines (41 loc) · 1.85 KB
/
crypto.R
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
library(ggpubr)
library(ggplot2)
library(ggthemes)
library(sjPlot)
# Input data from chart
x = c(4,13,35,14,410,88,162,8,53,4,24)
y = c(30,41,39,33,85,76,94,34,49,72,94)
z = c(8,40,55,48,1181,211,631,12,66,86,40)
# Create a dataframe from the data
df = data.frame(days_declining = x, percent_decline = y, days_recovering = z)
# Create column that calculates rate of decline as a new variable
df2 = mutate(df, decline.per.day = percent_decline/days_declining)
# Creates a log of outcome variable of interest
df2$log_days_declining = log(df2$days_declining)
# Creates a linear scatter plot (not a very good fit)
ggscatter(df2, x = "decline.per.day", y= "log_days_declining", add = c("reg.line"), conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson")
# See statistical analysis of linear model
fit = lm(log_days_declining ~ decline.per.day, data = df2)
summary(fit)
sjt.lm(fit,show.fstat=TRUE)
# Creates lowess curve (much better fit)
ggplot(df2, aes(x=decline.per.day,y=log_days_declining)) +
geom_point() +
geom_smooth(method="loess",span=1) +
geom_vline( xintercept = 56/49, color="red") +
scale_y_continuous(breaks=seq(0,6,by=0.5)) +
scale_x_continuous(breaks=seq(0,25,by=1)) +
ggtitle("Predicting how many days BTC downtrend takes based on average rate of decline") +
theme_economist() + scale_colour_economist()
# Creates lm curve
ggplot(df2, aes(x=decline.per.day,y=days_declining)) +
geom_point() +
geom_smooth(method = "lm", formula = log(y) ~ poly(x,4), span=1) +
geom_vline( xintercept = 56/49, color="red") +
scale_y_continuous(breaks=seq(0,6,by=0.5)) +
scale_x_continuous(breaks=seq(0,25,by=1)) +
ggtitle("Predicting how many days BTC downtrend takes based on average rate of decline") +
theme_economist() + scale_colour_economist()
fit2 = lm(days_declining ~ poly(decline.per.day,4), data = df2)
summary(fit2)
sjt.lm(fit2,show.fstat=TRUE)