การคำนวนผลที่ได้จากนโยบายด้วย Causal Impact Analysis

การคำนวนผลที่ได้จากนโยบายด้วย Causal Impact Analysis

29 June 2021

ไม่ว่าจะเป็นองค์กรของรัฐบาลหรือบริษัทเอกชน ผู้ที่มีอำนาจตัดสินใจย่อมต้องการวัดผลที่ได้รับจากนโยบายหรือโครงการที่ได้นำมาใช้เพื่อประเมินว่าผลที่ได้รับนั้นคุ้มค่ากับค่าใช้จ่ายในการดำเนินนโยบายหรือไม่ โดยวันนี้เราจะมาทำความรู้จักกับการทำ Causal Impact Analysis

ตัวอย่างในวันนี้เราจะทำการวิเคราะห์ผลกระทบต่อราคาหุ้นของเครือ Volkswagen หลักจากที่ถูกฟ้องร้องเรื่องละเมิดกฎหมายควบคุมมลพิษ เหตุการณ์ครั้งนี้เป็นที่รู้จักกันในชื่อว่า Volkswagen Emission Scandal

โดยปกติแล้ว คำถามประเภทนี้เราจะนำข้อมูลจากกลุ่มตัวอย่างที่ไม่ได้รับผลกระทบมาเปรียบเทียบ แต่ในกรณีนี้นั้นเป็นไปไม่ได้ ดังนั้นเราจะใช้ข้อมูลที่มีก่อนเกิดเหตุการณ์เพื่อมาใช้ทำนายค่าชี้วัดหลังจากเกิดเหตุการณ์ และนำผลมาเปรียบเทียบ

Causal Impact Analysis: Simple Model

เราจะใช้ R programming เพื่อทำการวิเคราะห์ในบทความนี้ เราจะเริ่มโดยการ plot ข้อมูลราคาปิดตลาดต่อหุ้นของ Volkswagen เพื่อพิจารณา ก่อนอื่นเราจะโหลด packages ที่จำเป็นแล้วก็เริ่มทำการ plot (หากยังไม่เคยติดตั้ง packages เหล่านี้ ให้ใช้คำสั่งที่ถูก commented ไว้นะครับ)

Figure 1: กราฟแสดงราคาหุ้นของเครือ Volkswagen ช่วงก่อนและหลัง Emission Scandal

จะเห็นได้ว่า หลังจากเส้นประที่ขีดไว้ ราคาปิดตลาดต่อหุ้นนั้นลดลงอย่างรวดเร็วมาก เราต้องการประเมินว่าผลกระทบนี้เป็นเท่าไหร่  เบื้องต้นเราอาจจะใช้วิธีการ Time Series แบบมาตรฐานเพื่อนำมาใช้ประเมิน จะได้ผลการวิเคราะห์ดังนี้

options(warn = -1)



# กำหนดช่วงก่อนและหลังเกิดเหตุการณ์
pre.period <- as.Date(c(start, "2015-09-14"))
post.period <- as.Date(c("2015-09-21", end))
impact_vw_reg <- CausalImpact(series, pre.period, post.period, model.args = list(niter = 1000, nseasons = 52))
# niter คือ จำนวนครั้งการทำ Optimisation Steps
# nseasons คือ ค่าความยาวของ seasonality cycle ในกรณีนี้เราใช้เป็น 52 (สัปดาห์)= 1 ปี



plot(impact_vw_reg)
Figure 2: แสดงผลการทำ Causal Impact Analysis ภาพด้านบนสุดเป็นการเปรียบเทียบค่าที่เกิดขึ้นจริง และค่าที่น่าจำเกิดขึ้นถ้าไม่มีเหตุการณ์ ภาพกลางแสดงผลต่าง และภาพล่างสุดแสดงผลต่างสะสม

จะเห็นได้ว่าการประเมินในรูปแบบนี้ไม่สามารถใช้ได้ในระยะยาว เนื่องจากค่าความไม่แน่นอนจะสูงขึ้นอย่างรวดเร็ว ซึ่งค่อนข้างสมเหตุสมผล เนื่องจากว่าข้อมูลราคาในอดีตอาจจะบอกข้อมูลได้ไม่สมบูรณ์ ดังนั้นเราจะเลือกนำ Time Series ชุดอื่นที่มีพฤติกรรมคล้าย ๆ กัน และไม่ได้รับผลกระทบจากเหตุการณ์นี้ ในกรณีนี้เราจะนำเอาราคาปิดตลาดของผู้ผลิตรถยนต์รายอื่น เช่น BMW และ Allianz มาพิจารณาเปรียบเทียบกัน

start = "2011-01-03"
end = "2017-03-20"
quote = "AdjClose"



# ดาวน์โหลดข้อมูลราคาหุ้น
VolksWagen <- get.hist.quote(instrument = "VOW.DE", start, end, quote, compression = "w")
BMW <- get.hist.quote(instrument = "BMW.DE", start, end, quote, compression = "w")
Allianz <- get.hist.quote(instrument = "ALV.DE", start, end, quote, compression = "w")



# นำ Time Series ทั้งสามอันมารวมเป็น Data Frame
series <- cbind(VolksWagen, BMW, Allianz)
scandalDate <-ymd('2015-09-14')
colnames(series) <- c("VolksWagen", "BMW", "Allianz")
autoplot(series, facet = NULL) + 
    xlab("") +
    ylab("Adjusted Close Price")+
    geom_vline(xintercept = scandalDate, linetype = 'dashed')
