Created
October 8, 2019 08:38
-
-
Save natzir/5ff92f4c7c4625c1f4b8a41b56996d6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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