Giter VIP home page Giter VIP logo

Comments (2)

etiennebacher avatar etiennebacher commented on August 14, 2024 1

Hi, I second this, it would be very convenient to have a function to plot the trends of the treated unit(s) and of the synthethic control of single_augsynth() and multisynth().

@Germancampos regarding your second point, plot returns a ggplot object, meaning that you can then customize it as you want with other ggplot2 functions (and extensions). Here's an example coming from the multisynth vignette:

library(magrittr)
library(dplyr)
library(augsynth)
library(ggplot2)

data <- read.csv("https://dataverse.harvard.edu/api/access/datafile/:persistentId?persistentId=doi:10.7910/DVN/WGWMAV/3UHTLP", sep="\t")

data %>%
  filter(!State %in% c("DC", "WI"),
         year >= 1959, year <= 1997) %>%
  mutate(YearCBrequired = ifelse(is.na(YearCBrequired), 
                                 Inf, YearCBrequired),
         cbr = 1 * (year >= YearCBrequired)) -> analysis_df

ppool_syn <- multisynth(lnppexpend ~ cbr, State, year, 
                        nu = 0.5, analysis_df)

plot(summary(ppool_syn), levels = "Average", label = FALSE) +
  theme_dark() +
  geom_line(color = "red") +
  geom_point(color = "red") +
  labs(title = "This is my plot")

foo1

Note however that the red line and points are simply put above the default black ones. This means that adding something like linetype = "dashed" in geom_line() will show parts of the original line (see below). Since these lines and points are hardcoded in plot, I don't think it is possible to remove them.

foo2

from augsynth.

ebenmichael avatar ebenmichael commented on August 14, 2024 1

@etiennebacher that's right. I think you could remove plot elements from the ggplot object and add new ones, but at that point, you should make your own plot directly from the results.

@Germancampos for your first question about plotting on the outcome scale, you can do this by accessing the effect estimates directly. After running the summary function for either single_augsynth or multisynth, you can take the att element of the summary object to get the estimates. E.g. for the example above summary(ppool_syn)$att will give a data frame of all the effect estimates. You can then merge this in with the actual data to graph the outcome series and it's synthetic control.

Here's how that looks for the kansas dataset and single_augsynth:

library(tidyverse)
library(augsynth)
data(kansas)

# fit augsynth and get effect estimates
syn <- augsynth(lngdpcapita ~ treated, fips, year_qtr, kansas)
att <- summary(syn)$att

# combine with data
kansas %>%
  filter(state == "Kansas") %>%
  select(year_qtr, lngdpcapita) %>%
  inner_join(att, by = c("year_qtr"="Time")) %>%
  ggplot(aes(x = year_qtr)) +
    geom_line(aes(y = lngdpcapita)) +
    geom_line(aes(y = lngdpcapita + Estimate), lty = 2, color = "red")

That'll give you something like this

Screen Shot 2022-05-02 at 4 19 22 PM

That could be added in the future. My only caution is that plotting the outcomes directly like this makes it more difficult to see how well the synthetic control is fitting the pre-treatment periods, since it's all washed out in the overall trend in gdp.

from augsynth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.