Figure 3: ราคาหุ้นเปรียบเทียบทั้งสามกลุ่มผู้ผลิตรถยนต์

จะพบว่าแนวโน้มของทั้งสามราคามีค่าใกล้เคียงกัน แต่ว่า BMW และ Allianz ไม่ได้รับผลกระทบกับคดีความครั้งนี้ เราจึงมีแนวคิดที่ว่าจะใช้ Time Series ของราคา BMW และ Allianz เพื่อมาทำนายราคาในกรณีที่การฟ้องร้องครั้งนี้ไม่เกิดขึ้น

Bayesian Structural Time Series

Bayesian Structural Analysis จะนำเอาการ Regression มารวมกันกับเทคนิคทาง Time Series โดยจะสรุปได้ในโดยสมการ

เราจะใช้ Package ใน software R และหลักการทาง Bayesian Inference เพื่อประมาณค่าของ  และค่าความคลาดเคลื่อนที่เป็นไปได้ของการประมาณ โดยผลลัพธ์ที่ได้สามารถนำมาแสดงผลได้ดังแผนภาพข้างล่างนี้ โดยที่ตัวแปร series ในโค้ดข้างล่างนี้เป็นตัวแปรเดียวกันกับโค้ดที่ใช้สร้าง Figure 3 ข้างบน

library(CausalImpact)

# ระบุวันที่ช่วงก่อน และหลังเกิดเหตุการณ์
pre.period <- as.Date(c(start, "2015-09-14"))
post.period <- as.Date(c("2015-09-21", end))

# นำข้อมูลที่ได้มาใส่ใน CausalImpact package เพื่อทำการวิเคราะห์
impact_vw_reg <- CausalImpact(series, pre.period, post.period, 
                              model.args = list(niter = 1000, nseasons = 52))

plot(impact_vw_reg)

 จะเห็นได้ว่า confidence interval นั้นไม่ได้กว้างขึ้นในระยะยาว ทำให้การทำนายระยะยาวพอมีความเป็นไปได้มากขึ้น นอกจากนี้เรายังสามารถดู Summary Statistics เพื่อประเมินความมั่นใจของค่าประมาณของเราได้

Figure 4: สรุปผล Impact และ Confident Interval ของเหตุการณ์ครั้งนี้ โดยเฉลี่ยเหตุการณ์ครั้งนี้ทำให้ราคารายวันโดยประมาณ 46USD จากที่ควรจะเป็น 176USD

References

  1. Causal Impact Package   – ทดลองการแยก Impact ด้วย Intervention ที่จำลองขึ้นมา
  2. Causal Impact Analysis on Volkswagen Emissions Scandal – การวิเคราะห์ impact ของ Emissions Scandal

Formal Senior Data Scientist at Big Data Institute (Public Organization), BDI

แบ่งปันบทความ

กลุ่มเนื้อหา

แท็กยอดนิยม

แจ้งเรื่องที่อยากอ่าน

คุณสามารถแจ้งเรื่องที่อยากอ่านให้เราทราบได้ !
และเราจะนำไปพัฒนาบทความให้มีเนื้อหาที่น่าสนใจมากขึ้น

PDPA Icon

We use cookies to optimize your browsing experience and improve our website’s performance. Learn more at our Privacy Policy and adjust your cookie settings at Settings

Privacy Preferences

You can choose your cookie settings by turning on/off each type of cookie as needed, except for necessary cookies.

Accept all
Manage Consent Preferences
  • Strictly Necessary Cookies
    Always Active

    This type of cookie is essential for providing services on the website of the Personal Data Protection Committee Office, allowing you to access various parts of the site. It also helps remember information you have previously provided through the website. Disabling this type of cookie will result in your inability to use key services of the Personal Data Protection Committee Office that require cookies to function.
    Cookies Details

  • Performance Cookies

    This type of cookie helps the Big Data Institute (Public Organization) understand user interactions with its website services, including which pages or areas of the site are most popular, as well as analyze other related data. The Big Data Institute (Public Organization) also uses this information to improve website performance and gain a better understanding of user behavior. Although the data collected by these cookies is non-identifiable and used solely for statistical analysis, disabling them will prevent the Big Data Institute (Public Organization) from knowing the number of website visitors and from evaluating the quality of its services.

  • Functional Cookies

    This type of cookie enables the Big Data Institute (Public Organization)’s website to remember the choices you have made and deliver enhanced features and content tailored to your usage. For example, it can remember your username or changes you have made to font sizes or other customizable settings on the page. Disabling these cookies may result in the website not functioning properly.

  • Targeting Cookies

    "This type of cookie helps the Big Data Institute (Public Organization) understand user interactions with its website services, including which pages or areas of the site are most popular, as well as analyze other related data. The Big Data Institute (Public Organization) also uses this information to improve website performance and gain a better understanding of user behavior. Although the data collected by these cookies is non-identifiable and used solely for statistical analysis, disabling them will prevent the Big Data Institute (Public Organization) from knowing the number of website visitors and from evaluating the quality of its services.

Save settings
This site is registered on wpml.org as a development site. Switch to a production site key to remove this banner.