SlideShare a Scribd company logo
1 of 30
UK QUARTERLY GAS CONSUMPTION
จัดทำโดย
นำย กิตติพศ อำสำพิทักท์ชำติ รหัส 57010093
นำย ชัยชนะ สีทัด รหัส 57010093
รหัสวิชำ 1076253 : ควำมน่ำจะเป็นและสถิติ (PROBABILITY AND STATISTICS) ภำคเรียนที่ 2 ปี 2558
สำขำวิชำคอมพิวเตอร์ คณะวิศวกรรมศำสตร์ สถำบันเทคโนโลยีพระจอมเกล้ำเจ้ำคุณทหำรลำดกระบัง
Link: https://vincentarelbundock.github.io/Rdatasets/csv/datasets/UKgas.csv
https://vincentarelbundock.github.io/Rdatasets/doc/datasets/UKgas.html
สำรบัญ
หัวเรื่อง สไลด์ที่
• ข้อมูลตัวอย่ำง 4
• ขั้นตอนกำรหำค่ำทำงสถิติแบบง่ำย โดยใช้โปรแกรม RStudio 5
• วิธีกำรเตรียมข้อมูล พร้อมภำพประกอบ 6
• กำรเรียกใช้ฟังชั่นต่ำงๆในทำงสถิติ 7
• วิธีกำรสร้ำงกรำฟ 9
• กรำฟต่ำงๆของตัวแปร UK GAS 11
• กรำฟต่ำงๆของตัวแปร Time 20
• สรุปผล 29
ข้อมูล : UK QUARTERLY GAS CONSUMPTION
ข้อมูลตัวอย่ำง
จำนวนข้อมูล
Time : เป็นเวลาที่ใช้ในการทาการสารวจในปี 1960 ถึง 1986 *แบ่งเป็นไตรมาตร
UK Gas : เป็นปริมาณแก็สในปีที่สารวจแบ่งเป็นไตรมาตรต่างๆ
ชื่อข้อมูล : UK Quarterly Gas Consumption
รายละเอียดข้อมูล : ไตรมาตร ปริมาณการใช้ก๊าซของสหราชอาณาจักรในปี 1960 ไตรมาตรที่ 1 ถึง 1986 ไตรมาตร 4
ขั้นตอนกำรหำค่ำทำงสถิติแบบง่ำย โดยใช้โปรแกรม RSTUDIO
1. เปิดใช้งานโปรแกรม RStudio
2. พิมพ์คาสั่งที่เราต้องการ เพื่อใช้ฟังชั่นของโปรแกรม R เพื่อหาค่าทางสถิติ เช่น hist() , summary()
3. ใช้คาสั่งจาก library ggplot2 เพื่อใช้ฟังชั่นเสริมของโปรแกรม R ในการวาดกราฟชนิดต่างๆ
วิธีกำรเตรียมข้อมูล พร้อมภำพประกอบ
1. เปิดโปรแกรม Rstudio ขึ้นมา
2. จากนั้นใช้คาสั่ง getwd() เพื่อให้เราทราบ file directory ของโปรแกรม R จากนั้นนาไฟล์ข้อมูล
(.csv) ไปไว้ใน file directory ดังกล่าว จากนั้นใช้คาสั่ง data <- read.csv(“ชื่อไฟล์”) เพื่อ
นาข้อมูลเข้ามาใช้
กำรเรียกใช้ฟังชั่นต่ำงๆในทำงสถิติ
1. ขั้นแรกเราต้องเตรียมข้อมูล โดยใช้คาสั่ง data <- read.csv(“ชื่อ
ไฟล์”) เพื่อที่เราจะได้สามารถนาข้อมูลมาใช้งานได้ โดยข้อมูลนั้นจะถูกเก็บอยู่ใน
ตัวแปรในโปรแกรม R
3. หาค่าเฉลี่ยจากคาสั่ง mean(data$ชื่อตัวแปร)
4. หาค่ามัธยฐานจากคาสั่ง median(data$ชื่อตัวแปร)
5. ใน R จะไม่มีคาสั่งในการหาฐานนิยมโดยตรงแต่สามารถทาได้โดยใช้คาสั่ง
which(table(data$ชื่อตัวแปร) == max(table(data$ชื่อ
ตัวแปร)))
2. เราสามารถเรียกใช้ข้อมูลได้จากการใช้ data ต่อด้วยชื่อตัวแปรข้อมูลของ
เรา โดยจะต้องคั่นด้วย $ จากภาพด้านขวาจะใช้ data$UKgas เพื่อดึง
ข้อมูลของ Ukgas ออกมาแสดงในรูปแบบ Vector
กำรเรียกใช้ฟั่งชั่นต่ำงๆในทำงสถิติ
6. หาค่าเบี่ยงเบนมาตรฐานโดยใช้คาสั่ง sd(data$ชื่อตัวแปร)
7. หาค่าความแปรปรวนโดยใช้คาสั่ง var(data$ชื่อตัวแปร)
8. หาค่าควอไทล์ที่ 1 และ 3 โดยใช้คาสั่ง quantile(data$
ชื่อตัวแปร)
9. สามารถสรุปค่าสถิติเบื้องต้นได้โดยใช้คาสั่ง
summary(data$ชื่อตัวแปร)
วิธีกำรสร้ำงกรำฟ
1. ขั้นแรกให้ใส่ install.packages(“ggplot2”) ก่อนถึงจะสามารถใช้ library ggplot2 ในการวาดกราฟของข้อมูล
ต่างๆได้
2. หลังจากนั้นให้เลือก 0-Cloud[https] ในเมนู HTTPS CRAN mirror แล้วกด OK
3. ใช้คาสั่ง library(“ggplot2”) เพื่อเริ่มใช้ฟังก์ชั่นของ ggplot2
HISTOGRAM GRAPH
1. ใช้คาสั่งดังนี้
ggplot(data,aes(UKgas))+geom_histogram(binwidth=154,colour=“Black”)
1.1 ggplot
-data เป็นข้อมูลจากไฟล์ .csv (จากตัวอย่างที่แล้ว)
-aes(x,y) เป็นการบอกให้ plot ตามแกน x แกน y แบบ
ไหน อิงจากค่าอะไร (ถ้าต้องการพล็อตค่าอื่นให้เปลี่ยนที่
UKgas)
-ถ้าไม่ใส่ค่า y จะถือว่าป็นการนับความถี่ของตัวแปรนั้นๆ
1.2 geom_histogram
- binwidth ค่าความกว้างในแต่ละชั้นของข้อมูล
- colour เป็นใส่สีให้กับขอบของแท่งกราฟ
จากที่เห็นฟังก์ชั่นด้านบนเราสามารถสังเกตได้ว่า ggplot นั้นเอาไว้กาหนดว่าแกน x แกน y จะมีข้อมูลแบบไหน และฟังก์ชั่นที่สองสามารถ
เพิ่มเข้าไปเพื่อบ่งบอกให้โปรแกรมนี้พล็อตกราฟในรูปแบบใด ซึ่งเรายังสามารถกาหนดคุณลักษณะต่างของกราฟที่เราจะพล็อตได้ด้วยเช่นความ
กว้างหรือสีของแท่งกราฟ
กรำฟต่ำงๆของตัวแปร UK GAS
1. ggplot(data,aes(UKgas))+geom_histogram(binwidth=154,colour=“black")
HISTOGRAM
HISTOGRAM POLYGON
2. ให้เพิ่มคาสั่ง +geom_freqpoly(binwidth=154,colour=“Green”) ต่อท้ายจากคาสั่งเดิมจากข้อ 1 จะได้ polygon graph คู่กับ
histogram
CUMULATIVE HISTOGRAM
3. เพิ่มพารามิเตอร์ใน geom_histogram ว่า aes(y=cumsum(..count..)) จะทาให้ได้กราฟ cumulative histogram มา
+geom_histogram(binwidth=154,colour="Black",aes(y=cumsum(..count..)))
4. ถ้าเราทาแบบเดียวกันกับข้อ 3 ให้ฟังก์ชั่น GEOM_FREQPOLY จะได้เป็น OGIVE มาโดยการเพิ่มในส่วนของโค้ด
+GEOM_FREQPOLY(BINWIDTH=154,COLOUR="GREEN")
OGIVE
ggplot(data,aes(UKgas))+geom_freqpoly(binwidth=154,colour="Green“)
HISTOGRAM POLYGON
ggplot(data,aes(UKgas))+geom_freqpoly(binwidth=154,colour="Green",aes(y=cumsum(..count..)))
OGIVE
STEM & LEAF
5. ใช้คาสั่ง stem(vector,scale=n) เพื่อให้ทาการพล็อตข้อมูลนั้นๆในรูปแบบของ stem&leaf
(n = จานวนเต็มใดๆใช้ในการกาหนดความละเอียด stem)
6. ใช้คาสั่ง BOXPLOT(VECTOR) เพื่อทาการพล็อตข้อมูลนั้นๆในรูปแบบ BOX PLOT (สามารถใช้ VECTOR กี่อันก็ได้
และตั้งชื่อผ่านพารามิเตอร์ NAMES หรือ XLAB)
- BOXPLOT(DATA$UKGAS)
BOX PLOT
กรำฟต่ำงๆของตัวแปร TIME
1. GGPLOT(DATA,AES(TIME))+ GEOM_HISTOGRAM(BINWIDTH=4,COLOUR=“BLACK")
HISTOGRAM
2. ให้เพิ่มคาสั่ง +geom_freqpoly(binwidth=4,colour=“Blue”) ต่อท้ายจากคาสั่งเดิม จะได้ polygon graph คู่กับ histogram
HISTOGRAM POLYGON
3. เพิ่มตาสั่งนี้ต่อจากข้อ1.+geom_histogram(binwidth=4,colour="Black",aes(y=cumsum(..count..)))
CUMULATIVE HISTOGRAM
4. เพิ่มคาสั่งนี้ต่อจากข้อ3.+geom_freqpoly(binwidth=4,colour=“Orange"), aes(y=cumsum(..count..)))
OGIVE
ggplot(data,aes(time))+geom_freqpoly(binwidth=4,colour=“Orange“)
HISTOGRAM POLYGON
ggplot(data,aes(time))+geom_freqpoly(binwidth=4,colour=“Orange",aes(y=cumsum(..count..)))
OGIVE
stem(data$time,scale=2)
STEM & LEAF
boxplot(data$time)
BOX PLOT
สรุปผล
จำกผลกำรวิเครำะห์ข้อมูลและกรำฟต่ำงๆพบว่ำเมื่อเวลำผ่ำนไปในแต่ละไตรมำสของปี ปริมำณกำรใช้ก๊ำซในสหรำช
อำณำจักรในแต่ละไตรมำสของปีนั้นจะมีอัตรำกำรเปลี่ยนแปลงของปริมำณกำรใช้แก๊สที่เหมือนกันในทุกปีคือช่วงไตรมำสแรก
ของปีนั้นจะมีปริมำณกำรใช้ก๊ำซสูงสุด จำกนั้นจะลดลงในไตรมำสที่ 2 และลดลงอีกเมื่อถึงไตรมำสที่ 3 แต่เมื่อถึงไตรมำสที่ 4
ปริมำณกำรใช้ก๊ำซก็จะกลับมำสูงขึ้นอีก
เรำสำมำรถเรียงลำดับจำกมำกไปหำน้อยได้ดังนี้ ไตรมำสที่ 1 > ไตรมำสที่ 4 > ไตรมำสที่ 2 > ไตรมำสที่ 3 ซึ่งเหตุผลที่
เป็นอย่ำงนี้ก็เพรำะว่ำสหรำชอำณำจักรนั้นในช่วงไตรมำสแรกของปีจะอยู่ในช่วงฤดูหนำวซึ่งจำเป็นต้องใช้ก๊ำซเพื่อเป็น
เชื้อเพลิงให้ควำมอบอุ่นแก่ผู้คน ส่วนในไตรมำสที่ 2 นั้นจะอยู่ในช่วงฤดูใบไม้พลิทำให้ปริมำณกำรใช้ก๊ำซลงมำ และเมื่อถึง
ไตรมำสที่ 3 ที่เป็นฤดูร้อนก็จะยิ่งใช้ปริมำณก๊ำซน้อยลงไปอีก แต่เมื่อเข้ำสู่ไตรมำสที่ 4 ซึ่งเป็นฤดูใบไม้ร่วงอำกำศเริ่มหนำวอีก
ครั้งปริมำณกำรใช้ก๊ำซจึงมำกขึ้นอีกครั้ง ทำให้เรำสำมำรถคำดกำร์ณได้ว่ำมันเกิดขึ้นเหมือนกันอย่ำงนี้ในทุกๆปีต่อจำกนี้
เมื่อเรำวิเครำะห์ข้อมูลในแต่ละปีพบว่ำปริมำณกำรใช้ก๊ำซเฉลี่ยในแต่ละปีนั้นมีอัตรำกำรเพิ่มขึ้นสูงขึ้นเรื่อยๆในแต่ละปี
ซึ่งเป็นผลมำจำกประชำกรที่เพิ่มขึ้น และเทคโนโลยีที่มีควำมแพร่หลำยมำกขึ้น ทำให้ปริมำณกำรใช้ก๊ำซเฉลี่ยนั้นสูงขึ้นตำมไป
ด้วยในทุกๆปี ทำให้เรำสำมำรถคำดกำร์ณได้ว่ำหลังจำกปี 1986 นั้นปริมำณกำรใช้ก๊ำซเฉลี่ยจะยิ่งสูงขึ้นอีก
จบกำรนำเสนอ
ขอบคุณครับ

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

UK Gas Consumption