forked from adamkaplan0/PML_Good_coding_practices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
69 lines (69 loc) · 2.22 KB
/
.Rhistory
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
setwd("C:/Users/adamk/Dropbox (MIT)/Current/PML_Good_coding_practices_example")
renv::init()
renv::snapshot()
setwd("C:/Users/adamk/Dropbox (MIT)/Current/PML_Good_coding_practices/PML_Good_coding_practices_example")
renv::activate()
install.packages("styler")
styler:::set_style_transformers()
styler:::style_active_file()
# Libraries and setup #######
#
library(here)
library(readr)
library(stargazer)
library(ggplot2)
# Let `here` know what file this is using RELATIVE paths
here::i_am("analysis/analysis.R")
# Analysis ##################
#
# Can use here to access data using RELATIVE paths
data <- readr::read_csv(here("data/simulated-data.csv"))
# Run regression
regression <- lm(y ~ x + 1, data = data)
# Outputs ###################
#
## Save table ###############
summary(regression)
stargazer::stargazer(regression, out = here("report/tables/regression.tex"))
## Plot results #############
### Base R version ##########
png(here("report/figures/regression.png"))
plot(data$x, data$y)
lines(data$x, predict(regression), col = "red")
dev.off()
# Libraries and setup #######
#
library(here)
library(readr)
library(stargazer)
library(ggplot2)
# Let `here` know what file this is using RELATIVE paths
here::i_am("analysis/analysis.R")
# Analysis ##################
#
# Can use here to access data using RELATIVE paths
data <- readr::read_csv(here("data/simulated-data.csv"))
# Run regression
regression <- lm(y ~ x + 1, data = data)
# Outputs ###################
#
## Save table ###############
summary(regression)
stargazer::stargazer(regression, out = here("report/tables/regression.tex"))
## Plot results #############
### Base R version ##########
png(here("report/figures/regression.png"))
plot(data$x, data$y)
lines(data$x, predict(regression), col = "red")
dev.off()
### GGplot version ##########
plotting_data <- data
plotting_data$predictions <- predict(regression)
ggplot2::ggplot(plotting_data, aes(x = x, y = y)) +
geom_point() +
geom_line(aes(y = predictions), color = "red")
ggplot2::ggsave(here("report/figures/regression_ggplot.png"))
debugSource("C:/Users/adamk/Dropbox (MIT)/Current/PML_Good_coding_practices/PML_Good_coding_practices_example/analysis/analysis.R")
plot(data$x, data$y)
lines(datas$x, predict(regression), col = "red")
print(datas$x)