Moving genomsnittet största lag


Tidsfördröjning mellan Mars och Earth Spacecraft-händelsestid vs jorden tar emot tid Ett foto på Mars Express-fördröjningsdisplayen på styrsystemet, vilket visar oss det kritiska antalet envägsljustid, tvåvägslystid och avståndet från jorden. En av de svåraste sakerna om att använda en rymdfarkost runt Mars (för att inte tala om de olika tidszoner) jämfört med jorden är att dess så långt borta är Mars så långt borta, att det tar ganska lång tid radiosignaler att få från rymdfarkosten tillbaka till jorden. Under nyfikenhet EDL kommer denna fördröjning att vara 13 minuter, 48 sekunder, ungefär halvvägs mellan minsta fördröjningen på cirka 4 minuter och maximalt cirka 24 minuter. Detta gör det svårt att använda Mars Express eftersom det är svårt att prata med rymdfarkosten eller reagera om något händer ombord. Om det finns ett problem och rymdfarkosten berättar för oss, vet vi inte i 13 minuter, och även om vi reagerar genast kommer det att vara ytterligare 13 minuter innan våra instruktioner går tillbaka till Mars, det finns mycket som kan hända om en halvtimme på Mars (till exempel en hel nyfikenhet). För att hålla Mars Express flyger säkert laddar vi alla kommandon för uppdraget i förväg och byggs i mycket autonomi för att låta rymdfarkosten ta hand om sig själv, du kan säga att för nyfikenhetens landning körde helt på autopilot Förseningen är inget att göra med rymdfarkosten eller hårdvaran på marken den kan inte förbättras med en snabbare dator eller en kraftfullare radio. Faktum är att det följer universets grundläggande hastighetsgräns ljusets hastighet. Vid 1,079,000,000 kmhour är ljuset ganska snabbt du kan komma härifrån till månen på lite över en sekund Men det understryker bara hur långt Mars är. Allt ljus (eller elektromagnetisk strålning, som inkluderar radiosignaler) går upp till denna hastighet, och radiovågor från jord till Mars Express och tillbaka är inget undantag. Ta en titt på Wikipedia-artikeln om ljusets hastighet och se hur Einstein kom 1905 på konceptet för denna kosmiska hastighetsgräns. Framför allt, för morgondagens täckning av nyfikenhetens landning, är det svårt för oss att träna sig när vi ska berätta vad som händer (som du har sett i vår tre kolonnens tidslinje) Vid ESOC talar vi om två olika tider Spacecraft Event Time (SCET) och Earth Received Time (ERT). Den förra är vad som händer faktiskt på Mars just nu, men vi kommer inte att höra om det förrän över 13 minuter senare, en gång vi kallar ERT. Förseningen mellan de två brukar kallas One-Way Light Time (OWLT) och tiden för att ett meddelande ska gå till Mars och återkomma är tvåvägs ljustid (TWLT) eller rundturstid. Under hela vår täckning följer du NASAs ledning och brukar kommunicera händelser här och på Twitter till dig i ERT, för det vet då väl faktiskt vad som hände. Om vi ​​kommunicerar något i SCET så låt du veta så att du (och vi också) inte blir förvirrade sin hela del av det roliga att utforska solsystemet 80 tankar om ldquo Tidsfördröjning mellan Mars och Earth rdquo Nej, alla vågor reser vid samma hastighet. Det tar ljus åtta minuter på en enkel resa, 16 minuter på en tvåvägsresa. Vänligen lär dig in i fysiken En foton är bärarpartikeln för både synligt ljus OCH radiovågor, vilka båda är former av elektromagnetisk energi, bara vid olika frekvenser. Photonic energi (som jag aldrig hört talas om) skulle vara synonymt med elektromagnetisk energi. Ljus, värme, gamma, radio, mikrovågor, ultraviolett - alla medieras av fotonpartiklar, men har också egenskaper av vågor, och därmed frekvensegenskaperna. Lättaste att tänka på dem som vågor medan de reser, men partiklar när de slår något. Och dessa siffror gäller endast för ljus som reser i vakuum. Ljus som passerar genom materiel färdas mätbart långsammare. Jag tror att några laboratorier nyligen genomförde ett experiment där de stoppade ljuset inuti ett ämne genom att sakta ner det på en eller annan sätt. Vet inte hur de gjorde det, jag läste inte hela grejen. skulle det vara motiverat att vissa frekvenser av elektromagnetisk energi färdas snabbare då de samverkar mindre med de flesta former av materia och därmed har mindre inblandning när de reser stora avstånd än andra våglängder som reser samma väg och avstånd till exempel, avledt ljus jämfört med gamma strålning, utlöst ljus skulle ha en högre chans att interagera med ett medium jämfört med gammarager som fördröjer våglängden när den passerar genom små mängder materia. Kan man säga att detta skulle resultera i gammarays med en snabbare nettofartshastighet i genomsnitt Felaktig. Låt mig citera direkt från artikeln du just läst eftersom du verkar ha missat den. Vid 1,079,000,000 kmhour är ljuset ganska snabbt du kan komma härifrån till månen på lite över en sekund Men det understryker bara hur långt Mars är. Allt ljus (eller elektromagnetisk strålning, som inkluderar radiosignaler) går upp till denna hastighet, och radiovågor från jord till Mars Express och tillbaka är inget undantag. Tiden från jord till mars varierar mellan 4 och 24 minuter eftersom jorden (och mars) både kretsar solen, inte varandra. Avståndet mellan dem kan därför förändras ganska dramatiskt beroende på var vi befinner oss i våra respektive banor. När Mars ligger direkt bakom jorden på närmaste möjliga punkt, är det bara fyra minuter bort. När det ligger vid farthes punkten mittemot oss bakom solen är det 24 minuter bort. Solen under tiden, som vi cirklar, förblir ungefär 8 minuter bort, eftersom vår omlopp runt solen är väldigt nästan cirkulär. En ytterligare anteckning, förutsatt att Mars också är en cirkulär omloppsbana (som det inte är), kan man anta att avståndet från mars till sol är ungefär 12 minuter och innebär att det maximala avståndet skulle vara 8 12 vilket bara skulle vara 20 minuter. Men det här är inte så eftersom Mars-banan är lite eliptisk och i ett något annorlunda plan från jordens omlopp gör det också möjligt för dem att vara så avlägsna som 24 minuter. Kom precis över detta: Radiosignaler är elektromagnetiska vågor, såsom ljus eller röntgen. Hastigheten för elektromagnetiska vågor i vakuum är 300000kmsec (ungefär). För att kunna beräkna klockan med denna hastighet från jord till mars behöver vi veta avståndet. När Mars och Jorden ligger på motsatta sidor av solen är avståndet det största: ungefär 378 miljoner km. Den tid som behövs för en elektromagnetisk våg för att täcka detta avstånd är ungefär: 21 minuter. Närmaste avstånd mellan Mars och Jorden är 78 miljoner km, tiden i det här fallet är: 4.3 min. Så tiden för resa mellan jorden och Mars är mellan 4,3 minuter och 21 minuter, beroende på det faktiska avståndet mellan de två planeterna. Shab, du beräknar som om det är 2D-plan, medan DoctorZuber redan nämnde jorden och marselipsen är av olika plan. Om jorden ligger på ena sidan av solen och mars är på andra sidan, är avståndet från jorden till mars större än från jorden till solen. Verkar ganska rakt framåt. All elektromagnetisk strålning färdas med ljusets hastighet. Gladson är fel. Både jord och mars är i omlopp runt solen. Vi gör resan på 265 jorddagar. Mars kräver 669 jorddagar. Mars betyder orbitalradie till solen är 1,6 gånger jordens. Vi kan vara mycket närmare Mars än solen, eller 2,6 gånger så långt bort, beroende på våra relativa orbitalpositioner. Rundturstiden beror på var jord och mars är i förhållande till solen. Om vi ​​är på vår närmaste punkt till mars är RT transittid 4 minuter. Om vi ​​står på motsatta sidor av solen är RT-tiden 24 minuter. Det varierar, eftersom jorden och Mars kretsar solen med olika hastigheter. Ibland är de på samma sida av solen och vid närmaste tillvägagångssätt tar ljus endast ca 3 minuter att resa mellan de två. Ibland är de på motsatta sidor av solen och det tar upp till ca 22 minuter. När det gäller de andra svaren är skillnaden mellan ljusets ljus och radiovågor försumbar över dessa korta avstånd. Beror på jordens position och Mars. Om vi ​​är på samma sida av solen är vi närmare. Om planeterna ligger på motsatta sidor av solen. Solen är närmare. Solavståndet från jorden är relativt konstant. Mars är inte. Varges, vi är inte nödvändigtvis samma sida av solen samtidigt - så den längsta tiden är för när jorden och Mars är 180 grader motsatta varandra och båda vid aphelion och den kortaste skulle vara när vi båda är samma sida , med Mars vid perihelion och Earth at aphelion .: Nu är det meningsfullt, men hur mycket längre kommer det att ta solens ljus för att nå MarsDigital Kamera Shutter Lag amp Förstärkare Time Shutter Lag - Vad är det En av de mest frustrerande Problem som vissa människor stöter på med digitalkameror är den karaktäristiska som kallas slutartid. Hur många gånger har du väntat på det rätta ögonblicket för att ta ett skott, bara för att spendera nästa sekund och vänta på att kameran tar bilden, om inte alls har ditt perfekta skott försvunnit ur sikte. Detta är slutartid. Tiden från när du trycker på avtryckaren (dvs. avtryckaren) tills kameran faktiskt tar bilden kallas total slutartid. Total slutartid är kombinationen av två processer på jobbet: autofokuslagret och slutartidsfördröjningen. Autofokuslag - Så snart du trycker på slutarknappen försöker kameran generellt att söka efter en lämplig fokuspunkt. Denna autofokusmekanism är ofta mycket långsam och bidrar mest till den totala lagringen. I punkt och skjut kameror fokuseras den fysiska linsen fram och tillbaka med en motor tills kameran bestämmer att fokuseringen är korrekt. Självklart eftersom vi måste vänta på att en motor ska röra sig i båda riktningarna kommer förseningen att vara stor. Med digitala SLR-kameror möjliggör en avancerad stängd kretsstyrkrets en snabb uppskattning av lämpligt fokusavstånd, utan att behöva sakta röra linsen fram och tillbaka. Observera att alla kameror tar längre tid att autofokusera om miljön är mörk eller det fotograferade objektet har dålig kontrast (vilket gör det svårare för kameran att låsa på). Slutarläge - När kameran har bestämt lämpligt fokusavstånd utlöser kameran den elektroniska eller fysiska avstängningsmekanismen. På vissa billigare kameror kan processen ta en måttlig tid, men det är vanligtvis inte så signifikant som autofokuslagret. Utlösningsfördröjningen är den tid det tar att ta bilden om man har quotpre-focusedquot (dvs håller ned slutarknappen halvvägs) eller använd manuellt fokusläge. Totallag - summan av autofokuslag och slutarlagret. Detta är förseningen oftast sett när quotpre-focusingquot inte är gjort, eller i tider när man försöker ta en bild snabbt (dvs utan att ställa in den). Självklart blir ju större den totala fördröjningen för en kamera, desto mer märkbar och frustrerande förseningen blir. Vid inköp av en ny kamera bör man noggrant jämföra skillnaderna i totallagring mellan olika modeller, eftersom vissa kameror är mycket snabbare än andra i detta avseende. Se till att du jämför tid som krävs för att skjuta samma objekt (eftersom olika objekt leder till olika lagringsfördröjningar för autofokus). Jämförelse av slutfördröjningsvärden för slutartidförstärkare i följande tabell är i sekunder. Referenskolonnen kommer att innehålla länkar till källorna för varje datapunkt. Om flera referenser används för data visas medelvärdet tillsammans med intervallet (min-max) inom parentes. Det är mycket viktigt att notera att skillnader i mätmetoder och resultatprecision gör direkta jämförelser svåra. Därför bör jämförelser mellan modeller som utförs av samma källa teoretiskt sett vara rättvisa, medan jämförelser mellan olika källor kan vara mindre korrekta. Fler kameror kommer att läggas över tiden. Observera att det ofta är svårt att testa för slutartid och att det finns viss grad av variation i de läsningar som olika källor kan indikera. Detta är speciellt fallet med totallagring, eftersom det är mycket beroende av linsuppställningen. Därför är det snabbaste mätvärdet inkluderat där mängderna fördröjda totala tester har utförts för en kamera av samma testare. OBS: Alla tider i tabellen nedan är i sekunder (S). Multiplicera med 1000 för att konvertera till millisekunder (mS). Sony Point amp Skjut 9ms slutarlag Ja, som förvånansvärt är det Sony som uppenbarligen har fördröjningsfördröjningar på så lite som 9ms. Detta värde har publicerats på Sony-webbplatsen med flera av deras punkt - och skjutmodeller under Specifikationer. Man bör alltid ta tillverkarens prestationsspecifikationer med saltkorn, men det kan finnas viss sanning till detta som en annan tester (Imaging-Resource) kom upp med samma bild. Det är viktigt att notera att detta är utan autofokus. Med automatisk fokusering i bilden faller den totala fördröjningstiden mer i linje med en typisk PampS-digikam. Källor för digitalkamera-test Följande webbplatser erbjuder detaljerad testning av digitalkameror, inklusive slutartid. Kvaliteten på testen varierar, men testuppsättningarna som används på var och en av följande platser är rimliga för en startpunkt: Läsarnas kommentarer: Vänligen lämna dina kommentarer eller förslag nedanför Johnny V. quotHep Catquot Brennan Good Day Jag hoppas att alla njuter av en trevlig ett. Som Per Commenter Liliken: Vad sägs om fördröjningen mellan att ta bilder som är den frustrerande för mig nu. Jag tar en bild och måste vänta tills kameran blir redo att ta nästa. Hur kallas fördröjningen Tack. Yep Det kan också vara en mycket störande LAG. För ett extremt exempel, ta en 2003 Sony Mavica med mini-CD-RW inuti den för inspelning av foton. Du tar ett foto och enheten måste bearbeta data och sedan skriva den till en mini-CD-RW. Jag är säker på att alla kan föreställa sig hur länge och frustrerande det ögonblicket kan vara. Jag råkar ha en gammal Mavica, tar fortfarande bra bilder, men nu förvandlas den till nödanvändning och konversationsbit, eftersom den verkliga Totallag är mord. Jag skulle kalla numret som nämns här: Process Lag. och jag tror att antalet för processlagret ska inkluderas med totallagret. Eftersom THATS Theee Number som verkligen orsakar ALLA Frustrationen Tryck på knappen - Vänta för fokus - Slutarutlösning - Vänta för bearbetning - Upprepa. Under tiden försvinner ögonblicken och skotten i historia för evighet. aldrig ses igen. Jag tror inte att tillverkarna kommer att göra dessa nummer lättillgängliga. Det verkar som att det är upp till En att göra omfattande forskning och bläddra i många webbplatser och forum för data. men som det ses här. det är svårt att hitta en komplett lista. Jag har hittat några data om SnapSort och (tro det eller inte) BestBuy. BestBuy har en av de bästa digitalkamera jämförelsekartorna som jag hittat än. Det har en fin storlek av filtren för att hitta en grupp kameror att jämföra. Kontrollera sedan kamerorna du vill jämföra, upp till 4 eller 5, och klicka sedan på Jämför och du får Specs för varje kamera, sida vid sida för Easy Comparison. För Instance: Jag filtrerade Samsung, Lågljuskänslighet, Burst Mode, upp till 200, WiFi. har en lista över kameror. jämfört 2. valde en Samsung WB350F. Boom Ease-as-Peas Good Luck Glad PhotoBugging Njut av alla goda noteringar. Några detaljer som finns tillgängliga på Nikon D7000 Har någon gjort något arbete på lagret i samband med direktutlösning av blixtenheter Hej Tack så mycket för denna utmärkta information Mycket användbar och välskriven. Vi letar efter en ny kamera. Vi hade två SONY Cybershot upp till kwow (inte så bra när det gäller pre-fokusering och slutarlag). Vi överväger att köpa en SONY HX 300 eller en NIKON P520. Vad sägs om dem om totallagring Tack i förväg för all information eller åsikt du kanske har. Jag har tittat på ditt diagram och siffrorna överensstämmer inte med verkligheten vid sida vid sida. Exempelvis visar ditt diagram att Canon 10D, 20D och Rebel XT har snabbare total slutartid än ett ID Mark II. Jag har en Canon 10D, 20D och 1D Mark II och jag kan försäkra dig om att det finns en värld av skillnad, med 1D Mark II som är imponerande snabbare än någon av dessa kameror. Jag tittade på dina referenser på vissa kameror och ser till att du använde data från bildhanteringsresurs, och när du tittar på dataen verkar beskrivningen rimlig, data måste faktiskt vara felaktigt. En möjlighet är att linsen som används i testen (inte en L-lins) är en begränsande faktor, inte kameran. Exempel: 1D Mark II är förbluffande snabbt jämfört med 10D med samma linser på samma ämne (jämför flera linser). För närvarande gör jag djurlivsfotografering med en 1D Mark II med en 10D som backup, ofta byter linser (t ex 500 mm f L IS på ett stativ och 300 mm f4 L IS handhållen). För att betygsätta 10D-totalvikten vid 0,189 sekunder och 1D Mark II vid 0.235 sekunder är helt enkelt fel, om du inte sätter den snabbaste autofokuseringslinsen på 10D och den långsammaste linsen på 1D Mark II. Jag spelar en hel del djurlivsåtgärder, och svarstiden på 1D Mark II är väl under 0,1 sekund (total fördröjningstid i min erfarenhet vid flera fotograferingsförhållanden). 10D känns som en långsam punkt och skjuter i jämförelse. I verkliga förhållanden skulle jag ha två problem med 10D: 1) oregelbunden åtgärd (t. ex. fågel i flygning) med komplex bakgrund (t. ex. avlägsna träd) har problem att låsa på ämnet och inte bakgrunden, och 2) medan spårning ett motiv, om fokuspunkten flyttas från motivet (t. ex. på grund av min oförmåga att spåra ojämn rörelse), skulle kameran aldrig återfå fokus tills motivet stannat. På 1D Mark II har jag inte dessa problem. Rapporter från människor i fältet säger att 20D har samma problem som 10D. Men med 1D Mark II, kan jag förlora och återfatta fokuspunkten på ett rörligt ämne i det som verkar som långt under 0,1 sekund. Fokusnoggrannheten är också mycket bättre på 1DII (med mer än 50 out of focus action shots på 10D, nästan allt i bra fokus med 1DII) med typiska stora fåglar under flygning (t ex örnar, kranar, öron). Så, ditt bord impulseadventurephotoshutter-lag. html är mycket misstänkt, oavsett källan till data. Roger (Foton på: clarkvision) Hej Roger - Tack för lite utmärkt inblick i prestanda utanför vad numren tycks innebära. Jag tror att den enda rättvisa mätningen för jämförelseändamål kan vara slutartiden. inte total fördröjning som härledd från ett genomsnitt av testresultat. Detta är anledningen till att jag listar de resulterande lägre och övre gränserna tillsammans med medelvärdet för att visa avvikelsen. Inklusive autofokus i den totala fördröjningstiden är mycket beroende av AF-läge, objektivval och scenkontrast som du med rätta påpekar. Du noterar att översynswebbplatser (3 av dem, inte bara avbildningsresurs) alla gav mätningar i intervallet 230 till 240 ms för Canon 1d Mk II. Du kan dock se att resultaten för 10D och 20D har en mycket bredare spridning, från 146 upp till 240 ms listade för Canon 1D mk II. Så, medan genomsnittet kan visa som 189, kan det rättvisa jämförelsevärdet vara 240 ms (identiskt med Canon 1D mkII). Jag är inte nödvändigtvis överens om att siffrorna är felaktiga. Att ta de största totala fördröjningstiderna i jämförelsen skulle ge liknande resultat, men de är sannolikt fångade i en mycket syntetisk inställning (statiskt högt kontrastmål i en väl upplyst miljö). Naturligtvis kommer din verkliga erfarenhet att lyfta fram svagheten i autofokuserna 10D och 20D, där rörelsespårspårning och låga kontrastförhållanden verkligen kan försämra 10D eller 20Ds bästa fallprestanda. Med detta sagt är slutartiden faktiskt rapporterad som betydligt snabbare på 1d Mark II jämfört med de andra proffskamerorna. Helst skulle vi ha en objektiv, reproducerbar jämförelse av totala slutarlagrar med samma inställning och lins, men med typiska verkliga scenarier Men det här ligger utanför ramen för inställningen för de flesta kameranalysatorer. De skulle behöva en mekaniserad rigg som skulle kunna reproducera rörelsen, med någon digital räknare i bildscenen (för att bedöma den verkliga fördröjningen exakt) och en fjärrutlösare. Om någon ställer upp det för de flesta av de stora dSLR-skivorna och med jämförbara linser (t. ex. L på Canon), skulle det vara fantastiskt. Tyvärr tycker jag väl att jag måste göra en provtagning av resultat från olika granskare, alla med lite varierande inställningar. Förhoppningen är att med tillräckliga recensioner och resultat kommer medelvärdena att vara användbara som en grov utgångspunkt för jämförelse. Återigen, tack så mycket för att ge en verklig inblick i det prestanda du har observerat mellan kamerorna. Denna återkoppling är ofta mycket mer användbar än en annan syntetisk datapunkt. Stort galleri, BTW Ett mans professionellt hårt arbete drar fördelar miljoner män och kvinnor. Tack Även kan någon vänligen meddela vilken som är snabb inom ett prisklass på U300. Jag behöver en snabb kamera för att filma mina två hyperaktiva småbarn. Diagrammet kan vara perfekt om det har en annan kolumn som visar priser. Tack, Robin Tyvärr kan jag inte lägga till priser eftersom jag aldrig skulle kunna hålla diagrammet uppdaterat med alla avvikelser i gatupriserna över tiden. Användning av R för tidsserieanalys Tidsserieanalys Den här häftet beskriver hur du använd R statistikprogrammet för att utföra några enkla analyser som är vanliga vid analys av tidsseriedata. Detta häfte förutsätter att läsaren har viss grundläggande kunskaper om tidsserieanalys och huvudboken för häftet är inte att förklara tidsserieanalys utan snarare att förklara hur man utför dessa analyser med R. Om du är ny på tidsserier analys, och vill lära mig mer om några av de begrepp som presenteras här, rekommenderar jag starkt Open University-boken 8220Time series8221 (produktkod M24902), tillgänglig från Open University Shop. I det här häftet använder jag tidsseriedatasatser som Rob Hyndman vänligen gjort tillgängligt i sitt tidsseriedatabibliotek på robjhyndmanTSDL. Om du gillar det här häftet kan du också kolla in min broschyr på att använda R för biomedicinsk statistik, lite-book-of-r-for-biomedical-statistics. readthedocs. org. och min broschyr om att använda R för multivariat analys, little-book-of-r-for-multivariate-analysis. readthedocs. org. Läsningstidsseriedata Det första du vill göra för att analysera dina tidsseriedata kommer att vara att läsa in det i R och att plotta tidsserien. Du kan läsa data i R med funktionen scan (), vilket förutsätter att dina data för successiva tidpunkter ligger i en enkel textfil med en kolumn. Till exempel innehåller filen robjhyndmantsdldatamisckings. dat data om dödsåldern hos de på varandra följande kungarna i England, från och med William the Conqueror (originalkälla: Hipel och Mcleod, 1994). Datasatsen ser så här ut: Endast de första linjerna i filen har visats. De tre första raderna innehåller en del kommentarer på data, och vi vill ignorera detta när vi läser in data i R. Vi kan använda detta genom att använda 8220skip8221-parametern i funktionen scan (), som anger hur många rader överst på filen att ignorera. För att läsa filen i R, ignorerar de tre första raderna, skriver vi: I detta fall har dödsåldern på 42 på varandra följande kungar i England lästs in i variabeln 8216kings8217. När du har läst tidsseriedata till R, är nästa steg att lagra data i ett tidsserieobjekt i R, så att du kan använda R8217s många funktioner för att analysera tidsseriedata. För att lagra data i ett tidsseriensobjekt använder vi funktionen ts () i R. Till exempel, för att lagra data i variabeln 8216kings8217 som ett tidsserieobjekt i R, skriver vi: Ibland anger tidsseriedata som du har kanske samlats in med jämna mellanrum som var mindre än ett år, till exempel månadsvis eller kvartalsvis. I det här fallet kan du ange hur många gånger data samlades per år genom att använda parametern 8216frequency8217 i funktionen ts (). För månatliga tidsseriedata ställer du in frekvens12 medan du anger kvartalsvisa tidsseriedata, frequency4. Du kan också ange det första året som data samlades in och det första intervallet i det året genom att använda parametern 8216start8217 i funktionen ts (). Om till exempel den första datapunkten motsvarar andra kvartalet 1986 skulle du ställa in startc (1986,2). Ett exempel är en datamängd av antalet födelser per månad i New York City, från januari 1946 till december 1959 (ursprungligen samlad av Newton). Denna data är tillgänglig i filen robjhyndmantsdldatadatanybirths. dat Vi kan läsa in data i R, och lagra den som ett tidsserieobjekt, genom att skriva: På samma sätt innehåller filen robjhyndmantsdldatadatafancy. dat månadsförsäljning till en souvenirbutik på en strandortstad i Queensland, Australien, för januari 1987-december 1993 (ursprungliga data från Wheelwright och Hyndman, 1998). Vi kan läsa in data i R genom att skriva: Plotting Time Series När du har läst en tidsserie i R, är det vanligtvis nästa steg att göra en plot av tidsseriedata som du kan göra med funktionen plot. ts () i R. Till exempel, för att plotta tidsserierna för dödsåldern på 42 på varandra följande kungar i England skriver vi: Vi kan se från tidsplanen att denna tidsserie troligen kunde beskrivas med hjälp av en tillsatsmodell, eftersom de slumpmässiga fluktuationerna i data är ungefär konstant i storlek över tiden. På samma sätt, för att plotta tidsserien för antalet födelser per månad i New York City, skriver vi: Vi kan se från denna tidsserie att det verkar finnas säsongsvariationer i antalet födelser per månad: det är en topp varje sommar , och ett tråg varje vinter. Återigen verkar det som om denna tidsserie troligtvis skulle kunna beskrivas med hjälp av en tillsatsmodell, eftersom säsongsvariationerna är ungefär konstanta i storlek över tiden och verkar inte bero på tidssekvensens nivå och de slumpmässiga fluktuationerna verkar också vara ungefär konstant i storlek över tiden. På samma sätt, för att plotta tidsserierna för den månatliga försäljningen för souvenirbutiken vid en strandortsstad i Queensland, Australien, skriver vi: I detta fall verkar det som om en tillsatsmodell inte är lämplig för att beskriva denna tidsserie, eftersom storleken av säsongsvariationerna och slumpmässiga fluktuationer tycks öka med nivån på tidsserierna. Således kan vi behöva omvandla tidsserierna för att få en transformerad tidsserie som kan beskrivas med hjälp av en tillsatsmodell. Till exempel kan vi omvandla tidsserierna genom att beräkna den naturliga loggen för de ursprungliga data: Här kan vi se att storleken på säsongsvariationerna och slumpmässiga fluktuationer i de loggformade tidsserierna verkar vara ungefär konstanta över tiden och göra inte beroende av tidsserien. Således kan den log-transformerade tidsserien förmodligen beskrivas med användning av en tillsatsmodell. Decomposing Time Series Nedbrytning av en tidsserie innebär att den separeras i dess ingående komponenter, som vanligen är en trendkomponent och en oregelbunden komponent, och om det är en säsongsbetonad tidsserie, en säsongsbeständig komponent. Nedbrytning av icke-säsongsdata En tidsserier utan säsong består av en trendkomponent och en oregelbunden komponent. Nedbrytning av tidsserien innebär att man försöker skilja tidsserierna i dessa komponenter, det vill säga att uppskatta trendkomponenten och den oregelbundna komponenten. För att uppskatta trendkomponenten i en icke-säsongsbetonad tidsserie som kan beskrivas med hjälp av en additivmodell, är det vanligt att använda en utjämningsmetod, såsom att beräkna det enkla glidande mediet av tidsserierna. Funktionen SMA () i 8220TTR8221 R-paketet kan användas för att släta tidsseriedata med ett enkelt glidande medelvärde. För att kunna använda denna funktion måste vi först installera 8220TTR8221 R-paketet (för instruktioner om hur man installerar ett R-paket, se Så här installerar du ett R-paket). När du har installerat 8220TTR8221 R-paketet kan du ladda 8220TTR8221 R-paketet genom att skriva: Du kan då använda 8220SMA () 8221-funktionen för att släta tidsseriedata. För att använda SMA () - funktionen måste du ange ordningen (span) för det enkla glidande medlet, med parametern 8220n8221. Till exempel, för att beräkna ett enkelt glidande medelvärde av ordning 5, ställer vi n5 i SMA () - funktionen. Exempelvis, som diskuterad ovan, framgår tidsserierna för dödsåldern för 42 på varandra följande kungar i England, som inte är säsongsbetonade, och kan förmodligen beskrivas med hjälp av en tillsatsmodell, eftersom de slumpmässiga fluktuationerna i data är ungefär konstant i storlek över tid: Således kan vi försöka uppskatta trendkomponenten i denna tidsserie genom utjämning med ett enkelt glidande medelvärde. För att släta tidsserierna med hjälp av ett enkelt rörligt medelvärde av ordning 3, och rita data för glatt tidsserie, skriver vi: Det verkar fortfarande finnas ganska många slumpmässiga fluktuationer i tidsserierna släta med ett enkelt glidande medelvärde av order 3. Således, för att uppskatta trendkomponenten mer noggrant, kan vi kanske försöka utjämna data med ett enkelt glidande medelvärde av en högre order. Det tar lite försök och fel, för att hitta rätt mängd utjämning. Till exempel kan vi försöka använda ett enkelt glidande medelvärde av order 8: Datan jämnas med ett enkelt glidande medelvärde av order 8 ger en tydligare bild av trendkomponenten och vi kan se att Engelska kungens död verkar har minskat från ca 55 år till ca 38 år under regeringens första 20 kungar, och sedan ökat efter det till cirka 73 år vid slutet av regeringens 40-talets regeringstid i tidsserierna. Dekomponering av säsongsdata En säsongsbetonad tidsserie består av en trendkomponent, en säsongsbetonad komponent och en oregelbunden komponent. Nedbrytning av tidsserien innebär att tidsserierna separeras i dessa tre komponenter: det vill säga uppskattning av dessa tre komponenter. För att uppskatta trendkomponenten och säsongskomponenten i en säsongsbetonad tidsserie som kan beskrivas med hjälp av en additivmodell, kan vi använda funktionen 8220decompose () 8221 i R. Denna funktion uppskattar trend, säsong och oregelbundna komponenter i en tidsserie som kan beskrivas med hjälp av en tillsatsmodell. Funktionen 8220decompose () 8221 returnerar ett listobjekt som ett resultat där uppskattningarna av säsongskomponenten, trendkomponenten och den oregelbundna komponenten lagras i namngivna element i listobjekten, som kallas 8220seasonal8221, 8220trend8221 respektive 8220random8221. Exempelvis är tidsserierna för antalet födelser per månad i New York City säsongsmässigt med en topp varje sommar och genom varje vinter och kan förmodligen beskrivas med hjälp av en tillsatsmodell, eftersom säsongs - och slumpmässiga fluktuationer tycks vara vara ungefär konstant i storlek över tiden: För att uppskatta trend, säsongsmässiga och oregelbundna komponenter i denna tidsserie skriver vi: De uppskattade värdena för säsongs-, trend - och oregelbundna komponenter lagras nu i variabler födelsestidereriescomponentsseasonal, birthstimeseriescomponentstrend och birthstimeseriescomponentsrandom. For example, we can print out the estimated values of the seasonal component by typing: The estimated seasonal factors are given for the months January-December, and are the same for each year. The largest seasonal factor is for July (about 1.46), and the lowest is for February (about -2.08), indicating that there seems to be a peak in births in July and a trough in births in February each year. We can plot the estimated trend, seasonal, and irregular components of the time series by using the 8220plot()8221 function, for example: The plot above shows the original time series (top), the estimated trend component (second from top), the estimated seasonal component (third from top), and the estimated irregular component (bottom). We see that the estimated trend component shows a small decrease from about 24 in 1947 to about 22 in 1948, followed by a steady increase from then on to about 27 in 1959. Seasonally Adjusting If you have a seasonal time series that can be described using an additive model, you can seasonally adjust the time series by estimating the seasonal component, and subtracting the estimated seasonal component from the original time series. We can do this using the estimate of the seasonal component calculated by the 8220decompose()8221 function. For example, to seasonally adjust the time series of the number of births per month in New York city, we can estimate the seasonal component using 8220decompose()8221, and then subtract the seasonal component from the original time series: We can then plot the seasonally adjusted time series using the 8220plot()8221 function, by typing: You can see that the seasonal variation has been removed from the seasonally adjusted time series. The seasonally adjusted time series now just contains the trend component and an irregular component. Forecasts using Exponential Smoothing Exponential smoothing can be used to make short-term forecasts for time series data. Simple Exponential Smoothing If you have a time series that can be described using an additive model with constant level and no seasonality, you can use simple exponential smoothing to make short-term forecasts. The simple exponential smoothing method provides a way of estimating the level at the current time point. Smoothing is controlled by the parameter alpha for the estimate of the level at the current time point. The value of alpha lies between 0 and 1. Values of alpha that are close to 0 mean that little weight is placed on the most recent observations when making forecasts of future values. For example, the file robjhyndmantsdldatahurstprecip1.dat contains total annual rainfall in inches for London, from 1813-1912 (original data from Hipel and McLeod, 1994). We can read the data into R and plot it by typing: You can see from the plot that there is roughly constant level (the mean stays constant at about 25 inches). The random fluctuations in the time series seem to be roughly constant in size over time, so it is probably appropriate to describe the data using an additive model. Thus, we can make forecasts using simple exponential smoothing. To make forecasts using simple exponential smoothing in R, we can fit a simple exponential smoothing predictive model using the 8220HoltWinters()8221 function in R. To use HoltWinters() for simple exponential smoothing, we need to set the parameters betaFALSE and gammaFALSE in the HoltWinters() function (the beta and gamma parameters are used for Holt8217s exponential smoothing, or Holt-Winters exponential smoothing, as described below). The HoltWinters() function returns a list variable, that contains several named elements. For example, to use simple exponential smoothing to make forecasts for the time series of annual rainfall in London, we type: The output of HoltWinters() tells us that the estimated value of the alpha parameter is about 0.024. This is very close to zero, telling us that the forecasts are based on both recent and less recent observations (although somewhat more weight is placed on recent observations). By default, HoltWinters() just makes forecasts for the same time period covered by our original time series. In this case, our original time series included rainfall for London from 1813-1912, so the forecasts are also for 1813-1912. In the example above, we have stored the output of the HoltWinters() function in the list variable 8220rainseriesforecasts8221. The forecasts made by HoltWinters() are stored in a named element of this list variable called 8220fitted8221, so we can get their values by typing: We can plot the original time series against the forecasts by typing: The plot shows the original time series in black, and the forecasts as a red line. The time series of forecasts is much smoother than the time series of the original data here. As a measure of the accuracy of the forecasts, we can calculate the sum of squared errors for the in-sample forecast errors, that is, the forecast errors for the time period covered by our original time series. The sum-of-squared-errors is stored in a named element of the list variable 8220rainseriesforecasts8221 called 8220SSE8221, so we can get its value by typing: That is, here the sum-of-squared-errors is 1828.855. It is common in simple exponential smoothing to use the first value in the time series as the initial value for the level. For example, in the time series for rainfall in London, the first value is 23.56 (inches) for rainfall in 1813. You can specify the initial value for the level in the HoltWinters() function by using the 8220l. start8221 parameter. For example, to make forecasts with the initial value of the level set to 23.56, we type: As explained above, by default HoltWinters() just makes forecasts for the time period covered by the original data, which is 1813-1912 for the rainfall time series. We can make forecasts for further time points by using the 8220forecast. HoltWinters()8221 function in the R 8220forecast8221 package. To use the forecast. HoltWinters() function, we first need to install the 8220forecast8221 R package (for instructions on how to install an R package, see How to install an R package ). Once you have installed the 8220forecast8221 R package, you can load the 8220forecast8221 R package by typing: When using the forecast. HoltWinters() function, as its first argument (input), you pass it the predictive model that you have already fitted using the HoltWinters() function. For example, in the case of the rainfall time series, we stored the predictive model made using HoltWinters() in the variable 8220rainseriesforecasts8221. You specify how many further time points you want to make forecasts for by using the 8220h8221 parameter in forecast. HoltWinters(). For example, to make a forecast of rainfall for the years 1814-1820 (8 more years) using forecast. HoltWinters(), we type: The forecast. HoltWinters() function gives you the forecast for a year, a 80 prediction interval for the forecast, and a 95 prediction interval for the forecast. For example, the forecasted rainfall for 1920 is about 24.68 inches, with a 95 prediction interval of (16.24, 33.11). To plot the predictions made by forecast. HoltWinters(), we can use the 8220plot. forecast()8221 function: Here the forecasts for 1913-1920 are plotted as a blue line, the 80 prediction interval as an orange shaded area, and the 95 prediction interval as a yellow shaded area. The 8216forecast errors8217 are calculated as the observed values minus predicted values, for each time point. We can only calculate the forecast errors for the time period covered by our original time series, which is 1813-1912 for the rainfall data. As mentioned above, one measure of the accuracy of the predictive model is the sum-of-squared-errors (SSE) for the in-sample forecast errors. The in-sample forecast errors are stored in the named element 8220residuals8221 of the list variable returned by forecast. HoltWinters(). If the predictive model cannot be improved upon, there should be no correlations between forecast errors for successive predictions. In other words, if there are correlations between forecast errors for successive predictions, it is likely that the simple exponential smoothing forecasts could be improved upon by another forecasting technique. To figure out whether this is the case, we can obtain a correlogram of the in-sample forecast errors for lags 1-20. We can calculate a correlogram of the forecast errors using the 8220acf()8221 function in R. To specify the maximum lag that we want to look at, we use the 8220lag. max8221 parameter in acf(). For example, to calculate a correlogram of the in-sample forecast errors for the London rainfall data for lags 1-20, we type: You can see from the sample correlogram that the autocorrelation at lag 3 is just touching the significance bounds. To test whether there is significant evidence for non-zero correlations at lags 1-20, we can carry out a Ljung-Box test. This can be done in R using the 8220Box. test()8221, function. The maximum lag that we want to look at is specified using the 8220lag8221 parameter in the Box. test() function. For example, to test whether there are non-zero autocorrelations at lags 1-20, for the in-sample forecast errors for London rainfall data, we type: Here the Ljung-Box test statistic is 17.4, and the p-value is 0.6, so there is little evidence of non-zero autocorrelations in the in-sample forecast errors at lags 1-20. To be sure that the predictive model cannot be improved upon, it is also a good idea to check whether the forecast errors are normally distributed with mean zero and constant variance. To check whether the forecast errors have constant variance, we can make a time plot of the in-sample forecast errors: The plot shows that the in-sample forecast errors seem to have roughly constant variance over time, although the size of the fluctuations in the start of the time series (1820-1830) may be slightly less than that at later dates (eg. 1840-1850). To check whether the forecast errors are normally distributed with mean zero, we can plot a histogram of the forecast errors, with an overlaid normal curve that has mean zero and the same standard deviation as the distribution of forecast errors. To do this, we can define an R function 8220plotForecastErrors()8221, below: You will have to copy the function above into R in order to use it. You can then use plotForecastErrors() to plot a histogram (with overlaid normal curve) of the forecast errors for the rainfall predictions: The plot shows that the distribution of forecast errors is roughly centred on zero, and is more or less normally distributed, although it seems to be slightly skewed to the right compared to a normal curve. However, the right skew is relatively small, and so it is plausible that the forecast errors are normally distributed with mean zero. The Ljung-Box test showed that there is little evidence of non-zero autocorrelations in the in-sample forecast errors, and the distribution of forecast errors seems to be normally distributed with mean zero. This suggests that the simple exponential smoothing method provides an adequate predictive model for London rainfall, which probably cannot be improved upon. Furthermore, the assumptions that the 80 and 95 predictions intervals were based upon (that there are no autocorrelations in the forecast errors, and the forecast errors are normally distributed with mean zero and constant variance) are probably valid. Holt8217s Exponential Smoothing If you have a time series that can be described using an additive model with increasing or decreasing trend and no seasonality, you can use Holt8217s exponential smoothing to make short-term forecasts. Holt8217s exponential smoothing estimates the level and slope at the current time point. Smoothing is controlled by two parameters, alpha, for the estimate of the level at the current time point, and beta for the estimate of the slope b of the trend component at the current time point. As with simple exponential smoothing, the paramters alpha and beta have values between 0 and 1, and values that are close to 0 mean that little weight is placed on the most recent observations when making forecasts of future values. An example of a time series that can probably be described using an additive model with a trend and no seasonality is the time series of the annual diameter of women8217s skirts at the hem, from 1866 to 1911. The data is available in the file robjhyndmantsdldatarobertsskirts. dat (original data from Hipel and McLeod, 1994). We can read in and plot the data in R by typing: We can see from the plot that there was an increase in hem diameter from about 600 in 1866 to about 1050 in 1880, and that afterwards the hem diameter decreased to about 520 in 1911. To make forecasts, we can fit a predictive model using the HoltWinters() function in R. To use HoltWinters() for Holt8217s exponential smoothing, we need to set the parameter gammaFALSE (the gamma parameter is used for Holt-Winters exponential smoothing, as described below). For example, to use Holt8217s exponential smoothing to fit a predictive model for skirt hem diameter, we type: The estimated value of alpha is 0.84, and of beta is 1.00. These are both high, telling us that both the estimate of the current value of the level, and of the slope b of the trend component, are based mostly upon very recent observations in the time series. This makes good intuitive sense, since the level and the slope of the time series both change quite a lot over time. The value of the sum-of-squared-errors for the in-sample forecast errors is 16954. We can plot the original time series as a black line, with the forecasted values as a red line on top of that, by typing: We can see from the picture that the in-sample forecasts agree pretty well with the observed values, although they tend to lag behind the observed values a little bit. If you wish, you can specify the initial values of the level and the slope b of the trend component by using the 8220l. start8221 and 8220b. start8221 arguments for the HoltWinters() function. It is common to set the initial value of the level to the first value in the time series (608 for the skirts data), and the initial value of the slope to the second value minus the first value (9 for the skirts data). For example, to fit a predictive model to the skirt hem data using Holt8217s exponential smoothing, with initial values of 608 for the level and 9 for the slope b of the trend component, we type: As for simple exponential smoothing, we can make forecasts for future times not covered by the original time series by using the forecast. HoltWinters() function in the 8220forecast8221 package. For example, our time series data for skirt hems was for 1866 to 1911, so we can make predictions for 1912 to 1930 (19 more data points), and plot them, by typing: The forecasts are shown as a blue line, with the 80 prediction intervals as an orange shaded area, and the 95 prediction intervals as a yellow shaded area. As for simple exponential smoothing, we can check whether the predictive model could be improved upon by checking whether the in-sample forecast errors show non-zero autocorrelations at lags 1-20. For example, for the skirt hem data, we can make a correlogram, and carry out the Ljung-Box test, by typing: Here the correlogram shows that the sample autocorrelation for the in-sample forecast errors at lag 5 exceeds the significance bounds. However, we would expect one in 20 of the autocorrelations for the first twenty lags to exceed the 95 significance bounds by chance alone. Indeed, when we carry out the Ljung-Box test, the p-value is 0.47, indicating that there is little evidence of non-zero autocorrelations in the in-sample forecast errors at lags 1-20. As for simple exponential smoothing, we should also check that the forecast errors have constant variance over time, and are normally distributed with mean zero. We can do this by making a time plot of forecast errors, and a histogram of the distribution of forecast errors with an overlaid normal curve: The time plot of forecast errors shows that the forecast errors have roughly constant variance over time. The histogram of forecast errors show that it is plausible that the forecast errors are normally distributed with mean zero and constant variance. Thus, the Ljung-Box test shows that there is little evidence of autocorrelations in the forecast errors, while the time plot and histogram of forecast errors show that it is plausible that the forecast errors are normally distributed with mean zero and constant variance. Therefore, we can conclude that Holt8217s exponential smoothing provides an adequate predictive model for skirt hem diameters, which probably cannot be improved upon. In addition, it means that the assumptions that the 80 and 95 predictions intervals were based upon are probably valid. Holt-Winters Exponential Smoothing If you have a time series that can be described using an additive model with increasing or decreasing trend and seasonality, you can use Holt-Winters exponential smoothing to make short-term forecasts. Holt-Winters exponential smoothing estimates the level, slope and seasonal component at the current time point. Smoothing is controlled by three parameters: alpha, beta, and gamma, for the estimates of the level, slope b of the trend component, and the seasonal component, respectively, at the current time point. The parameters alpha, beta and gamma all have values between 0 and 1, and values that are close to 0 mean that relatively little weight is placed on the most recent observations when making forecasts of future values. An example of a time series that can probably be described using an additive model with a trend and seasonality is the time series of the log of monthly sales for the souvenir shop at a beach resort town in Queensland, Australia (discussed above): To make forecasts, we can fit a predictive model using the HoltWinters() function. For example, to fit a predictive model for the log of the monthly sales in the souvenir shop, we type: The estimated values of alpha, beta and gamma are 0.41, 0.00, and 0.96, respectively. The value of alpha (0.41) is relatively low, indicating that the estimate of the level at the current time point is based upon both recent observations and some observations in the more distant past. The value of beta is 0.00, indicating that the estimate of the slope b of the trend component is not updated over the time series, and instead is set equal to its initial value. This makes good intuitive sense, as the level changes quite a bit over the time series, but the slope b of the trend component remains roughly the same. In contrast, the value of gamma (0.96) is high, indicating that the estimate of the seasonal component at the current time point is just based upon very recent observations. As for simple exponential smoothing and Holt8217s exponential smoothing, we can plot the original time series as a black line, with the forecasted values as a red line on top of that: We see from the plot that the Holt-Winters exponential method is very successful in predicting the seasonal peaks, which occur roughly in November every year. To make forecasts for future times not included in the original time series, we use the 8220forecast. HoltWinters()8221 function in the 8220forecast8221 package. For example, the original data for the souvenir sales is from January 1987 to December 1993. If we wanted to make forecasts for January 1994 to December 1998 (48 more months), and plot the forecasts, we would type: The forecasts are shown as a blue line, and the orange and yellow shaded areas show 80 and 95 prediction intervals, respectively. We can investigate whether the predictive model can be improved upon by checking whether the in-sample forecast errors show non-zero autocorrelations at lags 1-20, by making a correlogram and carrying out the Ljung-Box test: The correlogram shows that the autocorrelations for the in-sample forecast errors do not exceed the significance bounds for lags 1-20. Furthermore, the p-value for Ljung-Box test is 0.6, indicating that there is little evidence of non-zero autocorrelations at lags 1-20. We can check whether the forecast errors have constant variance over time, and are normally distributed with mean zero, by making a time plot of the forecast errors and a histogram (with overlaid normal curve): From the time plot, it appears plausible that the forecast errors have constant variance over time. From the histogram of forecast errors, it seems plausible that the forecast errors are normally distributed with mean zero. 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 uk

Comments