Wednesday 23 August 2017

การย้าย ค่าเฉลี่ย r โครงการ


วิธีคำนวณค่าเฉลี่ยเคลื่อนที่โดยไม่ใช้ตัวกรอง () มีคำตอบ zillion นี้เพราะคำถามของคุณเป็นจริง: ฉันจะเรียบชุดเวลาดังนั้นคุณสามารถค้นหาด้วยคำหลักที่เหมาะสม คำตอบของฉันคือใช้ค่าเฉลี่ยเคลื่อนที่ไม่ได้ less เป็นหนึ่งใน zillions ของทางเลือกที่คุณอาจพิจารณา โพสต์ใน CV (stats. stackexchange) สำหรับทางเลือกทางสถิติอื่น ๆ สำหรับการเรียบแบบเวลา นอกจากนี้ quotantlystanding ที่คุณแสดงไว้ข้างต้นมีข้อบกพร่อง โครงสร้างที่ใช้คือลูป (R ระดับ) คุณได้ทำการบ้านแล้วโดยอ่าน An Intro to R (cran. r-project. orgdocmanualsR-intro. pdf) หรือบทแนะนำบนเว็บอื่น ๆ ถ้าไม่โปรดดำเนินการก่อนที่จะโพสต์ที่นี่อีก Bert Gunter Genentech ข้อมูลชีวเคมีที่ไม่เป็นไปตามข้อกำหนด (650) 467-7374 quotData ไม่ใช่ข้อมูล ข้อมูลไม่ใช่ความรู้ และความรู้ไม่ใช่ภูมิปัญญาอย่างแท้จริงเอชกิลเบิร์ตเวลช์เมื่อวันจันทร์ที่ 17 ก. พ. 2557 เวลา 10:45 น. อีเมล C W lthidden gt wrote: gt Hi list, gt ฉันจะคำนวณค่าเฉลี่ยเคลื่อนที่โดยไม่ใช้ filter () ได้อย่างไร กรอง () ไม่ gt ดูเหมือนจะไม่ให้ค่าเฉลี่ยถ่วงน้ำหนัก gt gt ฉันกำลังมองหาในการสมัคร (), tapply แต่ไม่มีคำพูดใด ๆ เลย gt gt datlt-c (1:20) gt (dat1: 3) gt หมายถึง (dat4: 6) gt (dat7: 9) gt (dat10: 12) gt gt ฯลฯ gt gt ฉัน เข้าใจจุดของการสมัครคือการหลีกเลี่ยงการใช้ loops ฉันควรรวมแนวคิดนี้ในการใช้ gt () gt gt ขอบคุณ gt เมล gt gt รุ่น HTML อื่นที่ถูกลบออก gt gt gt ซ่อนรายชื่ออีเมล gt stat. ethz. chmailmanlistinfor-help โปรดอ่านคู่มือการโพสต์ R-project. orgposting-guide. html gt และแสดงรหัสที่สามารถอ่านซ้ําได้ ในการตอบโพสต์นี้โดย tmrsg11 เมื่อวันที่ 17 กุมภาพันธ์ 2014 เวลา 10:45 น. C W เขียน: gt Hi list, gt ฉันจะคำนวณค่าเฉลี่ยเคลื่อนที่โดยไม่ใช้ filter () ได้อย่างไร กรอง () ไม่ gt ดูเหมือนจะไม่ให้ค่าเฉลี่ยถ่วงน้ำหนัก gt gt ฉันกำลังมองหาในการสมัคร (), tapply แต่ไม่มีคำพูดใด ๆ เลย gt gt datlt-c (1:20) gt (dat1: 3) gt หมายถึง (dat4: 6) gt (dat7: 9) gt (dat10: 12) gt gt ฯลฯ gt gt ฉัน เข้าใจจุดของการใช้คือการหลีกเลี่ยงลูป, ฉันควรรวม gt ความคิดนี้ลงในการใช้ apply () gt สร้างเวกเตอร์สำหรับการจัดกลุ่มและใช้ tapply การแบ่ง Modulo เป็นวิธีการทั่วไปในการบรรลุเป้าหมายนี้ บางครั้งฟังก์ชั่น seq สามารถใช้งานได้ถ้าคุณปรับความยาวได้อย่างถูกต้อง gt tapply (dat, (0: ​​(length (dat) -1)) 3, mean) 0 1 2 3 4 5 6 2.0 5.0 8.0 11.0 14.0 17.0 19.5 tapply (ที่รอบ (seq (1, (ความยาว (วัน) 3), lenlength (dat))), mean) 1 2 3 4 5 6 7 1.5 4.5 8.0 11.0 14.5 18.0 20.0 ความคิดเห็นเกี่ยวกับ weighting dos ดูเหมือนจะไม่ได้ถูกยกตัวอย่างในตัวอย่างของคุณ gt ขอขอบคุณ gt gt gt gt รุ่น HTML อื่น ๆ ที่ถูกลบ gt gt gt ซ่อนรายชื่ออีเมลที่ส่งทางอีเมล gt stat. ethz. chmailmanlistinfor-help gt โปรดอ่านคู่มือการโพสต์ R-project. orgposting-guide. html gt และแสดงความคิดเห็นน้อยที่สุดด้วยตนเอง รหัสที่สามารถทำซ้ำได้ David Winsemius Alameda, CA, USA เปิดโพสต์ในมุมมองแบบเสียบส่วนได้รายงานเนื้อหาว่าไม่เหมาะสมเรื่องการคำนวณค่าเฉลี่ยเคลื่อนที่โดยไม่ใช้ filter () ในการตอบกระทู้นี้โดย Rui Barradas สำหรับค่าเฉลี่ยเคลื่อนที่ 5 จุด filter (x, side2, filterrep (1, 5) พวกเขามีผลเช่นเดียวกันเนื่องจากทั้งหมดจะต้องเป็น 1 Gabor amp Rui: ฉันตระหนักถึงสวนสัตว์แพคเกจฉันได้ ไม่ต้องการติดตั้งแพคเกจสำหรับฟังก์ชันหนึ่งเหตุผลเดียวกันสำหรับแพคเกจ sos เดวิดขอบคุณนั่นคือสิ่งที่ฉันกำลังมองหา On Mon, Feb 17, 2014 at 2:07 PM, Rui Barradas lthidden email gt wrote: gt Hello , gt gt หลายแพ็กเกจมีฟังก์ชันเฉลี่ยแบบ movind ตัวอย่างเช่นการคาดการณ์ของแพคเกจ gt หรือ gt gt library (sos) gt findFn (quotmoving averagequot) gt gt ในตัวอย่างของคุณค่าที่คำนวณไม่ตรงกับค่าเฉลี่ยเคลื่อนที่ แต่ใน gt สามารถ ให้คำนวณด้วยสิ่งต่อไปนี้ gt gt s lt - (seqalong (dat) - 1) 3 gt sapply (split (dat, s) mean) gt gt gt หวังว่าจะช่วยให้ gt gt Rui barra das gt gt gt em 17-02-2014 18:45, C W escreveu: gt gtgt Hi list, gtgt ฉันจะคำนวณค่าเฉลี่ยเคลื่อนที่โดยไม่ใช้ filter () ได้อย่างไร กรอง () ไม่ gtgt ดูเหมือนจะไม่ให้ค่าเฉลี่ยถ่วงน้ำหนัก gtgt gtgt ฉันกำลังมองหาในการใช้ (), tapply แต่ไม่มีคำพูดใด ๆ เลย gtgt gtgt mean (dat1: 3) gtgt mean (dat4: 6) gtgt mean (dat7: 9) gtgt mean (dat10: 12) gtgt gtgt ฯลฯ gtgt gtgt ฉัน เข้าใจจุดที่ใช้คือการหลีกเลี่ยงลูปวิธีที่ฉันควรจะรวม gtgt ความคิดนี้ไว้ในการใช้งาน () gtgt gtgt ขอบคุณ gtgt Mike gtgt gtgt รุ่น HTML อื่นที่ถูกลบ gtgt gtgt gtgt รายชื่ออีเมลที่ซ่อนอยู่ gtgt stat. ethz. chmailmanlistinfor - ช่วย gtgt โปรดอ่านคู่มือการโพสต์ R-project. org gtgt posting-guide. html gtgt และแสดงรหัสที่สามารถอ่านซ้ําได้ gtgt gtgt เลือก HTML version deletedUsing R for Time Series Analysis การวิเคราะห์อนุกรมเวลาชุดหนังสือเล่มนี้จะอธิบายวิธีการใช้ซอฟต์แวร์ทางสถิติ R เพื่อวิเคราะห์ข้อมูลที่เป็นประโยชน์ในการวิเคราะห์ข้อมูลชุดข้อมูลแบบเรียลไทม์ หนังสือเล่มนี้สันนิษฐานว่าผู้อ่านมีความรู้พื้นฐานเกี่ยวกับการวิเคราะห์อนุกรมเวลาและจุดสนใจหลักของหนังสือเล่มนี้ไม่ใช่เพื่ออธิบายถึงการวิเคราะห์อนุกรมเวลา แต่อธิบายถึงวิธีการวิเคราะห์เหล่านี้โดยใช้ R. ถ้าคุณยังใหม่กับซีรีส์เวลา การวิเคราะห์และต้องการเรียนรู้เพิ่มเติมเกี่ยวกับแนวคิดใด ๆ ที่นำเสนอในที่นี้ฉันขอแนะนำหนังสือ 8220Time series8221 ของ Open University (รหัสผลิตภัณฑ์ M24902) ที่มีจำหน่ายจาก Open University Shop ในหนังสือเล่มนี้ฉันจะใช้ชุดข้อมูลชุดข้อมูลตามเวลาที่ Rob Hyndman ได้รับในไลบรารีข้อมูล Time Series ของเขาที่ robjhyndmanTSDL หากคุณชอบหนังสือเล่มนี้คุณอาจต้องการดูหนังสือเล่มเล็ก ๆ เกี่ยวกับการใช้ R สำหรับสถิติทางการแพทย์, หนังสือเล่มเล็ก ๆ - จาก --for-bi-biomedical-statistics. readthedocs. org และหนังสือเล่มเล็ก ๆ ของฉันเกี่ยวกับการใช้ R สำหรับการวิเคราะห์แบบหลายตัวแปร, little-book-of-for-for-ultivariate-analysis. readthedocs. org การอ่านข้อมูลอนุกรมเวลาสิ่งแรกที่คุณจะต้องทำเพื่อวิเคราะห์ข้อมูลชุดเวลาของคุณคือการอ่านข้อมูลลงใน R และวางแผนชุดข้อมูลเวลา คุณสามารถอ่านข้อมูลลงใน R โดยใช้ฟังก์ชั่น scan () ซึ่งจะถือว่าข้อมูลของคุณอยู่ในแฟ้มข้อความแบบง่ายๆด้วยคอลัมน์เดียว ตัวอย่างเช่นไฟล์ robjhyndmantsdldatamisckings. dat มีข้อมูลเกี่ยวกับอายุการเสียชีวิตของกษัตริย์ต่อเนื่องของอังกฤษโดยเริ่มจาก William Conqueror (ต้นฉบับ: Hipel และ Mcleod, 1994) ชุดข้อมูลมีลักษณะดังนี้: เฉพาะบรรทัดแรกของไฟล์เท่านั้นที่แสดงขึ้น สามบรรทัดแรกมีความคิดเห็นเกี่ยวกับข้อมูลบางส่วนและเราต้องการละเว้นข้อมูลนี้เมื่อเราอ่านข้อมูลลงใน R. เราสามารถใช้พารามิเตอร์ 8220skip8221 ของฟังก์ชัน scan () ซึ่งระบุจำนวนบรรทัดที่ด้านบนของ ไฟล์ที่จะละเว้น หากต้องการอ่านไฟล์ใน R โดยไม่สนใจบรรทัดแรกสามบรรทัดเราจะพิมพ์: ในกรณีนี้อายุของราชาภิเษก 42 แห่งของอังกฤษถูกอ่านลงในตัวแปร 8216kings8217 เมื่อคุณอ่านข้อมูลชุดข้อมูลเวลาเป็น R แล้วขั้นตอนต่อไปคือการเก็บข้อมูลในชุดข้อมูลอนุกรมเวลาใน R เพื่อให้คุณสามารถใช้ R8217s หลายฟังก์ชันในการวิเคราะห์ข้อมูลชุดข้อมูลเวลา ในการจัดเก็บข้อมูลในวัตถุแบบอนุกรมเวลาเราใช้ฟังก์ชัน ts () ใน R. ตัวอย่างเช่นเพื่อเก็บข้อมูลในตัวแปร 8216kings8217 เป็นชุดข้อมูลอนุกรมเวลาใน R เราพิมพ์: บางครั้งชุดข้อมูลชุดเวลาที่คุณ อาจได้รับการเก็บรวบรวมเป็นระยะ ๆ ซึ่งน้อยกว่าหนึ่งปีเช่นรายเดือนหรือรายไตรมาส ในกรณีนี้คุณสามารถระบุจำนวนครั้งที่มีการรวบรวมข้อมูลต่อปีโดยใช้พารามิเตอร์ 8216frequency8217 ในฟังก์ชัน ts () สำหรับข้อมูลชุดข้อมูลรายเดือนคุณตั้งความถี่ 12 ในขณะที่ข้อมูลชุดข้อมูลรายไตรมาสจะกำหนดความถี่ 4 นอกจากนี้คุณสามารถระบุปีแรกที่มีการรวบรวมข้อมูลและช่วงแรกในปีนั้นโดยใช้พารามิเตอร์ 8216start8217 ในฟังก์ชัน ts () ตัวอย่างเช่นถ้าจุดข้อมูลแรกตรงกับไตรมาสที่สองของปี 1986 คุณจะตั้งค่าเริ่มต้น (1986,2) ตัวอย่างคือชุดข้อมูลจำนวนการเกิดต่อเดือนในนิวยอร์กซิตี้ตั้งแต่เดือนมกราคม พ. ศ. 2489 ถึงธันวาคม พ. ศ. 2502 (ซึ่งเดิมเก็บรวบรวมโดยนิวตัน) ข้อมูลนี้มีอยู่ในไฟล์ robjhyndmantsdldatadatanybirths. dat เราสามารถอ่านข้อมูลใน R และจัดเก็บข้อมูลเป็นชุดข้อมูลอนุกรมเวลาได้โดยการพิมพ์: ในทำนองเดียวกันไฟล์ robjhyndmantsdldatadatafancy. dat มียอดขายรายเดือนสำหรับร้านขายของที่ระลึกในเมืองริมหาดใน Queensland, Australia สำหรับมกราคม 1987 - ธันวาคม 1993 (ข้อมูลต้นฉบับจาก Wheelwright และ Hyndman, 1998) เราสามารถอ่านข้อมูลใน R ได้โดยการพิมพ์: Plotting Time Series เมื่อคุณอ่านชุดข้อมูลเวลาเป็น R แล้วขั้นตอนต่อไปคือการทำพล็อตข้อมูลชุดข้อมูลเวลาซึ่งคุณสามารถทำอะไรได้ด้วย plot. ts () ใน R. ตัวอย่างเช่นเพื่อพล็อตชุดเวลาของอายุของการตายของ 42 พระมหากษัตริย์ต่อเนื่องของอังกฤษเราพิมพ์: เราสามารถดูได้จากพล็อตครั้งที่ชุดเวลานี้อาจจะมีการอธิบายโดยใช้แบบจำลอง additive ตั้งแต่ความผันผวนแบบสุ่ม ในข้อมูลมีค่าคงที่โดยประมาณเมื่อเทียบกับช่วงเวลา ในทำนองเดียวกันในการวางแผนจำนวนเวลาที่เกิดจำนวนต่อเดือนในเมืองนิวยอร์กเราจะพิมพ์: เราเห็นได้จากชุดข้อมูลในช่วงเวลานี้ว่าอาจมีการเปลี่ยนแปลงตามฤดูกาลในจำนวนการเกิดต่อเดือน: มีจุดสูงสุดในทุกฤดูร้อน และรางน้ำทุกฤดูหนาว อีกครั้งดูเหมือนว่าชุดข้อมูลในครั้งนี้น่าจะได้รับการอธิบายโดยใช้แบบจำลอง additive เนื่องจากความผันผวนตามฤดูกาลมีค่าคงที่โดยประมาณในระยะเวลาและดูเหมือนจะไม่ขึ้นอยู่กับระดับของชุดข้อมูลเวลาและความผันผวนแบบสุ่มก็ดูเหมือนจะเป็น มีขนาดคงที่ตลอดเวลา ในทำนองเดียวกันในการจัดทำยอดขายรายเดือนสำหรับร้านขายของที่ระลึกในเมืองชายหาดในรัฐควีนส์แลนด์ประเทศออสเตรเลียเราพิมพ์: ในกรณีนี้ปรากฏว่าโมเดล additive ไม่เหมาะสำหรับการอธิบายชุดเวลานี้เนื่องจากขนาด ของความผันผวนตามฤดูกาลและความผันผวนแบบสุ่มดูเหมือนจะเพิ่มขึ้นตามระดับของชุดข้อมูล ดังนั้นเราอาจต้องเปลี่ยนชุดเวลาเพื่อให้ได้ชุดเวลาที่เปลี่ยนไปซึ่งสามารถอธิบายได้โดยใช้แบบจำลอง additive ตัวอย่างเช่นเราสามารถแปลงชุดข้อมูลเวลาโดยการคำนวณ log ธรรมชาติของข้อมูลเดิม: ที่นี่เราจะเห็นว่าขนาดของความผันผวนตามฤดูกาลและความผันผวนแบบสุ่มในชุดข้อมูลที่เปลี่ยนเป็นข้อมูลบันทึกมีแนวโน้มที่จะคงที่ตลอดเวลาและทำ ไม่ขึ้นอยู่กับระดับของชุดข้อมูลเวลา ดังนั้นซีรีส์เวลาที่เปลี่ยนเป็นข้อมูลเข้าสู่ระบบสามารถอธิบายได้โดยใช้แบบจำลอง additive การสลายตัวของซีรีส์เวลาการสลายชุดข้อมูลเวลาจะหมายถึงการแยกองค์ประกอบออกเป็นส่วนประกอบซึ่งมักเป็นส่วนประกอบของแนวโน้มและส่วนประกอบที่ผิดปกติและถ้าเป็นชุดฤดูกาลตามฤดูกาลองค์ประกอบตามฤดูกาล การย่อยสลายข้อมูลที่ไม่ใช่ฤดูกาลข้อมูลชุดเวลานอกเวลาตามฤดูกาลประกอบด้วยองค์ประกอบแนวโน้มและองค์ประกอบที่ไม่ต่อเนื่อง การสลายชุดข้อมูลเวลาเกี่ยวข้องกับการพยายามแยกชุดข้อมูลเวลาออกเป็นองค์ประกอบเหล่านี้นั่นคือการประมาณส่วนประกอบเทรนด์และองค์ประกอบที่ไม่สม่ำเสมอ ในการประมาณองค์ประกอบเทรนด์ของซีรีส์เวลาที่ไม่ใช่ฤดูกาลซึ่งสามารถอธิบายได้โดยใช้โมเดล additive เป็นเรื่องปกติที่จะใช้วิธีการปรับให้ราบเรียบเช่นการคำนวณค่าเฉลี่ยเคลื่อนที่แบบเรียบง่ายของชุดข้อมูลเวลา ฟังก์ชัน SMA () ในแพคเกจ 8220TTR8221 R สามารถใช้เพื่อให้ข้อมูลชุดข้อมูลเป็นไปอย่างราบรื่นโดยใช้ค่าเฉลี่ยเคลื่อนที่แบบเรียบ ในการใช้ฟังก์ชันนี้เราต้องติดตั้งแพ็คเกจ 8220TTR8221 R (สำหรับคำแนะนำในการติดตั้งแพคเกจ R โปรดดูที่การติดตั้งแพคเกจ R) เมื่อติดตั้งแพ็คเกจ 8220TTR8221 R แล้วคุณสามารถโหลดแพคเกจ 8220TTR8221 R ได้โดยการพิมพ์: จากนั้นคุณสามารถใช้ฟังก์ชัน 8220SMA () 8221 เพื่อให้ข้อมูลชุดข้อมูลเป็นไปอย่างราบรื่น ในการใช้ฟังก์ชัน SMA () คุณต้องระบุลำดับ (ช่วง) ของค่าเฉลี่ยเคลื่อนที่โดยใช้พารามิเตอร์ 8220n8221 ตัวอย่างเช่นในการคำนวณค่าเฉลี่ยเคลื่อนที่แบบง่ายของลำดับที่ 5 เรากำหนด n5 ในฟังก์ชัน SMA () ยกตัวอย่างเช่นตามที่ได้กล่าวไว้ข้างต้นชุดเวลาของอายุของราชาภิเษกที่ 42 ของอังกฤษปรากฏไม่ใช่ฤดูกาลและสามารถอธิบายได้โดยใช้แบบจำลอง additive เนื่องจากความผันผวนของข้อมูลที่สุ่มมีขนาดคงที่โดยประมาณ เวลา: ดังนั้นเราสามารถลองคำนวณคอมโพเนนต์แนวโน้มของซีรีส์เวลานี้ได้โดยการให้เรียบโดยใช้ค่าเฉลี่ยเคลื่อนที่ที่เรียบง่าย เพื่อเรียบชุดเวลาโดยใช้ค่าเฉลี่ยเคลื่อนที่ที่เรียบง่ายของคำสั่งที่ 3 และพล็อตข้อมูลชุดข้อมูลที่ราบรื่นเราพิมพ์: ยังคงดูเหมือนจะเป็นจำนวนมากของความผันผวนแบบสุ่มในชุดเวลาที่เรียบโดยใช้ค่าเฉลี่ยเคลื่อนที่ที่เรียบง่ายของคำสั่งที่ 3 ดังนั้นเพื่อประมาณการคอมโพเนนต์แนวโน้มอย่างแม่นยำมากขึ้นเราอาจต้องการลองทำให้ข้อมูลเรียบโดยมีค่าเฉลี่ยเคลื่อนที่ที่เรียบง่ายของคำสั่งซื้อที่สูงขึ้น ใช้เวลาในการทดลองและข้อผิดพลาดเล็กน้อยเพื่อค้นหาจำนวนที่เหมาะสมของการทำให้เรียบ ตัวอย่างเช่นเราสามารถลองใช้ค่าเฉลี่ยเคลื่อนที่แบบง่ายของคำสั่งที่ 8: ข้อมูลที่เรียบโดยมีค่าเฉลี่ยเคลื่อนที่ที่เรียบง่ายของคำสั่งที่ 8 จะให้ภาพที่ชัดเจนขึ้นขององค์ประกอบแนวโน้มและเราจะเห็นได้ว่าอายุการตายของกษัตริย์อังกฤษดูเหมือนจะเป็นอย่างไร ได้ลดลงจากประมาณ 55 ปีไปประมาณ 38 ปีในรัชสมัยของ 20 กษัตริย์แรกและจากนั้นเพิ่มขึ้นหลังจากที่ไปประมาณ 73 ปีโดยสิ้นรัชกาลของพระเจ้า 40 ในชุดเวลา การแจกแจงข้อมูลตามฤดูกาลซีรีส์เวลาตามฤดูกาลประกอบด้วยองค์ประกอบแนวโน้มองค์ประกอบตามฤดูกาลและองค์ประกอบที่ไม่สม่ำเสมอ การแยกชุดข้อมูลเวลาหมายถึงการแบ่งช่วงเวลาออกเป็นองค์ประกอบสามส่วนนี้นั่นคือการประมาณค่าส่วนประกอบทั้งสามนี้ ในการประมาณองค์ประกอบเทรนด์และองค์ประกอบตามฤดูกาลของซีรีส์เวลาตามฤดูกาลที่สามารถอธิบายได้โดยใช้โมเดล additive เราสามารถใช้ฟังก์ชัน 8220decompose () 8221 ในอาร์ได้ฟังก์ชันนี้จะประมาณการส่วนประกอบตามฤดูกาลและไม่สม่ำเสมอของชุดข้อมูลเวลาที่ สามารถอธิบายได้โดยใช้แบบจำลอง additive 8220decompose () 8221 ส่งกลับค่าอ็อบเจ็กต์ list เป็นผลลัพธ์ซึ่งการประมาณส่วนประกอบตามฤดูกาลคอมโพเนนต์แนวโน้มและองค์ประกอบที่ผิดปกติจะถูกเก็บไว้ในองค์ประกอบที่มีชื่อของอ็อบเจ็กต์ list ที่เรียกว่า 8220seasonal8221, 8220trend8221 และ 8220random8221 ตามลำดับ ตัวอย่างเช่นตามที่กล่าวไว้ข้างต้นชุดข้อมูลจำนวนเวลาเกิดขึ้นต่อเดือนในนิวยอร์กซิตี้เป็นฤดูกาลที่มียอดทุกฤดูร้อนและร่องน้ำทุกฤดูหนาวและสามารถอธิบายได้โดยใช้แบบจำลอง additive เนื่องจากความผันผวนตามฤดูกาลและแบบสุ่มดูเหมือนจะเป็นไปได้ เป็นค่าคงที่โดยประมาณเมื่อเทียบกับช่วงเวลา: ในการประมาณแนวโน้มส่วนประกอบตามฤดูกาลและไม่สม่ำเสมอของชุดข้อมูลในเวลานี้เราจะพิมพ์: ค่าประมาณขององค์ประกอบตามฤดูกาลแนวโน้มและไม่สม่ำเสมอจะถูกเก็บไว้ในตัวแปรที่เกิดขึ้นในช่วงเวลาที่เกิดขึ้นทั้งแบบทั่วไปการเกิดและช่วงเวลาที่เกิดขึ้น ตัวอย่างเช่นเราสามารถพิมพ์ค่าประมาณขององค์ประกอบตามฤดูกาลได้โดยพิมพ์: ปัจจัยฤดูกาลที่คาดการณ์ไว้จะมีขึ้นในช่วงเดือนมกราคม - ธันวาคมและจะเหมือนกันในแต่ละปี ปัจจัยฤดูกาลที่ใหญ่ที่สุดคือเดือนกรกฎาคม (ประมาณ 1.46) และต่ำสุดคือเดือนกุมภาพันธ์ (ประมาณ -2.08) ซึ่งบ่งชี้ว่าดูเหมือนว่าจะมียอดการคลอดสูงสุดในเดือนกรกฎาคมและมีการคลอดในเดือนกุมภาพันธ์ในแต่ละปี เราสามารถจัดทำประมาณการแนวโน้มส่วนประกอบตามฤดูกาลและไม่สม่ำเสมอของชุดข้อมูลเวลาได้โดยใช้ฟังก์ชัน 8220plot () 8221 ตัวอย่างเช่นพล็อตด้านบนแสดงชุดข้อมูลเวลาต้นฉบับ (ด้านบน) องค์ประกอบเทรนด์โดยประมาณ (ที่สองจากด้านบนสุด) องค์ประกอบที่เป็นฤดูกาลตามฤดูกาล (ที่สามจากด้านบน) และองค์ประกอบที่ไม่สม่ำเสมอโดยประมาณ (ด้านล่าง) เราเห็นว่าส่วนประกอบของแนวโน้มที่คาดการณ์ลดลงเล็กน้อยจากประมาณ 24 ในปี 1947 เป็นประมาณ 22 ในปี 1948 ตามมาด้วยการเพิ่มขึ้นอย่างสม่ำเสมอจากนั้นเป็นประมาณ 27 ในปี 1959 การปรับฤดูกาลถ้าคุณมีชุดเวลาตามฤดูกาลที่สามารถอธิบายได้โดยใช้ แบบจำลองเพิ่มเติมคุณสามารถปรับชุดข้อมูลเวลาตามฤดูกาลโดยการประมาณองค์ประกอบตามฤดูกาลและลบองค์ประกอบตามฤดูกาลโดยประมาณออกจากชุดเวลาเดิม เราสามารถทำได้โดยใช้ค่าประมาณขององค์ประกอบตามฤดูกาลที่คำนวณโดยฟังก์ชัน 8221decompose () 8221 ตัวอย่างเช่นหากต้องการปรับฤดูกาลตามจำนวนเดือนเกิดในเมือง New York ตามฤดูกาลเราสามารถคาดการณ์องค์ประกอบตามฤดูกาลโดยใช้ 8220decompose () 8221 จากนั้นลบส่วนประกอบตามฤดูกาลออกจากชุดเวลาเดิม: จากนั้นเราจะสามารถคำนวณ ชุดเวลาที่ปรับฤดูกาลตามฤดูกาลโดยใช้ 8220plot () 8221 ฟังก์ชันโดยพิมพ์: คุณจะเห็นว่ารูปแบบตามฤดูกาลถูกลบออกจากชุดเวลาที่ปรับฤดูกาลแล้ว ซีรีส์เวลาที่ปรับฤดูกาลตามฤดูกาลนี้มีองค์ประกอบเทรนด์และองค์ประกอบที่ไม่สม่ำเสมอ การคาดการณ์โดยใช้ Exponential Smoothing Exponential smoothing สามารถใช้เพื่อคาดการณ์ระยะสั้นสำหรับข้อมูลชุดเวลาได้ การเรียบอย่างง่าย Exponential ถ้าคุณมีชุดข้อมูลเวลาที่สามารถอธิบายได้โดยใช้โมเดล additive ที่มีระดับคงที่และไม่มี seasonality คุณสามารถใช้การคำนวณแบบเรียบง่ายเพื่อคาดการณ์ในระยะสั้นได้ วิธีการเรียบง่ายชี้แจงให้เป็นวิธีการประมาณระดับที่จุดเวลาปัจจุบัน Smoothing ถูกควบคุมโดยอัลฟ่าพารามิเตอร์สำหรับการประมาณระดับ ณ จุดเวลาปัจจุบัน ค่าอัลฟาอยู่ระหว่าง 0 ถึง 1. ค่าของอัลฟาที่ใกล้เคียงกับ 0 หมายถึงน้ำหนักตัวน้อยที่วางอยู่บนข้อสังเกตล่าสุดเมื่อทำการคาดการณ์ค่าในอนาคต ตัวอย่างเช่นไฟล์ robjhyndmantsdldatahurstprecip1.dat มีปริมาณฝนตกทุกปีเป็นนิ้วสำหรับลอนดอนตั้งแต่ปีพ. ศ. 2356 - 2455 (ข้อมูลเดิมจาก Hipel และ McLeod, 1994) เราสามารถอ่านข้อมูลลงใน R และพล็อตได้โดยการพิมพ์: คุณสามารถเห็นได้จากพล็อตที่มีระดับคงที่โดยประมาณ (ค่าคงที่อยู่ที่ประมาณ 25 นิ้ว) ความผันผวนของข้อมูลสุ่มในชุดเวลาดูเหมือนจะมีค่าคงที่โดยประมาณในระยะเวลาหนึ่งดังนั้นจึงอาจเหมาะสมที่จะอธิบายข้อมูลโดยใช้แบบจำลอง additive ดังนั้นเราจึงสามารถคาดการณ์โดยใช้การเรียบอย่างง่ายแทน เพื่อให้การคาดการณ์โดยใช้การเรียบอย่างง่ายใน R เราสามารถใส่คำอธิบายแบบเรียบง่ายที่ทำนายได้ด้วยการใช้ฟังก์ชัน 8220HoltWinters () 8221 ใน R. การใช้ HoltWinters () เพื่อให้เรียบง่ายขึ้นเราจำเป็นต้องตั้งค่าพารามิเตอร์ betaFALSE และ gammaFALSE ไว้ใน ฟังก์ชั่น HoltWinters () (พารามิเตอร์เบต้าและแกมมาใช้สำหรับการปรับให้เรียบแบบ Holt8217s หรือการเรียบเรียงชี้แจงตาม Holt-Winters ตามที่อธิบายไว้ด้านล่าง) ฟังก์ชัน HoltWinters () จะคืนค่าตัวแปรรายชื่อที่มีองค์ประกอบหลายชื่อ ตัวอย่างเช่นในการใช้การเรียบง่ายแบบเสวนาเพื่อคาดการณ์ปริมาณฝนที่ตกเป็นประจำทุกปีในลอนดอนเราจะพิมพ์: ผลลัพธ์ของ HoltWinters () บอกเราว่าค่าประมาณของพารามิเตอร์ alpha อยู่ที่ประมาณ 0.024 ซึ่งใกล้เคียงกับศูนย์บอกให้เราทราบว่าการคาดการณ์ขึ้นอยู่กับการสังเกตล่าสุดและการสังเกตการณ์ล่าสุดที่ไม่ค่อยได้รับการตอบรับ (แม้ว่าจะมีการสังเกตน้ำหนักที่ค่อนข้างมากก็ตาม) โดยค่าเริ่มต้น HoltWinters () จะทำให้การคาดการณ์ในช่วงเวลาเดียวกันที่ครอบคลุมตามชุดเวลาเดิมของเรา ในกรณีนี้ชุดเวลาเดิมของเรารวมถึงปริมาณน้ำฝนสำหรับลอนดอนจาก 1813-1912 ดังนั้นการคาดการณ์จึงเป็นเช่นนั้นสำหรับ 1813-1912 ในตัวอย่างข้างต้นเราได้เก็บผลลัพธ์ของฟังก์ชัน HoltWinters () ไว้ในตัวแปรรายการ 8220rainseriesforecasts8221 การคาดการณ์ที่ทำโดย HoltWinters () จะถูกเก็บไว้ในองค์ประกอบที่มีชื่อของตัวแปรรายการนี้ชื่อ 8220fitted8221 เพื่อให้เราสามารถรับค่าได้โดยการพิมพ์: เราสามารถพล็อตชุดเวลาต้นฉบับกับการคาดการณ์ได้โดยการพิมพ์: พล็อตแสดงชุดเวลาต้นฉบับใน ดำและการคาดการณ์เป็นเส้นสีแดง ชุดข้อมูลการคาดการณ์ในช่วงเวลานี้ดูเรียบง่ายกว่าชุดข้อมูลเดิมของข้อมูลที่นี่ เพื่อวัดความถูกต้องของการคาดการณ์เราสามารถคำนวณผลรวมของข้อผิดพลาดในการคำนวณสำหรับข้อผิดพลาดในการคาดการณ์ในตัวอย่างนั่นคือข้อผิดพลาดในการคาดการณ์สำหรับช่วงเวลาที่ครอบคลุมตามชุดเวลาเดิมของเรา ข้อผิดพลาดของ sum-of-squared ถูกเก็บไว้ใน element ชื่อของตัวแปร list 8220rainseriesforecasts8221 ที่เรียกว่า 8220SSE8221 เพื่อให้เราสามารถรับค่าได้โดยการพิมพ์: นั่นคือข้อผิดพลาดของ sum-of-squared คือ 1828.855 เป็นเรื่องธรรมดาในการเรียบง่ายชี้แจงให้ใช้ค่าแรกในซีรีส์เวลาเป็นค่าเริ่มต้นสำหรับระดับ ตัวอย่างเช่นในชุดข้อมูลเวลาฝนตกในลอนดอนค่าแรกเป็น 23.56 นิ้วสำหรับปริมาณน้ำฝนในปี 1813 คุณสามารถระบุค่าเริ่มต้นสำหรับระดับในฟังก์ชัน HoltWinters () โดยใช้พารามิเตอร์ 8220l. start8221 ตัวอย่างเช่นเพื่อให้การคาดการณ์ที่มีค่าเริ่มต้นของระดับที่ตั้งไว้ที่ 23.56 เราพิมพ์: ตามที่อธิบายไว้ข้างต้นโดยค่าเริ่มต้น HoltWinters () จะทำให้การคาดการณ์สำหรับช่วงเวลาที่ครอบคลุมโดยข้อมูลเดิมซึ่งเป็น 1813-1912 สำหรับปริมาณน้ำฝน time series เราสามารถคาดการณ์จุดเวลาต่อไปได้โดยใช้ 8220forecast. HoltWinters () 8221 ฟังก์ชันในแพคเกจ R 8220forecast8221 ในการใช้ฟังก์ชัน forecast. HoltWinters () ก่อนอื่นเราต้องติดตั้งแพ็กเกจ 8220forecast8221 R (สำหรับคำแนะนำในการติดตั้งแพคเกจ R โปรดดูที่การติดตั้งแพคเกจ R) เมื่อติดตั้งแพคเกจ 8220forecast8221 R แล้วคุณสามารถโหลดแพคเกจ 8220forecast8221 R ได้โดยการพิมพ์: เมื่อใช้ฟังก์ชัน forecast. HoltWinters () เป็นอาร์กิวเมนต์แรก (อินพุท) คุณจะส่งผ่านโมเดลการคาดการณ์ที่คุณได้ติดตั้งไว้แล้วโดยใช้ ฟังก์ชัน HoltWinters () ตัวอย่างเช่นในกรณีของชุดเวลาฝนตกเราได้เก็บโมเดลการคาดการณ์ที่ทำโดยใช้ HoltWinters () ในตัวแปร 8220rainseriesforecasts8221 คุณระบุจำนวนจุดเวลาที่คุณต้องการคาดการณ์โดยใช้พารามิเตอร์ 8220h8221 ใน forecast. HoltWinters () ตัวอย่างเช่นเพื่อให้การคาดการณ์ของปริมาณน้ำฝนสำหรับปี 1814-1820 (8 ปีเพิ่มเติม) โดยใช้ forecast. HoltWinters () เราพิมพ์: ฟังก์ชัน forecast. HoltWinters () จะช่วยให้คุณคาดการณ์ปีเป็น 80 ช่วงการคาดการณ์สำหรับ การคาดการณ์และช่วงคาดการณ์ 95 สำหรับการคาดการณ์ ตัวอย่างเช่นปริมาณน้ำฝนที่คาดการณ์ไว้สำหรับปีพ. ศ. 2463 ประมาณ 24.68 นิ้วโดยมีช่วงคาดการณ์ 95 (16.24, 33.11) เราสามารถใช้ 8220plot. forecast () 8221 ฟังก์ชัน: ที่นี่คาดการณ์สำหรับ 1913-1920 ถูกวางแผนเป็นเส้นสีน้ำเงิน 80 ช่วงทำนายเป็นพื้นที่สีส้มสีส้มและ 95 เป็นพื้นที่สีเหลืองที่แรเงา ข้อผิดพลาด 8216forecast ถูกคำนวณเป็นค่าที่สังเกตได้หักค่าที่คาดการณ์ไว้สำหรับแต่ละช่วงเวลา เราสามารถคำนวณข้อผิดพลาดในการคาดการณ์สำหรับช่วงเวลาที่ครอบคลุมตามชุดข้อมูลเดิมของเราซึ่งเป็นข้อมูลปริมาณน้ำฝนในช่วงเวลา 1813-1912 เท่านั้น ดังที่ได้กล่าวมาข้างต้นหนึ่งในการวัดความถูกต้องของรูปแบบการคาดการณ์คือข้อผิดพลาดของ sum-of-squared-errors (SSE) สำหรับข้อผิดพลาดในการคาดการณ์ในตัวอย่าง ข้อผิดพลาดในการคาดการณ์ในตัวอย่างจะถูกเก็บไว้ในองค์ประกอบ 8220 ที่ระบุว่า 82221 ของตัวแปรรายการที่ส่งคืนโดย forecast. HoltWinters () หากไม่สามารถปรับปรุงรูปแบบการคาดการณ์ได้ควรไม่มีความสัมพันธ์ระหว่างข้อผิดพลาดในการคาดการณ์สำหรับการคาดการณ์ต่อเนื่อง กล่าวอีกนัยหนึ่งถ้ามีความสัมพันธ์ระหว่างข้อผิดพลาดในการคาดการณ์สำหรับการคาดการณ์ต่อเนื่องอาจเป็นไปได้ว่าการคาดการณ์การทำให้เรียบแบบเรียบง่ายอาจได้รับการปรับปรุงโดยเทคนิคการพยากรณ์อื่น หากต้องการทราบว่าเป็นกรณีนี้หรือไม่เราสามารถขอรับความผิดพลาดในการคาดการณ์ตัวอย่างในกรณีที่ล่าช้า 1-20 เราสามารถคำนวณ correlogram ของข้อผิดพลาดในการคาดการณ์โดยใช้ฟังก์ชัน 8221a () 8221 ใน R. เพื่อระบุความล่าช้าสูงสุดที่เราต้องการดูเราใช้พารามิเตอร์ 8220lag. max8221 ใน acf () ตัวอย่างเช่นในการคำนวณ correlogram ของข้อผิดพลาดในการคาดการณ์ในตัวอย่างสำหรับข้อมูลปริมาณน้ำฝนในลอนดอนสำหรับความล่าช้า 1-20 เราจะพิมพ์: คุณสามารถดูได้จากตัวอย่าง correlogram ที่ความสัมพันธ์กันที่ระดับ lag 3 เป็นเพียงการสัมผัสความสำคัญเท่านั้น เพื่อทดสอบว่ามีหลักฐานสำคัญสำหรับ correlations ที่ไม่เป็นศูนย์ที่ lags 1-20 เราสามารถดำเนินการทดสอบ Ljung-Box ซึ่งสามารถทำได้ใน R โดยใช้ 8220Box. test () 8221 ฟังก์ชัน ความล่าช้าสูงสุดที่เราต้องการดูมีการระบุโดยใช้พารามิเตอร์ 8220lag8221 ในฟังก์ชัน Box. test () ตัวอย่างเช่นเมื่อต้องการทดสอบว่ามีการเชื่อมโยงกันที่ไม่ใช่ศูนย์ที่ล่าช้า 1-20 สำหรับข้อผิดพลาดในการคาดการณ์ตัวอย่างสำหรับข้อมูลปริมาณน้ำฝนในลอนดอนเราจะพิมพ์ที่นี่สถิติทดสอบ Ljung-Box เท่ากับ 17.4 และค่า p คือ 0.6 ดังนั้นมีหลักฐานน้อยมากเกี่ยวกับความสัมพันธ์กันที่ไม่ใช่ศูนย์ในข้อผิดพลาดในการคาดการณ์ในตัวอย่างที่ล่าช้า 1-20 เพื่อให้มั่นใจได้ว่าโมเดลการคาดการณ์ไม่สามารถปรับปรุงได้ดีกว่าควรเป็นเช่นนี้เพื่อตรวจสอบว่าข้อผิดพลาดในการคาดการณ์มีการแจกแจงแบบปกติหรือไม่และค่าความแปรปรวนคงที่ เพื่อตรวจสอบว่าข้อผิดพลาดในการคาดการณ์มีความแปรปรวนคงที่เราสามารถทำพล็อตเวลาของข้อผิดพลาดในการคาดการณ์ในตัวอย่าง: พล็อตแสดงให้เห็นว่าข้อผิดพลาดในการคาดการณ์ในตัวอย่างดูเหมือนจะมีความแปรปรวนคงที่ประมาณตลอดเวลาแม้ว่าจะมีขนาดของความผันผวนใน เริ่มต้นของชุดเวลา (1820-1830) อาจจะน้อยกว่าเล็กน้อยในภายหลัง (เช่น 1840-1850) เพื่อตรวจสอบว่าข้อผิดพลาดในการคาดการณ์มีการแจกจ่ายโดยปกติหรือไม่ศูนย์เราสามารถจัดทำฮิสโตแกรมของข้อผิดพลาดในการคาดการณ์ได้โดยมีเส้นกราฟปกติที่ซ้อนทับที่มีค่าเฉลี่ยศูนย์และส่วนเบี่ยงเบนมาตรฐานเดียวกันกับการแจกแจงข้อผิดพลาดในการคาดการณ์ ในการทำเช่นนี้เราสามารถกำหนดฟังก์ชัน R 8220plotForecastErrors () 8221 ด้านล่าง: คุณจะต้องคัดลอกฟังก์ชันข้างต้นลงใน R เพื่อใช้งาน จากนั้นคุณสามารถใช้ plotForecastErrors () เพื่อทำกราฟฮิสโตแกรม (มีการทับระดับเส้นโค้งปกติ) ของข้อผิดพลาดในการคาดการณ์สำหรับการคาดการณ์ปริมาณน้ำฝน: พล็อตแสดงว่าการแจกแจงข้อผิดพลาดในการคาดการณ์นั้นอยู่ตรงกลางเป็นศูนย์และมีการกระจายตามปกติมากกว่าหรือน้อยกว่า ดูเหมือนว่าจะเบี่ยงเบนไปทางขวาเล็กน้อยเมื่อเทียบกับเส้นโค้งปกติ อย่างไรก็ตามความลาดเอียงขวาค่อนข้างเล็กและดังนั้นจึงเป็นไปได้ที่ข้อผิดพลาดในการคาดการณ์จะมีการกระจายตามปกติโดยมีค่าเฉลี่ยศูนย์ การทดสอบ Ljung-Box แสดงให้เห็นว่ามีหลักฐานน้อยมากเกี่ยวกับการเชื่อมโยงกันที่ไม่ใช่ศูนย์ในข้อผิดพลาดในการคาดการณ์ในตัวอย่างและการกระจายข้อผิดพลาดในการคาดการณ์ดูเหมือนว่าจะมีการกระจายตามปกติโดยมีค่าเฉลี่ยศูนย์ นี่แสดงให้เห็นว่าวิธีการเรียบง่ายชี้แจงให้รูปแบบการคาดการณ์ที่เพียงพอสำหรับปริมาณน้ำฝนในลอนดอนซึ่งอาจจะไม่สามารถปรับปรุงให้ดีขึ้นได้ นอกจากนี้สมมติฐานที่ว่าช่วงการคาดการณ์ 80 และ 95 ขึ้นอยู่กับ (ที่ไม่มีการเทียบอัตโนมัติในข้อผิดพลาดในการคาดการณ์และข้อผิดพลาดในการคาดการณ์จะมีการกระจายตามปกติโดยมีค่าเฉลี่ยศูนย์และค่าความแปรปรวนคงที่) อาจถูกต้อง ถ้าคุณมีชุดข้อมูลเวลาที่สามารถอธิบายได้โดยใช้แบบจำลอง additive ที่มีแนวโน้มเพิ่มขึ้นหรือลดลงและไม่มีฤดูกาลคุณสามารถใช้การคำนวณหากำไรแบบละเอียดเพื่อให้ได้การคาดการณ์ในระยะสั้น Holt8217s การคำนวณความล้าสมัยของ Holt8217s จะประมาณระดับและความลาดชัน ณ จุดเวลาปัจจุบัน Smoothing ถูกควบคุมโดยพารามิเตอร์สองค่าอัลฟ่าสำหรับการประมาณระดับ ณ จุดเวลาปัจจุบันและเบต้าสำหรับการประมาณความชันของส่วนประกอบแนวโน้มที่จุดเวลาปัจจุบัน เช่นเดียวกับการเรียบง่ายชี้แจงอัลฟ่าและเบต้า paramters มีค่าระหว่าง 0 ถึง 1 และค่าที่ใกล้เคียงกับ 0 หมายความว่าน้ำหนักเพียงเล็กน้อยจะถูกวางไว้กับข้อสังเกตล่าสุดเมื่อทำการคาดการณ์ค่าในอนาคต ตัวอย่างชุดเวลาที่สามารถอธิบายได้โดยใช้แบบจำลองเพิ่มเติมที่มีแนวโน้มและไม่มีฤดูกาลเป็นชุดข้อมูลขนาดเส้นผ่านศูนย์กลางของผู้หญิงในช่วงปีพ. ศ. 2409 ถึง พ. ศ. 2454 มีข้อมูลอยู่ในไฟล์ robjhyndmantsdldatarobertsskirts dat (ข้อมูลต้นฉบับจาก Hipel และ McLeod, 1994) เราสามารถอ่านและวางแผนข้อมูลใน R โดยการพิมพ์: เราสามารถดูได้จากพล็อตว่ามีเส้นผ่านศูนย์กลางของเส้นด้ายเพิ่มขึ้นจากประมาณ 600 ใน 1866 ถึงประมาณ 1050 ในปี 1880 และหลังจากนั้นเส้นผ่านศูนย์กลางของห้อยลดลงประมาณ 520 ในปี 1911 เราจะต้องตั้งค่าพารามิเตอร์ gammaFALSE (พารามิเตอร์ gamma ใช้สำหรับการให้ความนุ่มนวลแบบเอ็กซอนเนลล์ - ฤดูหนาวของโฮลท์ - วินเทอร์ (Windmill Winters)) ซึ่งเป็นวิธีการที่ใช้ในการคาดการณ์ของ HoltWinters () ตามที่อธิบายไว้ด้านล่าง) ตัวอย่างเช่นในการใช้การอธิบายแบบย่อหน้า Holt8217s ให้พอดีกับรูปแบบการคาดการณ์สำหรับเส้นผ่าศูนย์กลางของกระโปรงเส้นผ่าศูนย์กลางเราพิมพ์: ค่าประมาณของ alpha เท่ากับ 0.84 และ beta คือ 1.00 ค่าเหล่านี้สูงทั้งสองบอกเราว่าการประมาณค่าปัจจุบันของระดับและความชันขององค์ประกอบแนวโน้มจะขึ้นอยู่กับข้อสังเกตล่าสุดในชุดข้อมูลเวลา นี้ทำให้รู้สึกดีใช้งานง่ายเนื่องจากระดับและความลาดเอียงของชุดเวลาทั้งสองเปลี่ยนแปลงได้ค่อนข้างมากเมื่อเวลาผ่านไป ค่าของข้อผิดพลาดในการประมาณค่าของข้อผิดพลาดในการประมาณตัวอย่างคือ 16954 เราสามารถคำนวณชุดข้อมูลเวลาต้นฉบับเป็นเส้นสีดำโดยมีค่าคาดการณ์เป็นเส้นสีแดงอยู่ด้านบนโดยพิมพ์: เรา สามารถมองเห็นได้จากภาพที่คาดการณ์ในตัวอย่างดีกว่าค่าที่สังเกตได้แม้ว่าจะมีแนวโน้มที่จะล้าหลังค่าที่สังเกตได้นิดหน่อย ถ้าคุณต้องการคุณสามารถระบุค่าเริ่มต้นของระดับและความลาดชัน b ของคอมโพเนนต์แนวโน้มโดยใช้อาร์กิวเมนต์ 8220l. start8221 และ 8220b. start8221 สำหรับฟังก์ชัน HoltWinters () โดยปกติแล้วจะกำหนดค่าเริ่มต้นของระดับเป็นค่าแรกในชุดข้อมูลเวลา (608 สำหรับข้อมูลกระโปรง) และค่าเริ่มต้นของความชันเป็นค่าที่สองซึ่งลบด้วยค่าแรก (9 สำหรับข้อมูลกระโปรง) ยกตัวอย่างเช่นเพื่อให้พอดีกับรูปแบบการทำนายของข้อมูลที่อยู่ในกระโปรงโดยใช้การคำนวณหาค่าความละเอียดแบบละเอียดแบบ Holt8217s โดยมีค่าเริ่มต้น 608 สำหรับระดับและ 9 สำหรับความลาดชัน b ขององค์ประกอบแนวโน้มเราพิมพ์: สำหรับการเรียบง่ายชี้แจงเราสามารถคาดการณ์ได้ สำหรับเวลาในอนาคตที่ไม่ได้ครอบคลุมตามชุดเวลาเดิมโดยใช้ฟังก์ชัน forecast. HoltWinters () ในชุด 8220forecast8221 ตัวอย่างเช่นข้อมูลชุดข้อมูลเวลาของเราสำหรับชุดกระโปรงเป็นช่วงปี 1866 ถึง 1911 ทำให้เราสามารถคาดการณ์ได้ตั้งแต่ 1912 ถึง 1930 (19 จุดข้อมูลเพิ่มเติม) และวางแผนโดยพิมพ์: การคาดการณ์จะแสดงเป็นเส้นสีน้ำเงินโดยมี 80 ช่วงการคาดการณ์เป็นพื้นที่สีส้มที่เป็นสีส้มและช่วงคาดการณ์ 95 เป็นพื้นที่สีเหลืองที่แรเงา สำหรับการเรียบง่ายชี้แจงเราสามารถตรวจสอบว่ารูปแบบการทำนายสามารถปรับปรุงได้โดยการตรวจสอบว่าข้อผิดพลาดในการคาดการณ์ตัวอย่างแสดง autocorrelations ที่ไม่เป็นศูนย์ที่ lags 1-20 ตัวอย่างเช่นสำหรับข้อมูลของชุดกระโปรงเราสามารถสร้าง correlogram และดำเนินการทดสอบ Ljung-Box โดยการพิมพ์: ที่นี่ correlogram แสดงให้เห็นว่าตัวอย่างความสัมพันธ์อัตโนมัติสำหรับข้อผิดพลาดในการคาดการณ์ในตัวอย่างที่ระดับ lag 5 เกินขอบเขตที่มีนัยสำคัญ อย่างไรก็ตามเราคาดว่าหนึ่งใน 20 ของ autocorrelations สำหรับ 20 ครั้งแรกล่าช้าเกินขอบเขตสำคัญ 95 โดยบังเอิญเพียงอย่างเดียว เมื่อเราดำเนินการทดสอบ Ljung-Box ค่า p จะเท่ากับ 0.47 ซึ่งแสดงให้เห็นว่ามีหลักฐานน้อยมากเกี่ยวกับความสัมพันธ์กันที่ไม่ใช่ศูนย์ในข้อผิดพลาดในการคาดการณ์ในตัวอย่างที่ล่าช้า 1-20 สำหรับการเรียบเรียบง่ายเราควรตรวจสอบว่าข้อผิดพลาดในการคาดการณ์มีความแปรปรวนคงที่ตลอดเวลาและมีการกระจายตามปกติโดยมีค่าเฉลี่ยเป็นศูนย์ เราสามารถทำได้โดยทำพล็อตเวลาของข้อผิดพลาดในการคาดการณ์และฮิสโตแกรมของการแจกแจงข้อผิดพลาดในการคาดการณ์กับเส้นโค้งปกติที่ซ้อนทับ: พล็อตเวลาของข้อผิดพลาดในการคาดการณ์แสดงให้เห็นว่าข้อผิดพลาดในการคาดการณ์มีค่าแปรปรวนคงที่ประมาณตลอดเวลา ฮิสโทแกรมของข้อผิดพลาดในการคาดการณ์แสดงให้เห็นว่าเป็นไปได้ว่าข้อผิดพลาดในการคาดการณ์มีการกระจายตามปกติโดยค่าเฉลี่ยศูนย์และความแปรปรวนคงที่ ดังนั้นการทดสอบ Ljung-Box แสดงให้เห็นว่ามีหลักฐานน้อยมากเกี่ยวกับความคลาดเคลื่อนในข้อผิดพลาดในการคาดการณ์ในขณะที่พล็อตเวลาและฮิสโตแกรมของข้อผิดพลาดในการคาดการณ์แสดงให้เห็นว่าเป็นไปได้ว่าข้อผิดพลาดในการคาดการณ์มีการแจกแจงแบบปกติด้วยค่าเฉลี่ยศูนย์และความแปรปรวนคงที่ ดังนั้นเราจึงสามารถสรุปได้ว่าการคำนวณหาค่าความละเอียดแบบเอกซ์ไทม์ Holt8217s ให้รูปแบบการทำนายที่เพียงพอสำหรับเส้นผ่าศูนย์กลางของกระโปรงซึ่งอาจไม่สามารถปรับปรุงได้ นอกจากนี้ยังหมายถึงสมมติฐานที่ว่าช่วงการคาดการณ์ 80 และ 95 ขึ้นอยู่กับว่าอาจเป็นผล Holt-Winters Smoothing แบบ Exponential หากคุณมีชุดข้อมูลเวลาที่สามารถอธิบายได้โดยใช้แบบจำลอง additive ที่มีแนวโน้มเพิ่มขึ้นหรือลดลงและฤดูกาลคุณสามารถใช้การคำนวณแบบย่อหน้าของ Holt-Winters เพื่อคาดการณ์ในระยะสั้นได้ การคำนวณความลื่นของ Holt-Winters ประเมินระดับความชันและองค์ประกอบตามฤดูกาล ณ จุดเวลาปัจจุบัน Smoothing ถูกควบคุมโดยพารามิเตอร์สามค่า ได้แก่ อัลฟาเบต้าและแกมมาสำหรับการประมาณระดับความลาดชัน b ขององค์ประกอบแนวโน้มและองค์ประกอบตามฤดูกาลตามลำดับ ณ จุดเวลาปัจจุบัน พารามิเตอร์อัลฟาเบต้าและแกมมาทั้งหมดมีค่าตั้งแต่ 0 ถึง 1 และค่าที่ใกล้เคียงกับ 0 หมายความว่าน้ำหนักที่น้อยมากจะถูกวางไว้บนข้อสังเกตล่าสุดเมื่อทำการคาดการณ์ค่าในอนาคต ตัวอย่างของชุดเวลาที่สามารถอธิบายได้โดยใช้แบบจำลองเพิ่มเติมซึ่งมีแนวโน้มและฤดูกาลเป็นชุดข้อมูลบันทึกการขายประจำเดือนสำหรับร้านขายของที่ระลึกในเมืองริมหาดในรัฐควีนส์แลนด์ออสเตรเลีย (กล่าวไว้ข้างต้น) เพื่อให้ เราสามารถใส่รูปแบบการคาดการณ์ได้โดยใช้ฟังก์ชัน HoltWinters () ตัวอย่างเช่นเพื่อให้พอดีกับรูปแบบการคาดการณ์สำหรับบันทึกการขายรายเดือนในร้านขายของที่ระลึกเราจะพิมพ์: ค่าประมาณของ alpha, beta และ gamma เท่ากับ 0.41, 0.00 และ 0.96 ตามลำดับ ค่าอัลฟ่า (0.41) ค่อนข้างต่ำบ่งชี้ว่าการประมาณระดับในจุดเวลาปัจจุบันขึ้นอยู่กับการสังเกตล่าสุดและข้อสังเกตบางอย่างในอดีตอันไกลโพ้น ค่าของเบต้าคือ 0.00 แสดงให้เห็นว่าค่าประมาณความลาดชัน b ขององค์ประกอบแนวโน้มจะไม่ได้รับการปรับปรุงตามช่วงเวลาและแทนค่าเท่ากับค่าเริ่มต้น นี่เป็นความรู้สึกที่ใช้งานได้ง่ายเนื่องจากระดับการเปลี่ยนแปลงในช่วงเวลาไม่น้อย แต่ช่วงความลาดชัน b ขององค์ประกอบแนวโน้มจะยังคงอยู่ในเกณฑ์เดียวกัน ในทางตรงกันข้ามค่าของแกมมา (0.96) สูงซึ่งบ่งชี้ว่าการประมาณองค์ประกอบตามฤดูกาล ณ จุดเวลาปัจจุบันขึ้นอยู่กับการสังเกตล่าสุด สำหรับการเรียบแบบเรียบง่ายและการเรียบแบบเลขยกกำลัง Holt8217s เราสามารถวางแผนชุดเวลาเดิมเป็นเส้นสีดำโดยมีค่าที่คาดการณ์ไว้เป็นเส้นสีแดงที่ด้านบนของที่: เราเห็นได้จากพล็อตว่าวิธีการแบบเมท็อดแบบโฮลท์ - วินเทอร์สประสบความสำเร็จมาก ในการคาดการณ์ยอดเขาตามฤดูกาลซึ่งเกิดขึ้นประมาณเดือนพฤศจิกายนของทุกปี หากต้องการคาดการณ์เวลาในอนาคตที่ไม่รวมอยู่ในชุดเวลาเดิมเราจะใช้ 8220forecast. HoltWinters () 8221 ฟังก์ชันในแพคเกจ 8220forecast8221 ตัวอย่างเช่นข้อมูลเดิมสำหรับการขายของที่ระลึกคือตั้งแต่เดือนมกราคม 2530 ถึงเดือนธันวาคม 2536 หากเราต้องการคาดการณ์ในช่วงมกราคม 2537 ถึงธันวาคม 2541 (48 เดือนขึ้นไป) และคาดการณ์การคาดการณ์เราจะพิมพ์: การคาดการณ์จะแสดงเป็น เส้นสีน้ำเงินและพื้นที่สีเทาสีส้มและสีเหลืองแสดงช่วงเวลาคาดการณ์ 80 และ 95 ตามลำดับ เราสามารถตรวจสอบได้ว่าจะสามารถปรับปรุงรูปแบบการคาดการณ์ได้หรือไม่โดยการตรวจสอบว่าข้อผิดพลาดในการคาดการณ์ในตัวอย่างแสดงการเชื่อมโยงกันที่ไม่เป็นศูนย์ที่ล่าช้า 1-20 โดยทำ correlogram และดำเนินการทดสอบ Ljung-Box: correlogram แสดงให้เห็นว่าการเชื่อมโยงกันด้วยตนเอง (autocorrelations) สำหรับข้อผิดพลาดในการคาดการณ์ในตัวอย่างจะต้องไม่เกินขอบเขตสำคัญสำหรับความล่าช้า 1-20 นอกจากนี้ค่า p สำหรับการทดสอบ Ljung-Box เท่ากับ 0.6 ซึ่งแสดงให้เห็นว่ามีหลักฐานเกี่ยวกับการเชื่อมโยงกันที่ไม่ใช่ศูนย์ที่มีการล่าช้า 1-20 เราสามารถตรวจสอบว่าข้อผิดพลาดในการคาดการณ์มีความแปรปรวนคงที่ตลอดเวลาและมีการแจกแจงตามปกติโดยมีค่าเฉลี่ยเป็นศูนย์โดยการทำพล็อตเวลาของข้อผิดพลาดในการคาดการณ์และฮิสโตแกรม (มีการซ้อนทับเส้นโค้งปกติ): จากพล็อตเวลา ข้อผิดพลาดในการคาดการณ์มีความแปรปรวนคงที่ตลอดช่วงเวลา จากฮิสโตแกรมของข้อผิดพลาดในการคาดการณ์ดูเหมือนว่าน่าจะเป็นไปได้ว่าข้อผิดพลาดในการคาดการณ์มีการกระจายตามปกติโดยมีค่าเฉลี่ยศูนย์ Thus, there is little evidence of autocorrelation at lags 1-20 for the forecast errors, and the forecast errors appear to be normally distributed with mean zero and constant variance over time. This suggests that Holt-Winters exponential smoothing provides an adequate predictive model of the log of sales at the souvenir shop, which probably cannot be improved upon. Furthermore, the assumptions upon which the prediction intervals were based are probably valid. ARIMA Models Exponential smoothing methods are useful for making forecasts, and make no assumptions about the correlations between successive values of the time series. However, if you want to make prediction intervals for forecasts made using exponential smoothing methods, the prediction intervals require that the forecast errors are uncorrelated and are normally distributed with mean zero and constant variance. While exponential smoothing methods do not make any assumptions about correlations between successive values of the time series, in some cases you can make a better predictive model by taking correlations in the data into account. Autoregressive Integrated Moving Average (ARIMA) models include an explicit statistical model for the irregular component of a time series, that allows for non-zero autocorrelations in the irregular component. Differencing a Time Series ARIMA models are defined for stationary time series. Therefore, if you start off with a non-stationary time series, you will first need to 8216difference8217 the time series until you obtain a stationary time series. If you have to difference the time series d times to obtain a stationary series, then you have an ARIMA(p, d,q) model, where d is the order of differencing used. You can difference a time series using the 8220diff()8221 function in R. For example, the time series of the annual diameter of women8217s skirts at the hem, from 1866 to 1911 is not stationary in mean, as the level changes a lot over time: We can difference the time series (which we stored in 8220skirtsseries8221, see above) once, and plot the differenced series, by typing: The resulting time series of first differences (above) does not appear to be stationary in mean. Therefore, we can difference the time series twice, to see if that gives us a stationary time series: Formal tests for stationarity Formal tests for stationarity called 8220unit root tests8221 are available in the fUnitRoots package, available on CRAN, but will not be discussed here. The time series of second differences (above) does appear to be stationary in mean and variance, as the level of the series stays roughly constant over time, and the variance of the series appears roughly constant over time. Thus, it appears that we need to difference the time series of the diameter of skirts twice in order to achieve a stationary series. If you need to difference your original time series data d times in order to obtain a stationary time series, this means that you can use an ARIMA(p, d,q) model for your time series, where d is the order of differencing used. For example, for the time series of the diameter of women8217s skirts, we had to difference the time series twice, and so the order of differencing (d) is 2. This means that you can use an ARIMA(p,2,q) model for your time series. The next step is to figure out the values of p and q for the ARIMA model. Another example is the time series of the age of death of the successive kings of England (see above): From the time plot (above), we can see that the time series is not stationary in mean. To calculate the time series of first differences, and plot it, we type: The time series of first differences appears to be stationary in mean and variance, and so an ARIMA(p,1,q) model is probably appropriate for the time series of the age of death of the kings of England. By taking the time series of first differences, we have removed the trend component of the time series of the ages at death of the kings, and are left with an irregular component. We can now examine whether there are correlations between successive terms of this irregular component if so, this could help us to make a predictive model for the ages at death of the kings. Selecting a Candidate ARIMA Model If your time series is stationary, or if you have transformed it to a stationary time series by differencing d times, the next step is to select the appropriate ARIMA model, which means finding the values of most appropriate values of p and q for an ARIMA(p, d,q) model. To do this, you usually need to examine the correlogram and partial correlogram of the stationary time series. To plot a correlogram and partial correlogram, we can use the 8220acf()8221 and 8220pacf()8221 functions in R, respectively. To get the actual values of the autocorrelations and partial autocorrelations, we set 8220plotFALSE8221 in the 8220acf()8221 and 8220pacf()8221 functions. Example of the Ages at Death of the Kings of England For example, to plot the correlogram for lags 1-20 of the once differenced time series of the ages at death of the kings of England, and to get the values of the autocorrelations, we type: We see from the correlogram that the autocorrelation at lag 1 (-0.360) exceeds the significance bounds, but all other autocorrelations between lags 1-20 do not exceed the significance bounds. To plot the partial correlogram for lags 1-20 for the once differenced time series of the ages at death of the English kings, and get the values of the partial autocorrelations, we use the 8220pacf()8221 function, by typing: The partial correlogram shows that the partial autocorrelations at lags 1, 2 and 3 exceed the significance bounds, are negative, and are slowly decreasing in magnitude with increasing lag (lag 1: -0.360, lag 2: -0.335, lag 3:-0.321). The partial autocorrelations tail off to zero after lag 3. Since the correlogram is zero after lag 1, and the partial correlogram tails off to zero after lag 3, this means that the following ARMA (autoregressive moving average) models are possible for the time series of first differences: an ARMA(3,0) model, that is, an autoregressive model of order p3, since the partial autocorrelogram is zero after lag 3, and the autocorrelogram tails off to zero (although perhaps too abruptly for this model to be appropriate) an ARMA(0,1) model, that is, a moving average model of order q1, since the autocorrelogram is zero after lag 1 and the partial autocorrelogram tails off to zero an ARMA(p, q) model, that is, a mixed model with p and q greater than 0, since the autocorrelogram and partial correlogram tail off to zero (although the correlogram probably tails off to zero too abruptly for this model to be appropriate) We use the principle of parsimony to decide which model is best: that is, we assum e that the model with the fewest parameters is best. The ARMA(3,0) model has 3 parameters, the ARMA(0,1) model has 1 parameter, and the ARMA(p, q) model has at least 2 parameters. Therefore, the ARMA(0,1) model is taken as the best model. An ARMA(0,1) model is a moving average model of order 1, or MA(1) model. This model can be written as: Xt - mu Zt - (theta Zt-1), where Xt is the stationary time series we are studying (the first differenced series of ages at death of English kings), mu is the mean of time series Xt, Zt is white noise with mean zero and constant variance, and theta is a parameter that can be estimated. A MA (moving average) model is usually used to model a time series that shows short-term dependencies between successive observations. Intuitively, it makes good sense that a MA model can be used to describe the irregular component in the time series of ages at death of English kings, as we might expect the age at death of a particular English king to have some effect on the ages at death of the next king or two, but not much effect on the ages at death of kings that reign much longer after that. Shortcut: the auto. arima() function The auto. arima() function can be used to find the appropriate ARIMA model, eg. type 8220library(forecast)8221, then 8220auto. arima(kings)8221. The output says an appropriate model is ARIMA(0,1,1). Since an ARMA(0,1) model (with p0, q1) is taken to be the best candidate model for the time series of first differences of the ages at death of English kings, then the original time series of the ages of death can be modelled using an ARIMA(0,1,1) model (with p0, d1, q1, where d is the order of differencing required). Example of the Volcanic Dust Veil in the Northern Hemisphere Let8217s take another example of selecting an appropriate ARIMA model. The file file robjhyndmantsdldataannualdvi. dat contains data on the volcanic dust veil index in the northern hemisphere, from 1500-1969 (original data from Hipel and Mcleod, 1994). This is a measure of the impact of volcanic eruptions8217 release of dust and aerosols into the environment. We can read it into R and make a time plot by typing: From the time plot, it appears that the random fluctuations in the time series are roughly constant in size over time, so an additive model is probably appropriate for describing this time series. Furthermore, the time series appears to be stationary in mean and variance, as its level and variance appear to be roughly constant over time. Therefore, we do not need to difference this series in order to fit an ARIMA model, but can fit an ARIMA model to the original series (the order of differencing required, d, is zero here). We can now plot a correlogram and partial correlogram for lags 1-20 to investigate what ARIMA model to use: We see from the correlogram that the autocorrelations for lags 1, 2 and 3 exceed the significance bounds, and that the autocorrelations tail off to zero after lag 3. The autocorrelations for lags 1, 2, 3 are positive, and decrease in magnitude with increasing lag (lag 1: 0.666, lag 2: 0.374, lag 3: 0.162). The autocorrelation for lags 19 and 20 exceed the significance bounds too, but it is likely that this is due to chance, since they just exceed the significance bounds (especially for lag 19), the autocorrelations for lags 4-18 do not exceed the signifiance bounds, and we would expect 1 in 20 lags to exceed the 95 significance bounds by chance alone. From the partial autocorrelogram, we see that the partial autocorrelation at lag 1 is positive and exceeds the significance bounds (0.666), while the partial autocorrelation at lag 2 is negative and also exceeds the significance bounds (-0.126). The partial autocorrelations tail off to zero after lag 2. Since the correlogram tails off to zero after lag 3, and the partial correlogram is zero after lag 2, the following ARMA models are possible for the time series: an ARMA(2,0) model, since the partial autocorrelogram is zero after lag 2, and the correlogram tails off to zero after lag 3, and the partial correlogram is zero after lag 2 an ARMA(0,3) model, since the autocorrelogram is zero after lag 3, and the partial correlogram tails off to zero (although perhaps too abruptly for this model to be appropriate) an ARMA(p, q) mixed model, since the correlogram and partial correlogram tail off to zero (although the partial correlogram perhaps tails off too abruptly for this model to be appropriate) Shortcut: the auto. arima() function Again, we can use auto. arima() to find an appropriate model, by typing 8220auto. arima(volcanodust)8221, which gives us ARIMA(1,0,2), which has 3 parameters. However, different criteria can be used to select a model (see auto. arima() help page). If we use the 8220bic8221 criterion, which penalises the number of parameters, we get ARIMA(2,0,0), which is ARMA(2,0): 8220auto. arima(volcanodust, ic8221bic8221)8221. The ARMA(2,0) model has 2 parameters, the ARMA(0,3) model has 3 parameters, and the ARMA(p, q) model has at least 2 parameters. Therefore, using the principle of parsimony, the ARMA(2,0) model and ARMA(p, q) model are equally good candidate models. An ARMA(2,0) model is an autoregressive model of order 2, or AR(2) model. This model can be written as: Xt - mu (Beta1 (Xt-1 - mu)) (Beta2 (Xt-2 - mu)) Zt, where Xt is the stationary time series we are studying (the time series of volcanic dust veil index), mu is the mean of time series Xt, Beta1 and Beta2 are parameters to be estimated, and Zt is white noise with mean zero and constant variance. An AR (autoregressive) model is usually used to model a time series which shows longer term dependencies between successive observations. Intuitively, it makes sense that an AR model could be used to describe the time series of volcanic dust veil index, as we would expect volcanic dust and aerosol levels in one year to affect those in much later years, since the dust and aerosols are unlikely to disappear quickly. If an ARMA(2,0) model (with p2, q0) is used to model the time series of volcanic dust veil index, it would mean that an ARIMA(2,0,0) model can be used (with p2, d0, q0, where d is the order of differencing required). Similarly, if an ARMA(p, q) mixed model is used, where p and q are both greater than zero, than an ARIMA(p,0,q) model can be used. Forecasting Using an ARIMA Model Once you have selected the best candidate ARIMA(p, d,q) model for your time series data, you can estimate the parameters of that ARIMA model, and use that as a predictive model for making forecasts for future values of your time series. You can estimate the parameters of an ARIMA(p, d,q) model using the 8220arima()8221 function in R. Example of the Ages at Death of the Kings of England For example, we discussed above that an ARIMA(0,1,1) model seems a plausible model for the ages at deaths of the kings of England. You can specify the values of p, d and q in the ARIMA model by using the 8220order8221 argument of the 8220arima()8221 function in R. To fit an ARIMA(p, d,q) model to this time series (which we stored in the variable 8220kingstimeseries8221, see above), we type: As mentioned above, if we are fitting an ARIMA(0,1,1) model to our time series, it means we are fitting an an ARMA(0,1) model to the time series of first differences. An ARMA(0,1) model can be written Xt - mu Zt - (theta Zt-1), where theta is a parameter to be estimated. From the output of the 8220arima()8221 R function (above), the estimated value of theta (given as 8216ma18217 in the R output) is -0.7218 in the case of the ARIMA(0,1,1) model fitted to the time series of ages at death of kings. Specifying the confidence level for prediction intervals You can specify the confidence level for prediction intervals in forecast. Arima() by using the 8220level8221 argument. For example, to get a 99.5 prediction interval, we would type 8220forecast. Arima(kingstimeseriesarima, h5, levelc(99.5))8221. We can then use the ARIMA model to make forecasts for future values of the time series, using the 8220forecast. Arima()8221 function in the 8220forecast8221 R package. For example, to forecast the ages at death of the next five English kings, we type: The original time series for the English kings includes the ages at death of 42 English kings. The forecast. Arima() function gives us a forecast of the age of death of the next five English kings (kings 43-47), as well as 80 and 95 prediction intervals for those predictions. The age of death of the 42nd English king was 56 years (the last observed value in our time series), and the ARIMA model gives the forecasted age at death of the next five kings as 67.8 years. We can plot the observed ages of death for the first 42 kings, as well as the ages that would be predicted for these 42 kings and for the next 5 kings using our ARIMA(0,1,1) model, by typing: As in the case of exponential smoothing models, it is a good idea to investigate whether the forecast errors of an ARIMA model are normally distributed with mean zero and constant variance, and whether the are correlations between successive forecast errors. For example, we can make a correlogram of the forecast errors for our ARIMA(0,1,1) model for the ages at death of kings, and perform the Ljung-Box test for lags 1-20, by typing: Since the correlogram shows that none of the sample autocorrelations for lags 1-20 exceed the significance bounds, and the p-value for the Ljung-Box test is 0.9, we can conclude that there is very little evidence for non-zero autocorrelations in the forecast errors at lags 1-20. To investigate whether the forecast errors are normally distributed with mean zero and constant variance, we can make a time plot and histogram (with overlaid normal curve) of the forecast errors: The time plot of the in-sample forecast errors shows that the variance of the forecast errors seems to be roughly constant over time (though perhaps there is slightly higher variance for the second half of the time series). The histogram of the time series shows that the forecast errors are roughly normally distributed and the mean seems to be close to zero. Therefore, it is plausible that the forecast errors are normally distributed with mean zero and constant variance. Since successive forecast errors do not seem to be correlated, and the forecast errors seem to be normally distributed with mean zero and constant variance, the ARIMA(0,1,1) does seem to provide an adequate predictive model for the ages at death of English kings. Example of the Volcanic Dust Veil in the Northern Hemisphere We discussed above that an appropriate ARIMA model for the time series of volcanic dust veil index may be an ARIMA(2,0,0) model. To fit an ARIMA(2,0,0) model to this time series, we can type: As mentioned above, an ARIMA(2,0,0) model can be written as: written as: Xt - mu (Beta1 (Xt-1 - mu)) (Beta2 (Xt-2 - mu)) Zt, where Beta1 and Beta2 are parameters to be estimated. The output of the arima() function tells us that Beta1 and Beta2 are estimated as 0.7533 and -0.1268 here (given as ar1 and ar2 in the output of arima()). Now we have fitted the ARIMA(2,0,0) model, we can use the 8220forecast. ARIMA()8221 model to predict future values of the volcanic dust veil index. The original data includes the years 1500-1969. To make predictions for the years 1970-2000 (31 more years), we type: We can plot the original time series, and the forecasted values, by typing: One worrying thing is that the model has predicted negative values for the volcanic dust veil index, but this variable can only have positive values The reason is that the arima() and forecast. Arima() functions don8217t know that the variable can only take positive values. Clearly, this is not a very desirable feature of our current predictive model. Again, we should investigate whether the forecast errors seem to be correlated, and whether they are normally distributed with mean zero and constant variance. To check for correlations between successive forecast errors, we can make a correlogram and use the Ljung-Box test: The correlogram shows that the sample autocorrelation at lag 20 exceeds the significance bounds. However, this is probably due to chance, since we would expect one out of 20 sample autocorrelations to exceed the 95 significance bounds. Furthermore, the p-value for the Ljung-Box test is 0.2, indicating that there is little evidence for non-zero autocorrelations in the forecast errors for lags 1-20. To check whether the forecast errors are normally distributed with mean zero and constant variance, we make a time plot of the forecast errors, and a histogram: The time plot of forecast errors shows that the forecast errors seem to have roughly constant variance over time. However, the time series of forecast errors seems to have a negative mean, rather than a zero mean. We can confirm this by calculating the mean forecast error, which turns out to be about -0.22: The histogram of forecast errors (above) shows that although the mean value of the forecast errors is negative, the distribution of forecast errors is skewed to the right compared to a normal curve. Therefore, it seems that we cannot comfortably conclude that the forecast errors are normally distributed with mean zero and constant variance Thus, it is likely that our ARIMA(2,0,0) model for the time series of volcanic dust veil index is not the best model that we could make, and could almost definitely be improved upon Links and Further Reading Here are some links for further reading. For a more in-depth introduction to R, a good online tutorial is available on the 8220Kickstarting R8221 website, cran. r-project. orgdoccontribLemon-kickstart . There is another nice (slightly more in-depth) tutorial to R available on the 8220Introduction to R8221 website, cran. r-project. orgdocmanualsR-intro. html . You can find a list of R packages for analysing time series data on the CRAN Time Series Task View webpage . To learn about time series analysis, I would highly recommend the book 8220Time series8221 (product code M24902) by the Open University, available from the Open University Shop . There are two books available in the 8220Use R8221 series on using R for time series analyses, the first is Introductory Time Series with R by Cowpertwait and Metcalfe, and the second is Analysis of Integrated and Cointegrated Time Series with R by Pfaff. Acknowledgements I am grateful to Professor Rob Hyndman. for kindly allowing me to use the time series data sets from his Time Series Data Library (TSDL) in the examples in this booklet. Many of the examples in this booklet are inspired by examples in the excellent Open University book, 8220Time series8221 (product code M24902), available from the Open University Shop . Thank you to Ravi Aranke for bringing auto. arima() to my attention, and Maurice Omane-Adjepong for bringing unit root tests to my attention, and Christian Seubert for noticing a small bug in plotForecastErrors(). Thank you for other comments to Antoine Binard and Bill Johnston. I will be grateful if you will send me (Avril Coghlan) corrections or suggestions for improvements to my email address alc 64 sanger 46 ac 46 ukMoving average could not read the data you posted try dput next time. If it is just a 2 day moving average, try the filter function: gt x lt - 1:20 gt x 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 gt filter(x, c(.5,.5)) Time Series: Start 1 End 20 Frequency 1 1 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5 14.5 15.5 16.5 17.5 18.5 19.5 NA gt Jim Holtman Data Munger Guru What is the problem that you are trying to solve Tell me what you want to do, not how you want to do it. เมื่อวันอาทิตย์ที่ 28 ธันวาคม 2014 เวลา 6:56 น. Rolf Edberg lthidden email gt wrote: เวอร์ชัน HTML อื่น ๆ ได้ลบรายชื่ออีเมลที่ซ่อนอยู่ - ไปที่ UNSUBSCRIBE และอื่น ๆ ดูที่ stat. ethz. chmailmanlistinfor-help โปรดอ่านคำแนะนำการโพสต์ R - project. orgposting-guide. html และให้ความเห็นว่ามีเนื้อหาน้อยและมีความสามารถในการทำซ้ำได้ gt x lt - read. csv(text quotDate, Open, High, Low, Close, Volume, Adj Close 2014-12-26,162.27,163.09,162.01,162.34,1912200,162.34 2014-12-24,162.88,162.99,161.61,161.82,1868100,161.82 2014-12-23,162.23,162.90,161.61,162.24,4043300,162.24 2014-12-22,158.33,161.91,158.33,161.44,4682500,161.44quot, as. is TRUE) gt require(lubridate) gt xDate lt - ymd(xDate) convert to a date field gt x lt - xorder(xDate), sort by date gt xtwoday lt - filter(xClose, c(0.5, 0.5)) compute moving average gt x Date Open High Low Close Volume Adj. Close twoday 4 2014-12-22 158.33 161.91 158.33 161.44 4682500 161.44 161.84 3 2014-12-23 162.23 162.90 161.61 162.24 4043300 162.24 162.03 2 2014-12-24 162.88 162.99 161.61 161.82 1868100 161.82 162.08 1 2014-12-26 162.27 163.09 162.01 162.34 1912200 162.34 NA Jim Holtman Data Munger Guru What is the problem that you are trying to solve Tell me what you want to do, not how you want to do it. เมื่อวันอาทิตย์ที่ 28 ธันวาคม 2014 เวลา 8:31 น. Rolf Edberg ได้พิมพ์อีเมล gt wrote: gt ขอบคุณที่พยายามช่วย gt gt gt gt ฉันเป็นคนใหม่ในรหัส R ดังนั้นต้องการความช่วยเหลือในทุกขั้นตอน gt gt gt gt The goal is to use technical analysis on stock prices. ไม่เพียง แต่ MA แต่ถ้า GT ฉันเข้าใจหลักการด้วยที่ฉันหวังว่าฉันจะใช้เทคนิคอื่น ๆ ได้เช่นกัน ฉันพบ R-adamant แต่ไม่ทราบวิธีใช้ gt gt gt gt I downloaded 4 days of IBM prices from yahoo in a csv-file. gt gt ฉันไม่รู้ว่า Dput คืออะไร gt gt gt gt Here is the IBM prices in a text string: gt gt Date, Open, High, Low, Close, Volume, Adj Close gt gt 2014-12-26,162.27,163.09,162.01,162.34,1912200,162.34 gt gt 2014-12-24,162.88,162.99,161.61,161.82,1868100,161.82 gt gt 2014-12-23,162.23,162.90,161.61,162.24,4043300,162.24 gt gt 2014-12-22,158.33,161.91,158.33,161.44,4682500,161.44 gt gt gt gt I would like the date in sorted with the oldest at the top. gt gt gt gt I would like to add a column with the technical indicator, in this case gt 2-days MA of Close. gt gt gt gt And I would like to have the result in a csv file. ฉันจะใช้ไฟล์นี้ในอีกหนึ่งโปรแกรม gt gt gt gt Thank you. gt; gt; gt; gt; gt; gt; gt; gt gt gt gt; gt; gt; gt gt gt gt gt; gt; gt; gt; gt; gt gt gt gt gt; gt; gt; gt; gt; gt gt gt gt gt gt gt gt gt gt ส่ง: วันอาทิตย์ 28 ธันวาคม 2014 4:45 PM gt ถึง: Rolf Edberg gt Cc: R gt gt gt ไม่สามารถอ่านข้อมูลที่คุณโพสต์ได้ลอง dput ในครั้งต่อไป gt gt gt gt ถ้าเป็นค่าเฉลี่ยเคลื่อนที่ 2 วันให้ลองใช้ฟังก์ชันกรอง: gt gt gt gt gt x lt - 1:20 gt gt gt 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 gt gt gt (x, c (.5, .5)) gt gt Time Series: gt gt เริ่มต้น 1 gt gt สิ้นสุด 20 gt gt ความถี่ 1 gt gt 1 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5 14.5 gt 15.5 16.5 17.5 18.5 19.5 NA gt gt gt gt; gt; gt; gt gt; gt; gt; gt; gt; gt; gt gt; gt; gt gt; gt gt; gt gt; gt; gt & gt; munger guru gt gt ปัญหาคืออะไรที่คุณกำลังพยายามแก้ gt บอกฉันว่าคุณต้องการทำอะไร ไม่ใช่วิธีการที่คุณต้องการทำ gt; gt gt gt gt ในวันอาทิตย์ที่ 28 ธันวาคม 2014 เวลา 6:56 น. Rolf Edberg ได้พิมพ์อีเมล: gt gt gt gt ฉันจะเพิ่มคอลัมน์ใหม่โดยมีค่าเฉลี่ยเคลื่อนที่ 2 วัน (จาก gt r-adamant (githubTotallyBullshitradamant) ) ในราคา IBM ในไฟล์ gt csv (ibm. csv) จากนั้นบันทึกทั้งหมดในไฟล์ CSV ใหม่ (ibm2.csv) gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt gt ต่ำ gt gt gt ปิด gt gt gt gt gt gt gt 162.27 gt gt 163.09 gt gt 162.01 gt gt 162.34 gt gt 1,912,200 gt gt 162.34 gt gt gt วันที่ 24 ธันวาคม 2014 gt gt 162.88 gt gt 162.99 gt gt 161.61 gt gt 161.82 gt gt gt วันที่ 23 ธันวาคม 2014 gt gt 162.23 gt gt 162.90 gt gt 161.61 gt gt 162.24 gt gt 4,043,300 gt gt 162.24 gt gt gt 22 ธันวาคม 2014 gt gt 158.33 gt gt 161.91 gt gt; 158.33 gt gt; 161.44 gt gt; gt; gt; gt; gt; 157.49 gt gt; 160.41 gt; gt; 157.49 gt; gt; 158.51 gt; gt; 8,864,900 gt; gt; 158.51 gt; gt; gt gt; gt; gt; จดหมาย li st - UNSUBSCRIBE และอื่น ๆ โปรดดูที่ gt stat. ethz. chmailmanlistinfor-help gt โปรดอ่านคู่มือการโพสต์ GT R-project. orgposting-guide. html gt และแสดงรหัสที่สามารถอ่านซ้ําได้ gt gt gt alternative HTML version deleted hidden email mailing list -- To UNSUBSCRIBE and more, see stat. ethz. chmailmanlistinfor-help PLEASE do read the posting guide R-project. orgposting-guide. html and provide commented, minimal, self-contained, reproducible code. On Tue, 30 Dec 2014, jim holtman wrote: gt Try this: gt gtgt x lt - read. csv(text quotDate, Open, High, Low, Close, Volume, Adj Close gt 2014-12-26,162.27,163.09,162.01,162.34,1912200,162.34 gt 2014-12-24,162.88,162.99,161.61,161.82,1868100,161.82 gt 2014-12-23,162.23,162.90,161.61,162.24,4043300,162.24 gt 2014-12-22,158.33,161.91,158.33,161.44,4682500,161.44quot, as. is TRUE) gtgt require(lubridate) gtgt xDate lt - ymd(xDate) convert to a date field gtgt x lt - xorder(xDate), sort by date gtgt xtwoday lt - filter(xClose, c(0.5, 0.5)) compute moving average gtgt x gt Date Open High Low Close Volume Adj. Close twoday gt 4 2014-12-22 158.33 161.91 158.33 161.44 4682500 161.44 161.84 gt 3 2014-12-23 162.23 162.90 161.61 162.24 4043300 162.24 162.03 gt 2 2014-12-24 162.88 162.99 161.61 161.82 1868100 161.82 162.08 gt 1 2014-12-26 162.27 163.09 162.01 162.34 1912200 162.34 NA A canned approach for reading and filtering the data is also available in the quotzooquot package. ฟังก์ชัน read. zoo () สามารถสร้างวัตถุแบบอนุกรมเวลาได้อย่างอิสระด้วยดัชนีเวลา quotDatequot: Rgt z lt - read. zoo (text quotat, Open, High, Low, Close, Volume, Adj Close 2014-12-26,162.27,163.09 , 162.01,162.34,1912200,162.34 2014-12-24,162.88,162.99,161.61,161.82,1868100,161.82 2014-12-23,162.23,162.90,161.61,162.24,4043300,162.24 2014-12-22,158.33,161.91,158.33,161.44, แล้ว rollmean () สามารถคำนวณหมายถึงการรีดสำหรับตัวแปรทั้งหมด column: Rgt rollmean (z, 2) เปิด High Low Close Volume Adj. Close 2014- 12-22 160.280 4362900 161.84 2014.12-23 162.555 162.945 161.61 162.03 2955700 162.03 2014-12-24 162.575 163.040 161.81 162.08 1890150 162.08 นอกจากนี้คุณยังสามารถจัดหาอาร์กิวเมนต์ NA NA ได้หากต้องการต่อท้าย NA สำหรับปี 2014-12-26 . gt gt Jim Holtman gt Data Munger Guru gt gt What is the problem that you are trying to solve gt Tell me what you want to do, not how you want to do it. gt gt On Sun, Dec 28, 2014 at 8:31 AM, Rolf Edberg lthidden email gt wrote: gt gtgt Thank you for trying to help. gtgt gtgt gtgt gtgt ฉันเป็นคนใหม่กับรหัส R ดังนั้นต้องการความช่วยเหลือในทุกขั้นตอน gtgt gtgt gtgt gtgt เป้าหมายคือการใช้การวิเคราะห์ทางเทคนิคในราคาหุ้น ไม่เพียง แต่ MA แต่ถ้า gtgt ฉันเข้าใจหลักการด้วยที่ฉันหวังว่าฉันสามารถใช้เทคนิคอื่น ๆ gtgt เช่นกัน gtgt gtgt gtgt gtgt I found R-adamant but do not know how to use it. gtgt gtgt gtgt gtgt ฉันดาวน์โหลดราคาไอบีเอ็มเป็นเวลา 4 วันจาก yahoo ในไฟล์ csv gtgt gtgt I dont know what dput is. gtgt gtgt gtgt gtgt Here is the IBM prices in a text string: gtgt gtgt Date, Open, High, Low, Close, Volume, Adj Close gtgt gtgt 2014-12-26,162.27,163.09,162.01,162.34,1912200,162.34 gtgt gtgt 2014-12-24,162.88,162.99,161.61,161.82,1868100,161.82 gtgt gtgt 2014-12-23,162.23,162.90,161.61,162.24,4043300,162.24 gtgt gtgt 2014-12-22,158.33,161.91,158.33,161.44,4682500,161.44 gtgt gtgt gtgt gtgt I would like the date in sorted with the oldest at the top. gtgt gtgt gtgt gtgt ฉันต้องการเพิ่มคอลัมน์ที่มีตัวบ่งชี้ด้านเทคนิคในกรณีนี้คือปิดการขายงานโดยประมาณ 2 วันของ gtgt gtgt gtgt gtgt gtgt And I would like to have the result in a csv file. I will use the file in gtgt another program. gtgt gtgt gtgt gtgt Thank you. gtgt gtgt gtgt gtgt Rolf gtgt gtgt gtgt gtgt From: jim holtman mailto:hidden email gtgt Sent: Sunday, December 28, 2014 4:45 PM gtgt To: Rolf Edberg gtgt Cc: R mailing list gtgt Subject: Re: R Moving average gtgt gtgt gtgt gtgt could not read the data you posted try dput next time. gtgt gtgt gtgt gtgt If it is just a 2 day moving average, try the filter function: gtgt gtgt gtgt gtgt gt x lt - 1:20 gtgt gtgt gt x gtgt gtgt 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 gtgt gtgt gt filter(x, c(.5,.5)) gtgt gtgt Time Series: gtgt gtgt Start 1 gtgt gtgt End 20 gtgt gtgt Frequency 1 gtgt gtgt 1 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5 12.5 13.5 14.5 gtgt 15.5 16.5 17.5 18.5 19.5 NA gtgt gtgt gt gtgt gtgt gtgt gtgt gtgt gtgt Jim Holtman gtgt Data Munger Guru gtgt gtgt What is the problem that you are trying to solve gtgt Tell me what you want to do, not how you want to do it. gtgt gtgt gtgt gtgt On Sun, Dec 28, 2014 at 6:56 AM, Rolf Edberg lthidden email gt wrote: gtgt gtgt gtgt gtgt How do I add a new column with 2-days moving average (from gtgt r-adamant(githubTotallyBullshitradamant )) on IBM prices in a gtgt csv-file (ibm. csv) and then save all in a new csv file(ibm2.csv) gtgt gtgt gtgt gtgt gtgt Prices gtgt gtgt gtgt gtgt gtgt gtgt Date gtgt gtgt Open gtgt gtgt High gtgt gtgt Low gtgt gtgt Close gtgt gtgt Volume gtgt gtgt Adj Close gtgt gtgt gtgt Dec 26, 2014 gtgt gtgt 162.27 gtgt gtgt 163.09 gtgt gtgt 162.01 gtgt gtgt 162.34 gtgt gtgt 1,912,200 gtgt gtgt 162.34 gtgt gtgt gtgt Dec 24, 2014 gtgt gtgt 162.88 gtgt gtgt 162.99 gtgt gtgt 161.61 gtgt gtgt 161.82 gtgt gtgt 1,868,100 gtgt gtgt 161.82 gtgt gtgt gtgt Dec 23, 2014 gtgt gtgt 162.23 gtgt gtgt 162.90 gtgt gtgt 161.61 gtgt gtgt 162.24 gtgt gtgt 4,043,300 gtgt gtgt 162.24 gtgt gtgt gtgt Dec 22, 2014 gtgt gtgt 158.33 gtgt gtgt 161.91 gtgt gtgt 158.33 gtgt gtgt 161.44 gtgt gtgt 4,682,500 gtgt gtgt 161.4 4 gtgt gtgt gtgt Dec 19, 2014 gtgt gtgt 157.49 gtgt gtgt 160.41 gtgt gtgt 157.49 gtgt gtgt 158.51 gtgt gtgt 8,864,900 gtgt gtgt 158.51 gtgt gtgt gtgt gtgt gtgt alternative HTML version deleted gtgt gtgt gtgt hidden email mailing list -- To UNSUBSCRIBE and more, see gtgt stat. ethz. chmailmanlistinfor-help gtgt PLEASE do read the posting guide gtgt R-project. orgposting-guide. html gtgt and provide commented, minimal, self-contained, reproducible code. gtgt gtgt gtgt gt gt เวอร์ชัน HTML อื่นที่ถูกลบ gt gt gt gt รายการอีเมลที่ซ่อนอยู่ - สำหรับ UNSUBSCRIBE และอื่น ๆ โปรดดูที่ gt stat. ethz. chmailmanlistinfor-help gt โปรดอ่านคู่มือการโพสต์ R-project. orgposting-guide. html gt และ ให้ความเห็นน้อยที่สุดตัวเองในตัวทำซ้ำรหัส รายชื่ออีเมลที่ซ่อนอยู่ - เพื่อ UNSUBSCRIBE และอื่น ๆ โปรดดูที่ stat. ethz. chmailmanlistinfor-help โปรดอ่านคู่มือการโพสต์ R-project. orgposting-guide. html และแสดงความคิดเห็นที่มีเนื้อหาน้อยและมีความสามารถในการทำซ้ำได้ ในวันพุธที่ 31 ธันวาคม 2014 เวลา 11:24 น. John Sorkin lthidden email gt wrote: เพื่อนร่วมงานของ GT Windows 7 gt gt, gt ฉันใช้ฟังก์ชัน fix () เพื่อแก้ไขฟังก์ชันที่มีอยู่เมื่อใช้ RStudio หลังจากแก้ไขฟังก์ชันแล้วฉันจะได้รับตัวเลือกในการบันทึกฟังก์ชันแก้ไข I would like to know (1) where the modified function is stored (the save button does not have an option to specify where the modified function will be saved), and (2) how I can access the modified function in other RStudio or R sessions, and (3) how I can make the function accessible to R and RStudio sessions run on other computers. I dont use RStudio, so I have no idea if it overwrites the base fix() function. But if it does, this is the wrong place to ask about it, so heres the base R answer. fix() saves the edited function to your workspace. That is, if you type ls() at an R prompt after running fix(), it will show your new edited function. The usual methods for exporting something from R to your hard disk will work, such as save() and load(). You could also put your function into a text file myfun. R and use source() to read it into R. Once youve used one of these options to save your file to disk, it is portable between R sessions and computers. ฉันคิดว่ามันสะดวกมากที่จะใช้โปรแกรมแก้ไขข้อความและแหล่งที่มา () แทนเป็นการแก้ไข () That eases the transition into making packages too. รายชื่ออีเมลที่ซ่อนอยู่ - เพื่อ UNSUBSCRIBE และอื่น ๆ โปรดดูที่ stat. ethz. chmailmanlistinfor-help โปรดอ่านคู่มือการโพสต์ R-project. orgposting-guide. html และแสดงความคิดเห็นที่มีเนื้อหาน้อยและมีความสามารถในการทำซ้ำได้ เปิดโพสต์นี้ในมุมมองแบบกำหนดเองรายงานเนื้อหาว่าไม่เหมาะสมเรื่องการบันทึกฟังก์ชัน R ที่แก้ไขแล้ว RStudio และ R ในการตอบกลับโพสต์นี้โดย John Sorkin เมื่อ 31.12.2014 17:24 John Sorkin เขียน: gt Windows 7 gt gt Colleagues, gt i ใช้ฟังก์ชัน fix () เพื่อแก้ไขฟังก์ชั่นที่มีอยู่เมื่อใช้ RStudio หลังจากแก้ไขฟังก์ชันแล้วฉันจะได้รับตัวเลือกในการบันทึกฟังก์ชันแก้ไข I would like to know (1) where the modified function is stored (the save button does not have an option to specify where the modified function will be saved), and (2) how I can access the modified function in other RStudio or R sessions, and (3) how I can make the function accessible to R and RStudio sessions run on other computers. ไม่แน่ใจว่าสิ่งนี้จะทำอย่างไรกับ RStudio แต่จำเป็นนี้เป็นวิธีที่ไม่ถูกต้องเนื่องจากการบันทึกภายใต้ชื่อที่แตกต่างกันเคยชินทำให้ฟังก์ชันมีอยู่ใน R แล้ว ถ้าคุณต้องการเปลี่ยนฟังก์ชันบางอย่างให้ใช้เวอร์ชันต้นฉบับและแก้ไขโดยตรงจากนั้นบันทึกด้วยชื่อที่ชัดเจนแล้วนำไปวางใน R. Best, Uwe Ligges gt ขอบคุณ, gt john gt gt John David Sorkin MD Ph D. gt Professor of Medicine gt Chief, Biostatistics and Informatics gt University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine gt Baltimore VA Medical Center gt 10 North Greene Street gt GRECC (BT18GR) gt Baltimore, MD 21201-1524 gt (Phone) 410-605-7119 gt (Fax) 410-605-7913 (Please call phone number above prior to faxing) gt gt Confidentiality Statement: gt This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. ถ้าคุณไม่ใช่ผู้รับที่ต้องการโปรดติดต่อผู้ส่งโดยตอบอีเมลและทำลายสำเนาของข้อความต้นฉบับทั้งหมด gt gt hidden email mailing list -- To UNSUBSCRIBE and more, see gt stat. ethz. chmailmanlistinfor-help gt PLEASE do read the posting guide R-project. orgposting-guide. html gt and provide commented, minimal, self-contained, reproducible code. gt hidden email mailing list -- To UNSUBSCRIBE and more, see stat. ethz. chmailmanlistinfor-help PLEASE do read the posting guide R-project. orgposting-guide. html and provide commented, minimal, self-contained, reproducible code. I have a plot of time series in ggplot2 package and I have performed the Moving average and I would like to add the result of moving average to the plot of time series. Sample of Data-set (p31): ambtemp dt -1.14 2007-09-29 00:01:57 -1.12 2007-09-29 00:03:57 -1.33 2007-09-29 00:05:57 -1.44 2007-09-29 00:07:57 -1.54 2007-09-29 00:09:57 -1.29 2007-09-29 00:11:57 Applied code for time series presentation: Sample of Moving average plot Sample of expected results The challenge is that time series data ovbtained from data-set which includes timestamps and temperature but Moving average data include just the average column and not the timestamps and fitting these two can cause inconsistency.

No comments:

Post a Comment