Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
---
title: "Causal Impact"
output: causal_impact_notebook
---
```{r}
install.packages("devtools")
install.packages("curl")
install_github("skardhamar/rga")
install.packages("CausalImpact")
```
```{r}
library(devtools)
library(curl)
library(CausalImpact)
library(ggplot2)
library(rga)
```
```{r}
rga.open(instance = "ga")
```
```{r}
id <- ""
ga$getData(id)
```
```{r}
gaData <- ga$getData(id, start.date = as.Date("2017-10-01"),end.date=as.Date("2019-05-30"), metrics = "ga:sessions",dimensions = "ga:date", segment = "gaid::G1FqL1zpQHaaeoBTJlIOxA")
```
```{r}
ggplot(gaData, aes(date, sessions)) + geom_line() +
ylab("Daily Sessions") + theme_bw() +
ggtitle("Organic Sessions")
```
```{r}
pre.period <- as.Date(c("2017-10-01", "2019-02-24"))
post.period <- as.Date(c("2019-02-25", "2019-05-30"))
```
```{r}
impact <- CausalImpact(gaData, pre.period, post.period, model.args = list(niter = 5000))
plot(impact)
summary(impact)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.