This question already has an answer here:
Command Lines error in Rstudio console
(1 answer)
Closed 2 years ago.
I would like to use a very long vector in R, but it seems that when I create a vector, the maximum length/number of values in the vector is 349. See below for code for vector1 and vector2. I can create vector1 with 349 values without a problem, but vector2, which contains 350 values, throws + on the next line, as if I forgot to use a closing " or ).
I read this post:
Max Length for a Vector in R, but that is completely different from my experience.
Am I missing something? Can anyone help, please?
Code
vector1 <- c("value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9", "value10", "value11", "value12", "value13", "value14", "value15", "value16", "value17", "value18", "value19", "value20", "value21", "value22", "value23", "value24", "value25", "value26", "value27", "value28", "value29", "value30", "value31", "value32", "value33", "value34", "value35", "value36", "value37", "value38", "value39", "value40", "value41", "value42", "value43", "value44", "value45", "value46", "value47", "value48", "value49", "value50", "value51", "value52", "value53", "value54", "value55", "value56", "value57", "value58", "value59", "value60", "value61", "value62", "value63", "value64", "value65", "value66", "value67", "value68", "value69", "value70", "value71", "value72", "value73", "value74", "value75", "value76", "value77", "value78", "value79", "value80", "value81", "value82", "value83", "value84", "value85", "value86", "value87", "value88", "value89", "value90", "value91", "value92", "value93", "value94", "value95", "value96", "value97", "value98", "value99", "value100", "value101", "value102", "value103", "value104", "value105", "value106", "value107", "value108", "value109", "value110", "value111", "value112", "value113", "value114", "value115", "value116", "value117", "value118", "value119", "value120", "value121", "value122", "value123", "value124", "value125", "value126", "value127", "value128", "value129", "value130", "value131", "value132", "value133", "value134", "value135", "value136", "value137", "value138", "value139", "value140", "value141", "value142", "value143", "value144", "value145", "value146", "value147", "value148", "value149", "value150", "value151", "value152", "value153", "value154", "value155", "value156", "value157", "value158", "value159", "value160", "value161", "value162", "value163", "value164", "value165", "value166", "value167", "value168", "value169", "value170", "value171", "value172", "value173", "value174", "value175", "value176", "value177", "value178", "value179", "value180", "value181", "value182", "value183", "value184", "value185", "value186", "value187", "value188", "value189", "value190", "value191", "value192", "value193", "value194", "value195", "value196", "value197", "value198", "value199", "value200", "value201", "value202", "value203", "value204", "value205", "value206", "value207", "value208", "value209", "value210", "value211", "value212", "value213", "value214", "value215", "value216", "value217", "value218", "value219", "value220", "value221", "value222", "value223", "value224", "value225", "value226", "value227", "value228", "value229", "value230", "value231", "value232", "value233", "value234", "value235", "value236", "value237", "value238", "value239", "value240", "value241", "value242", "value243", "value244", "value245", "value246", "value247", "value248", "value249", "value250", "value251", "value252", "value253", "value254", "value255", "value256", "value257", "value258", "value259", "value260", "value261", "value262", "value263", "value264", "value265", "value266", "value267", "value268", "value269", "value270", "value271", "value272", "value273", "value274", "value275", "value276", "value277", "value278", "value279", "value280", "value281", "value282", "value283", "value284", "value285", "value286", "value287", "value288", "value289", "value290", "value291", "value292", "value293", "value294", "value295", "value296", "value297", "value298", "value299", "value300", "value301", "value302", "value303", "value304", "value305", "value306", "value307", "value308", "value309", "value310", "value311", "value312", "value313", "value314", "value315", "value316", "value317", "value318", "value319", "value320", "value321", "value322", "value323", "value324", "value325", "value326", "value327", "value328", "value329", "value330", "value331", "value332", "value333", "value334", "value335", "value336", "value337", "value338", "value339", "value340", "value341", "value342", "value343", "value344", "value345", "value346", "value347", "value348", "value349")
vector2 <- c("value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9", "value10", "value11", "value12", "value13", "value14", "value15", "value16", "value17", "value18", "value19", "value20", "value21", "value22", "value23", "value24", "value25", "value26", "value27", "value28", "value29", "value30", "value31", "value32", "value33", "value34", "value35", "value36", "value37", "value38", "value39", "value40", "value41", "value42", "value43", "value44", "value45", "value46", "value47", "value48", "value49", "value50", "value51", "value52", "value53", "value54", "value55", "value56", "value57", "value58", "value59", "value60", "value61", "value62", "value63", "value64", "value65", "value66", "value67", "value68", "value69", "value70", "value71", "value72", "value73", "value74", "value75", "value76", "value77", "value78", "value79", "value80", "value81", "value82", "value83", "value84", "value85", "value86", "value87", "value88", "value89", "value90", "value91", "value92", "value93", "value94", "value95", "value96", "value97", "value98", "value99", "value100", "value101", "value102", "value103", "value104", "value105", "value106", "value107", "value108", "value109", "value110", "value111", "value112", "value113", "value114", "value115", "value116", "value117", "value118", "value119", "value120", "value121", "value122", "value123", "value124", "value125", "value126", "value127", "value128", "value129", "value130", "value131", "value132", "value133", "value134", "value135", "value136", "value137", "value138", "value139", "value140", "value141", "value142", "value143", "value144", "value145", "value146", "value147", "value148", "value149", "value150", "value151", "value152", "value153", "value154", "value155", "value156", "value157", "value158", "value159", "value160", "value161", "value162", "value163", "value164", "value165", "value166", "value167", "value168", "value169", "value170", "value171", "value172", "value173", "value174", "value175", "value176", "value177", "value178", "value179", "value180", "value181", "value182", "value183", "value184", "value185", "value186", "value187", "value188", "value189", "value190", "value191", "value192", "value193", "value194", "value195", "value196", "value197", "value198", "value199", "value200", "value201", "value202", "value203", "value204", "value205", "value206", "value207", "value208", "value209", "value210", "value211", "value212", "value213", "value214", "value215", "value216", "value217", "value218", "value219", "value220", "value221", "value222", "value223", "value224", "value225", "value226", "value227", "value228", "value229", "value230", "value231", "value232", "value233", "value234", "value235", "value236", "value237", "value238", "value239", "value240", "value241", "value242", "value243", "value244", "value245", "value246", "value247", "value248", "value249", "value250", "value251", "value252", "value253", "value254", "value255", "value256", "value257", "value258", "value259", "value260", "value261", "value262", "value263", "value264", "value265", "value266", "value267", "value268", "value269", "value270", "value271", "value272", "value273", "value274", "value275", "value276", "value277", "value278", "value279", "value280", "value281", "value282", "value283", "value284", "value285", "value286", "value287", "value288", "value289", "value290", "value291", "value292", "value293", "value294", "value295", "value296", "value297", "value298", "value299", "value300", "value301", "value302", "value303", "value304", "value305", "value306", "value307", "value308", "value309", "value310", "value311", "value312", "value313", "value314", "value315", "value316", "value317", "value318", "value319", "value320", "value321", "value322", "value323", "value324", "value325", "value326", "value327", "value328", "value329", "value330", "value331", "value332", "value333", "value334", "value335", "value336", "value337", "value338", "value339", "value340", "value341", "value342", "value343", "value344", "value345", "value346", "value347", "value348", "value349", "value350")
Command lines entered at the console are limited to about 4095 bytes (not characters).
Source: R Documentation
You can try it yourself, if you insert a line break, it will work:
vector2 <- c("value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9", "value10", "value11", "value12", "value13", "value14", "value15", "value16", "value17", "value18", "value19", "value20", "value21", "value22", "value23", "value24", "value25", "value26", "value27", "value28", "value29", "value30", "value31", "value32", "value33", "value34", "value35", "value36", "value37", "value38", "value39", "value40", "value41", "value42", "value43", "value44", "value45", "value46", "value47", "value48", "value49", "value50", "value51", "value52", "value53", "value54", "value55", "value56", "value57", "value58", "value59", "value60", "value61", "value62", "value63", "value64", "value65", "value66", "value67", "value68", "value69", "value70", "value71", "value72", "value73", "value74", "value75", "value76", "value77", "value78", "value79", "value80", "value81", "value82", "value83", "value84", "value85", "value86", "value87", "value88", "value89", "value90", "value91", "value92", "value93", "value94", "value95", "value96", "value97", "value98", "value99", "value100", "value101", "value102", "value103", "value104", "value105", "value106", "value107", "value108", "value109", "value110", "value111", "value112", "value113", "value114", "value115", "value116", "value117", "value118", "value119", "value120", "value121", "value122", "value123", "value124", "value125", "value126", "value127", "value128", "value129", "value130", "value131", "value132", "value133", "value134", "value135", "value136", "value137", "value138", "value139", "value140", "value141", "value142", "value143", "value144", "value145", "value146", "value147", "value148", "value149", "value150", "value151", "value152", "value153", "value154", "value155", "value156", "value157", "value158", "value159", "value160", "value161", "value162", "value163", "value164", "value165", "value166", "value167", "value168", "value169", "value170", "value171", "value172", "value173", "value174", "value175", "value176", "value177", "value178", "value179", "value180", "value181", "value182", "value183", "value184", "value185", "value186", "value187", "value188", "value189", "value190", "value191", "value192", "value193", "value194", "value195", "value196", "value197", "value198", "value199", "value200", "value201", "value202", "value203", "value204", "value205", "value206", "value207", "value208", "value209", "value210", "value211", "value212", "value213", "value214", "value215", "value216", "value217", "value218", "value219", "value220", "value221", "value222", "value223", "value224", "value225", "value226", "value227", "value228", "value229", "value230", "value231", "value232", "value233", "value234", "value235", "value236", "value237", "value238", "value239", "value240", "value241", "value242", "value243", "value244", "value245", "value246", "value247", "value248", "value249", "value250", "value251", "value252", "value253", "value254", "value255", "value256", "value257", "value258", "value259", "value260", "value261", "value262", "value263", "value264", "value265", "value266", "value267", "value268", "value269", "value270", "value271", "value272", "value273", "value274", "value275", "value276", "value277", "value278", "value279", "value280", "value281", "value282", "value283", "value284", "value285", "value286", "value287", "value288", "value289", "value290", "value291", "value292", "value293", "value294", "value295", "value296", "value297", "value298", "value299", "value300", "value301", "value302", "value303", "value304", "value305", "value306", "value307", "value308", "value309", "value310", "value311", "value312", "value313", "value314", "value315", "value316", "value317", "value318", "value319", "value320", "value321", "value322", "value323", "value324", "value325", "value326", "value327", "value328", "value329", "value330", "value331", "value332", "value333", "value334", "value335", "value336", "value337", "value338", "value339", "value340", "value341", "value342", "value343", "value344", "value345", "value346", "value347", "value348", "value349",
"value350")
Anyway, it is good practice to avoid long lines to increase code readability. Stick to 80 or 120 character long lines, e.g.:
vector2 <- c("value1", "value2", "value3", "value4", "value5", "value6", "value7",
"value8", "value9", "value10", "value11", "value12", "value13",
"value14", "value15", "value16", "value17", "value18", "value19",
.
.
.
"value344", "value345", "value346", "value347", "value348", "value349",
"value350")
Related
For each driver, I want to create and save a plots$MixtureModelPlot png plot. It returns ggplots.
If I only want one plot, it would be:
plots <- MethylMix_PlotModel("MGMT", MethylMixResults, METcancer)
plots$MixtureModelPlot
plots$CorrelationPlot
However, when I want to plot all the drivers, my code below returns an empty plot.
for (gene in MethylMixResults$MethylationDrivers) {
png(file = paste(gene, '.png', sep = ''))
plots[gene] <- MethylMix_PlotModel(gene, MethylMixResults, met.kirp, METnormal = met.normal)
plots[gene]$MixtureModelPlot
plots[gene]$CorrelationPlot
dev.off()
}
Data:
> dput(drivers)
c("A2ML1", "ABCA4", "ABCC12", "ABHD1", "ACRBP", "ACSL5", "ACSM5",
"ACSS3", "ACVRL1", "ADH1C", "ADRB2", "AEBP1", "AFMID", "AIF1",
"AIM2", "AKR1B10", "AKR1C4", "AKR7L", "ALDH3B2", "ALDH8A1", "ALDOC",
"ALOX5AP", "ALPK3", "AMFR", "ANKRD2", "ANKRD22", "ANKRD45", "ANXA8L2",
"ANXA9", "AOC3", "APBB1IP", "APH1B", "APOBEC3C", "APOL3", "APOL4",
"APOM", "APP", "AQP1", "ARFRP1", "ARHGAP29", "ARHGDIB", "ARL11",
"ARL4D", "ARRDC3", "ASCL3", "B3GNT3", "B3GNT8", "BAMBI", "BAZ2B",
"BCHE", "BCL2L14", "BCL2L15", "BHMT", "BIN2", "BIRC7", "BRF2",
"BSCL2", "BST2", "C10orf116", "C10orf140", "C10orf82", "C10orf99",
"C11orf53", "C11orf63", "C11orf70", "C11orf92", "C12orf34", "C13orf23",
"C14orf109", "C15orf54", "C16orf55", "C17orf64", "C1QTNF3", "C1orf114",
"C1orf116", "C1orf168", "C1orf229", "C1orf38", "C1orf54", "C1orf88",
"C2", "C20orf114", "C20orf118", "C20orf151", "C21orf56", "C2orf43",
"C2orf65", "C3AR1", "C3orf67", "C4orf33", "C6orf132", "C7orf41",
"C8orf55", "C8orf56", "C8orf84", "C9orf125", "C9orf152", "C9orf25",
"C9orf41", "CALML5", "CAMK2G", "CAPG", "CAPN8", "CAPS", "CASC1",
"CASP4", "CCDC19", "CCDC8", "CCR2", "CD101", "CD200", "CD248",
"CD28", "CD4", "CD48", "CD68", "CD69", "CD9", "CD93", "CDC42BPG",
"CDC42SE1", "CDCA2", "CDK2", "CDK3", "CFP", "CGB2", "CHD7", "CHRNB1",
"CIAPIN1", "CKMT1B", "CLCNKB", "CLDN1", "CLDN23", "CLDN3", "CLDN7",
"CLDN8", "CLEC1A", "CLEC2B", "CLIC2", "CMAH", "CMTM3", "CNKSR1",
"CNTN6", "COX7A1", "COX7B2", "CP", "CPN2", "CPNE5", "CREB3L2",
"CRYBB1", "CSF2RB", "CT47B1", "CTLA4", "CTSF", "CTSS", "CTSZ",
"CXorf61", "CYP4Z2P", "DACT1", "DACT2", "DAPP1", "DBNDD1", "DCAF12L1",
"DDR2", "DDX43", "DEF6", "DEM1", "DFNA5", "DISP1", "DLEC1", "DNALI1",
"DNASE1", "DOPEY2", "DQX1", "DSEL", "DUSP7", "ECHDC2", "ECHDC3",
"EFCAB4A", "EFCAB4B", "EFEMP2", "EFS", "EHF", "ENG", "ENO3",
"EPHA4", "EPHX1", "ERMP1", "ESRP2", "ETV7", "EVC2", "EXPH5",
"EXTL1", "FAM108C1", "FAM124B", "FAM176B", "FAM25A", "FAM55D",
"FAM71D", "FAM83A", "FAM83C", "FBXL21", "FBXO27", "FBXO4", "FCAMR",
"FER1L5", "FERMT1", "FERMT2", "FES", "FGFR4", "FGG", "FHL1",
"FITM1", "FKBP1B", "FLJ44606", "FLVCR2", "FOXS1", "FURIN", "FUT2",
"FUT3", "FXYD3", "FXYD4", "FZD4", "GALNT3", "GAS1", "GBP6", "GGT6",
"GIMAP2", "GIMAP6", "GIPC2", "GJB5", "GJB6", "GJC2", "GLB1L",
"GLRB", "GLTP", "GNPNAT1", "GPC4", "GPR109B", "GPR143", "GPR152",
"GPR172B", "GPR182", "GPR77", "GPR84", "GPSM3", "GPT", "GSDMB",
"GYPC", "H1F0", "HAAO", "HCG4", "HECA", "HEY2", "HHLA2", "HIGD1B",
"HKR1", "HLA-B", "HLA-DPA1", "HNRNPA3P1", "HORMAD2", "HOXA11",
"HOXA11AS", "HOXA3", "HOXA4", "HOXA5", "HOXA7", "HOXB2", "HOXB6",
"HOXB9", "HOXC8", "HOXD10", "HOXD3", "HOXD4", "HOXD8", "HOXD9",
"HP", "HRG", "HS3ST1", "HSD17B14", "HSD17B7P2", "HSPB3", "HSPB9",
"HTATIP2", "HYAL1", "IFFO1", "IFI16", "IFI27", "IFITM1", "IFITM2",
"IFITM5", "IGFBP4", "IKZF3", "IL12RB2", "IL1F5", "IL1RL1", "INO80E",
"IRS1", "ISG20L2", "ITGA5", "ITGB2", "ITIH5L", "KCNJ1", "KHK",
"KIAA0494", "KIAA1826", "KIAA1949", "KISS1", "KLF2", "KLHDC7B",
"KLHL17", "KNG1", "KRT13", "KRT19", "KRT20", "KRT23", "KRT7",
"KRT8", "KRTAP4-8", "KRTCAP3", "LAMB3", "LAMC2", "LAT", "LCTL",
"LDHAL6A", "LEAP2", "LGALS12", "LGALS4", "LGALS7", "LGALS7B",
"LHX1", "LIME1", "LIPC", "LOC100133893", "LOC134466", "LOC144776",
"LOC149837", "LOC25845", "LOC284837", "LOC339535", "LOC391322",
"LOC400931", "LOC440563", "LOC441666", "LOC441869", "LOC554202",
"LOC642587", "LOC645166", "LOC728264", "LPXN", "LRG1", "LRRC34",
"LRRN4", "LY6G6C", "LY75", "MACC1", "MAGEA1", "MAGEA10", "MAGEB6",
"MAL", "MAP1A", "MAP4K5", "MAPKBP1", "MCCD1", "MFNG", "MFSD2A",
"MGP", "MICAL2", "MMP13", "MMP19", "MS4A1", "MS4A13", "MSL3L2",
"MTMR9L", "MUC20", "N4BP2L1", "NAA11", "NAPRT1", "NAPSB", "NARFL",
"NAT8", "NAT8B", "NBL1", "NDRG1", "NINL", "NKAPL", "NLRP1", "NOSTRIN",
"NPL", "NR0B2", "NRSN2", "NUDT12", "NUDT4", "ODAM", "OLFML1",
"OR13A1", "OSM", "OVOL1", "PAGE1", "PAGE3", "PAPLN", "PARVG",
"PCDH10", "PCDHB8", "PDCD1LG2", "PDE1A", "PGD", "PHF11", "PIK3CG",
"PIWIL2", "PKN3", "PKP3", "PLCB4", "PLEK", "PLIN2", "PLIN4",
"PLLP", "PLOD3", "PLS1", "PLS3", "PNMA3", "POF1B", "POGK", "PON3",
"PPFIBP2", "PPP1R3D", "PRB3", "PRKAG3", "PRKY", "PROM2", "PRPH2",
"PRSS38", "PSCA", "PSMA2", "PTPN22", "PTPN6", "PTPN7", "PWWP2B",
"ProSAPiP1", "RAB25", "RAB34", "RAPSN", "RASSF10", "RBM23", "RBP3",
"RBP4", "RBP5", "RDH5", "REC8", "REG4", "REM2", "RFTN2", "RHOF",
"RMND1", "RNASE1", "RNASE2", "RNF122", "RPL39L", "RRAD", "RRN3P1",
"RSPH9", "RTP4", "RXFP4", "S100A16", "S100B", "S100P", "SAMD9",
"SCNN1A", "SDR42E1", "SDR9C7", "SEPX1", "SERP2", "SERPINA3",
"SERPINB9", "SFN", "SFRS16", "SFT2D3", "SH2D1A", "SH3BGRL2",
"SHC1", "SIGIRR", "SLAMF7", "SLC10A6", "SLC12A3", "SLC15A2",
"SLC16A5", "SLC22A2", "SLC23A2", "SLC26A7", "SLC2A10", "SLC34A2",
"SLC35E2", "SLC39A5", "SLC45A3", "SLC47A2", "SLC5A1", "SLC5A6",
"SLC7A8", "SLC9A1", "SLC9A11", "SLC9A3R2", "SLFN12", "SLURP1",
"SMAD7", "SMAGP", "SMEK3P", "SNCG", "SOCS2", "SOX15", "SOX9",
"SPAG6", "SPATA18", "SPINK1", "SPINK8", "SPN", "SPTBN2", "SRRM1",
"STAP1", "STAT5A", "STOM", "SULT1C4", "SYPL2", "TACSTD2", "TAGAP",
"TBX2", "TBX3", "TCEA3", "TCN1", "TEAD2", "TEAD3", "TFEC", "TFF1",
"TFPI", "TGFBR3", "TGM1", "THRSP", "THY1", "TIE1", "TIFAB", "TINAG",
"TKT", "TLR1", "TMEM139", "TMEM220", "TMEM25", "TMEM40", "TMEM71",
"TMEM88", "TMEM98", "TMPRSS12", "TMPRSS2", "TNF", "TNFAIP6",
"TNFRSF6B", "TNFRSF9", "TNFSF10", "TOMM70A", "TP63", "TRAM2",
"TREML4", "TRIB2", "TRIL", "TRIM14", "TRIM29", "TRIM61", "TRIM63",
"TRIM9", "TRIP13", "TRPV6", "TSPAN8", "TSPYL3", "TUBA3C", "TYRP1",
"UBD", "UBE2DNL", "UGT3A1", "ULK2", "UOX", "UPK1A", "UPK1B",
"USH1C", "USHBP1", "USP46", "VCX2", "VCX3A", "VCX3B", "VENTXP1",
"VILL", "VNN1", "WBSCR26", "XCL2", "XIST", "ZDHHC23", "ZFP3",
"ZFP82", "ZG16B", "ZIK1", "ZMYND10", "ZNF135", "ZNF154", "ZNF208",
"ZNF215", "ZNF233", "ZNF234", "ZNF238", "ZNF280A", "ZNF433",
"ZNF454", "ZNF501", "ZNF542", "ZNF544", "ZNF572", "ZNF577", "ZNF586",
"ZNF620", "ZNF660", "ZNF662", "ZNF664", "ZNF667", "ZNF679", "ZNF69",
"ZNF714", "ZNF716", "ZNF763", "ZNF788", "ZNF790", "ZNF814", "ZNF844",
"ZP1", "ZSCAN12")
Since your function returns a list of ggplot objects, you need to plot these inside your loop:
for (gene in MethylMixResults$MethylationDrivers) {
png(file = paste(gene, '.png', sep = ''))
plots[gene] <- MethylMix_PlotModel(gene, MethylMixResults, met.kirp, METnormal = met.normal)
plot(plots[gene]$MixtureModelPlot)
plot(plots[gene]$CorrelationPlot)
dev.off()
}
In interactive mode (i.e. when directly writing e.g. plots[gene]$MictureModelPlot on the R command prompt) you can omit the plot() call because R auto-prints the value (and printing a ggplot plots it). But inside a loop auto-printing does not happen. You can see the same when working with any other values; for instance, compare:
a = 1
a
with
for (i in 1 : 5) {
a
}
The first code snippet will print the value of a. The second code snippet won’t because a is used as part of a compound statement rather than on its own on the command prompt.
I have a list in R from a Structural VAR Model I've run. Here is the dataset I've used
structure(c(-2.46773175636719, -7.72826473957142, 11.7280053716074,
-1.90017613519231, 2.46070753200911, -10.9055849254775, 12.5325444143789,
1.3401777880631, 1.11706357603545, -11.9683333308867, 13.8014223673123,
3.00567366940339, 1.93467425287253, -12.4811258520841, 12.5337510851622,
6.17970387794458, -0.311524449552714, -4.43067381564184, 6.00580266302142,
0.733215859597713, -0.0920826461465296, -10.4968848655989, 15.1592141225619,
-0.0142294828419764, 2.81612947228318, -7.95484787976672, 11.3258100085652,
-4.26536944046738, 1.71777230300645, 3.05071906367438, 6.86888493397788,
-2.04121390648186, -5.45632423113958, 4.32701496742318, -1.77039007913358,
-3.38387552001187, -3.6948032720689, 9.71137617961375, 7.70239243534423,
-7.34908250395865, 1.66529724744393, 4.12699586248877, 1.46757481960265,
0.371903496562886, -3.1265641490501, 10.1504446414976, -6.97113134346488,
10.6335568680931, -7.74296970668011, -0.31563625249369, 4.86848083529221,
0.0394209612387897, 4.1060141554107, 4.40828962229318, -3.65631265465627,
-0.804371886780864, 5.300399767623, 3.33547294572138, 2.19966779280814,
-2.96620054964727, 2.01147630916658, 3.00808531323007, -1.78858517036105,
-0.262917554632125, -2.63540419004151, 3.42060573075127, -0.379197105963414,
-2.24861964821645, -1.33132752566709, 1.67672890048411, 2.42834777679839,
-1.28230298674303, 2.33228006495114, -1.79196678955762, -3.25533945043563,
-2.49506277883942, 3.87275419034108, -0.237088301198796, 3.15158720918571,
-8.16796902280537, -5.40342750457601, -0.684253285161596, 2.76776077124627,
3.03762540403962, 1.59655060303945, 2.81108799665279, 2.12619249528281,
1.25976266808472, 1.75072385830202, 3.35523567403357, 3.66056933213099,
2.81157744760496, 2.8694753969682, 1.22389693906415, 1.23949528512668,
0.655297291930701, -0.0811557166513488, 2.49469766016768, 1.04750905161959,
0.553154355370644, 0.0394037933455493, 0.495095459931427, 0.263970407073533,
1.46876270708987, 1.02690822562028, 1.21249150827216, 0.744350196120713,
2.28082505446663, 1.40375659950536, 1.59077468759525, 1.74048892256584,
1.81791859189397, 0.640927792895951, 2.05320969806211, 3.31708856718933,
3.94172305193239, 1.29907384513261, 2.18844272980503, 2.02564945461834,
2.89662683480758, 0.531971587307556, 1.69103059033393, 0.195326999327161,
1.20287931837835, -0.0417495586606087, 1.89055607207678, 1.8793164132429,
1.19212718508228, 1.43097285231573, 2.4079363839828, 1.02287700043888,
1.41700117422383, 1.9324642470476, 1.42192313279805, 1.00916357593048,
1.26198292983659, 0.929701659038162, 1.77329986790085, 1.88793046797189,
0.685737107435092, 0.400744609924519, 0.766302538581343, 1.09780031685389,
1.00049427220021, 0.535284014354875, 3.18688973234602, 1.75770144393539,
1.19538307882463, 0.904511107610428, 3.52708500618766, 0.526934426385495,
0.361429093322574, 0.624469028588326, 1.95600784906818, 0.781933189336748,
1.09121935535335, 1.30962848646536, 1.24173607356797, 0.453213216209214,
0.468243562258674, 0.489076348335971, 0.848706378173603, 0.125371629239357,
0.817153292286932), .Dim = c(82L, 2L), .Dimnames = list(NULL,
c("GDP_NAM", "CPI_NAM")), index = structure(c(962323200,
970272000, 978220800, 985996800, 993859200, 1001808000, 1009756800,
1017532800, 1025395200, 1033344000, 1041292800, 1049068800, 1056931200,
1064880000, 1072828800, 1080691200, 1088553600, 1096502400, 1104451200,
1112227200, 1120089600, 1128038400, 1135987200, 1143763200, 1151625600,
1159574400, 1167523200, 1175299200, 1183161600, 1191110400, 1199059200,
1206921600, 1214784000, 1222732800, 1230681600, 1238457600, 1246320000,
1254268800, 1262217600, 1269993600, 1277856000, 1285804800, 1293753600,
1301529600, 1309392000, 1317340800, 1325289600, 1333152000, 1341014400,
1348963200, 1356912000, 1364688000, 1372550400, 1380499200, 1388448000,
1396224000, 1404086400, 1412035200, 1419984000, 1427760000, 1435622400,
1443571200, 1451520000, 1459382400, 1467244800, 1475193600, 1483142400,
1490918400, 1498780800, 1506729600, 1514678400, 1522454400, 1530316800,
1538265600, 1546214400, 1553990400, 1561852800, 1569801600, 1577750400,
1585612800, 1593475200, 1601424000), tzone = "UTC", tclass = "Date"), class = c("xts",
"zoo"))
and the code I've used to create the model
library(tidyverse)
library(vars)
var.namibia <- namibia %>% VAR(.,p=1,type = 'both',season=NULL)
SVAR.namibia <- BQ(var.namibia)
from this, I want to extract residuals from the variables in my model. I can do it by indexing (see below), but I'm interested in finding a dplyr solution to achieve the same. Any suggestions?
res <- SVAR.namibia$var$varresult$CPI_NAM$residuals
You can use purrr's pluck function.
SVAR.namibia %>%
purrr::pluck('var', 'varresult', 'CPI_NAM', 'residuals')
I want to write an algorithm that spits out the points highlighted by arrows. I've tried using a second derivative but it returns a similar plot to the one above and not sure how to use it.
Hi, sorry about that, I don't want the peaks, I want the point where the graph starts to increase - ie I want the point where the gradient changes from ~0 to something larger, does that make sense
Example data is below.
df = structure(list(X1 = c("2729", "2730", "2731", "2732", "2733",
"2734", "2735", "2736", "2737", "2738", "2739", "2740", "2741",
"2742", "2743", "2744", "2745", "2746", "2747", "2748", "2749",
"2750", "2751", "2752", "2753", "2754", "2755", "2756", "2757",
"2758", "2759", "2760", "2761", "2762", "2763", "2764", "2765",
"2766", "2767", "2768", "2769", "2770", "2771", "2772", "2773",
"2774", "2775", "2776", "2777", "2778", "2779", "2780", "2781",
"2782", "2783", "2784", "2785", "2786", "2787", "2788", "2789",
"2790", "2791", "2792", "2793", "2794", "2795", "2796", "2797",
"2798", "2799", "2800", "2801", "2802", "2803", "2804", "2805",
"2806", "2807", "2808", "2809", "2810", "2811", "2812", "2813",
"2814", "2815", "2816", "2817", "2818", "2819", "2820", "2821",
"2822", "2823", "2824", "2825", "2826", "2827", "2828", "2829",
"2830", "2831", "2832", "2833", "2834", "2835", "2836", "2837",
"2838", "2839", "2840", "2841", "2842", "2843", "2844", "2845",
"2846", "2847", "2848", "2849", "2850", "2851", "2852", "2853",
"2854", "2855", "2856", "2857", "2858", "2859", "2860", "2861",
"2862", "2863", "2864", "2865", "2866", "2867", "2868", "2869",
"2870", "2871", "2872", "2873", "2874", "2875", "2876", "2877",
"2878", "2879", "2880", "2881", "2882", "2883", "2884", "2885",
"2886", "2887", "2888", "2889", "2890", "2891", "2892", "2893",
"2894", "2895", "2896", "2897", "2898", "2899", "2900", "2901",
"2902", "2903", "2904", "2905", "2906", "2907", "2908", "2909",
"2910", "2911", "2912", "2913", "2914", "2915", "2916", "2917",
"2918", "2919", "2920", "2921", "2922", "2923", "2924", "2925",
"2926", "2927", "2928", "2929", "2930", "2931", "2932", "2933",
"2934", "2935", "2936", "2937", "2938", "2939", "2940", "2941",
"2942", "2943", "2944", "2945", "2946", "2947", "2948", "2949",
"2950", "2951", "2952", "2953", "2954", "2955", "2956", "2957",
"2958", "2959", "2960", "2961", "2962", "2963", "2964", "2965",
"2966", "2967", "2968", "2969", "2970", "2971", "2972", "2973",
"2974", "2975", "2976", "2977", "2978", "2979", "2980", "2981",
"2982", "2983", "2984", "2985", "2986", "2987", "2988", "2989",
"2990", "2991", "2992", "2993", "2994", "2995", "2996", "2997",
"2998", "2999", "3000", "3001", "3002", "3003", "3004", "3005",
"3006", "3007", "3008", "3009", "3010", "3011", "3012", "3013",
"3014", "3015", "3016", "3017", "3018", "3019", "3020", "3021",
"3022", "3023", "3024", "3025", "3026", "3027", "3028", "3029",
"3030", "3031", "3032", "3033", "3034", "3035", "3036", "3037",
"3038", "3039", "3040", "3041", "3042", "3043", "3044", "3045",
"3046", "3047", "3048", "3049", "3050", "3051", "3052", "3053",
"3054", "3055", "3056", "3057", "3058", "3059", "3060", "3061",
"3062", "3063", "3064", "3065", "3066", "3067", "3068", "3069",
"3070", "3071", "3072", "3073", "3074", "3075", "3076", "3077",
"3078", "3079", "3080", "3081", "3082", "3083", "3084", "3085",
"3086", "3087", "3088", "3089", "3090", "3091", "3092", "3093",
"3094", "3095", "3096", "3097", "3098", "3099", "3100", "3101",
"3102", "3103", "3104", "3105", "3106", "3107", "3108", "3109",
"3110", "3111", "3112", "3113", "3114", "3115", "3116", "3117",
"3118", "3119", "3120", "3121", "3122", "3123", "3124", "3125",
"3126", "3127", "3128", "3129", "3130", "3131", "3132", "3133",
"3134", "3135", "3136", "3137", "3138", "3139", "3140", "3141",
"3142", "3143", "3144", "3145", "3146", "3147", "3148", "3149",
"3150", "3151", "3152", "3153", "3154", "3155", "3156", "3157",
"3158", "3159", "3160", "3161", "3162", "3163", "3164", "3165",
"3166", "3167", "3168", "3169", "3170", "3171", "3172", "3173",
"3174", "3175", "3176", "3177", "3178", "3179", "3180", "3181",
"3182", "3183", "3184", "3185", "3186", "3187", "3188", "3189",
"3190", "3191", "3192", "3193", "3194", "3195", "3196", "3197",
"3198", "3199", "3200", "3201", "3202", "3203", "3204", "3205",
"3206", "3207", "3208", "3209", "3210", "3211", "3212", "3213",
"3214", "3215", "3216", "3217", "3218", "3219", "3220", "3221",
"3222", "3223", "3224", "3225", "3226", "3227", "3228", "3229",
"3230", "3231", "3232", "3233", "3234", "3235", "3236", "3237",
"3238", "3239", "3240", "3241", "3242", "3243", "3244", "3245",
"3246", "3247", "3248", "3249", "3250", "3251", "3252", "3253",
"3254", "3255", "3256", "3257", "3258", "3259", "3260", "3261",
"3262", "3263", "3264", "3265", "3266", "3267", "3268", "3269",
"3270", "3271", "3272", "3273", "3274", "3275", "3276", "3277",
"3278", "3279", "3280", "3281", "3282", "3283", "3284", "3285",
"3286", "3287", "3288", "3289", "3290", "3291", "3292", "3293",
"3294", "3295", "3296", "3297", "3298", "3299", "3300", "3301",
"3302", "3303", "3304", "3305", "3306", "3307", "3308", "3309",
"3310", "3311", "3312", "3313", "3314", "3315", "3316", "3317",
"3318", "3319", "3320", "3321", "3322", "3323", "3324", "3325",
"3326", "3327", "3328", "3329", "3330", "3331", "3332", "3333",
"3334", "3335", "3336", "3337", "3338", "3339", "3340", "3341",
"3342", "3343", "3344", "3345", "3346", "3347", "3348", "3349",
"3350", "3351", "3352", "3353", "3354", "3355", "3356", "3357",
"3358", "3359", "3360", "3361", "3362", "3363", "3364", "3365",
"3366", "3367", "3368", "3369", "3370", "3371", "3372", "3373",
"3374", "3375", "3376", "3377", "3378", "3379", "3380", "3381",
"3382", "3383", "3384", "3385", "3386", "3387", "3388", "3389",
"3390", "3391", "3392", "3393", "3394", "3395", "3396", "3397",
"3398", "3399", "3400", "3401", "3402", "3403", "3404", "3405",
"3406", "3407", "3408", "3409", "3410", "3411", "3412", "3413",
"3414", "3415", "3416", "3417", "3418", "3419", "3420", "3421",
"3422", "3423", "3424", "3425", "3426", "3427", "3428", "3429",
"3430", "3431", "3432", "3433", "3434", "3435", "3436", "3437",
"3438", "3439", "3440", "3441", "3442", "3443", "3444", "3445"
), X2 = c(-0.00385000000001254, -0.0154500000000484, -0.0277600000000007,
-0.0154500000000279, -0.0386000000000704, -0.0154500000000329,
-0.0115500000000053, 2.5238009638656e-15, -0.00385000000000757,
3.60475000000867, -0.470850000000881, -0.347350000000663, -0.173700000000328,
-0.139699999999998, -0.096500000000187, -0.0617500000001111,
-0.0579000000001016, -0.0424500000000768, -0.050150000000105,
-0.0579000000001191, -0.0540000000000976, -0.0579000000001924,
-0.0270000000000563, -0.0309000000000539, -0.0231500000000468,
-0.0270500000000538, -0.00775000000002209, -0.0193000000000404,
-0.0131199999999931, 0.219999999999842, 0.0579000000001427, -0.061750000000126,
-0.0617500000002055, -0.0309000000000726, -0.050150000000105,
-0.042450000000091, -0.0193000000000293, -0.0309000000000144,
-0.0115500000000196, -0.0116000000000154, -0.0154500000000366,
-0.00385000000000946, -0.0193000000000305, -0.00390000000000946,
-0.00390000000000639, -0.00771000000000015, -0.000789999999999225,
-4.97400384373025e-15, -0.00619000000000085, -0.0116000000000265,
-0.011550000000014, -0.00385000000000504, -0.00538999999999987,
-0.0116000000000203, -0.011550000000014, 0.00385000000001136,
-0.00230999999999795, 2.86419210237446e-15, -0.00230999999999954,
-0.00770000000002508, -0.00770000000001703, -0.00390000000000449,
-0.0085000000000008, -0.0193000000000529, -8.05101707233625e-15,
-0.00385000000001751, -0.0146699999999988, -0.00619000000000085,
-0.0116000000000265, 0.00153999999999996, 0.00385000000000546,
-0.00231000000000233, -0.000780000000000314, -0.00230999999999884,
0.0015400000000021, -8.05101707233625e-15, -0.00848000000000013,
-0.00385000000001751, -0.00775000000003729, -0.00769999999999792,
-1.1787959787484e-15, -0.00384999999999692, 0.00385000000001136,
-0.00384999999999762, 0.00385000000000639, -0.00385000000001161,
-0.000440000000001542, -0.00390000000000639, -0.000769999999999981,
0, -0.0154500000000091, -0.0077500000000059, -0.0154500000000335,
-0.0115500000000165, -0.00385000000000567, -0.00311000000000092,
0.0116000000000272, -0.00230999999999994, 0.0116000000000172,
0.00770000000001277, -0.00385000000000377, -0.00385000000001254,
0.00385000000001136, -0.00385000000000411, -0.0038499999999997,
-0.0116000000000215, -0.0154300000000006, -6.15348059644161e-15,
-0.00849999999999866, -0.0015500000000003, 0.00154000000000174,
-3.07674029821757e-15, -0.0115500000000345, -0.0115500000000165,
-6.15348059644161e-15, -0.00385000000002247, 0.0077000000000059,
-0.00385000000001254, -0.0115500000000315, -0.0154500000000107,
-0.0154500000000229, -0.0309000000000733, -1.65190000000256,
-0.258600000000477, -0.111900000000204, -0.0640499999999989,
-0.0579000000001016, -0.0270000000000494, -0.02393, -0.0193000000000324,
-0.0115500000000165, -0.0270000000000624, -0.0193000000000598,
-0.0309000000000733, -0.0463000000001036, -2.19220000000482,
-0.524900000000959, -0.189100000000636, -0.11580000000022, -0.0717700000000001,
-0.0424500000001407, -0.057900000000101, -0.0386000000000673,
-0.0193000000000449, -0.0277899999999995, -0.0077500000000276,
-0.0208600000000011, -0.0193000000000293, -0.0463000000000912,
-0.0386000000000716, -0.0501500000001031, -0.0347500000000728,
-0.0502000000000926, -0.0424500000000836, -0.00307999999999993,
-0.0116000000000234, 0.00389999999999833, -0.000769999999999981,
-0.00153999999999996, -0.00153999999999996, 0.00153999999999783,
-0.0162100000000009, -0.0386000000000797, -0.0432300000000026,
-0.038600000000117, -0.050200000000097, -0.0309000000000527,
-0.0231500000000593, 0.00461999999999989, -0.00385000000001064,
-0.00385000000000757, -0.0116000000000215, 0.00770000000004104,
0.00385000000000639, -0.941700000001459, -0.169850000000308,
-0.100350000000196, -0.0933799999999984, -0.0617500000001154,
-0.0579000000001165, -0.0386000000000822, -0.019300000000043,
-0.0231500000000629, -0.0115500000000165, -0.0270000000000464,
-0.0116000000000284, -0.00769999999999982, -2.76340000000441,
-0.270200000000513, -0.119650000000229, -0.108100000000387, -0.0540000000001033,
-0.0772000000001527, -0.0579000000001345, -0.0656000000001255,
-0.0540500000001704, -0.0386000000000716, -0.0270500000000663,
-0.0116000000000284, -0.0216200000000043, -0.00770000000001206,
-0.0308500000000552, -0.0115500000000265, -2.4190463576414e-14,
-0.00770000000003006, -0.0115900000000011, -0.0231500000000985,
-0.0193000000000293, -0.033979999999999, -0.00775000000002643,
-0.0478400000000022, -0.0231500000000412, -0.019300000000043,
-0.00233000000000134, -0.00390000000002501, 0.00154999999999958,
0.00384999999999991, 0.0077000000000059, -0.00770000000003193,
-0.0200899999999983, -0.0193000000000423, -0.0347000000000634,
-0.0540000000000927, -0.0733500000001364, -0.0501500000001637,
-0.0424500000000886, -0.050200000000087, -0.0308500000000459,
0.00384999999999834, -0.00231000000000208, -0.00387000000000167,
0.0030799999999978, -0.00385000000000757, -0.00385000000001064,
-0.0192500000000504, -0.0115500000000296, -0.0231500000001104,
-0.0579000000001085, -0.0733500000001314, -0.0386000000000697,
-0.0386000000000754, -0.0347500000000935, -0.00775000000001395,
0.00385000000000881, 0.000769999999999982, 0.0115500000000203,
0.00390000000001095, 0.00154000000000294, -0.00385000000001497,
-0.00385000000000567, -0.0309000000001234, -0.0347500000000728,
-0.0193000000000814, -0.0424500000000992, -0.0347500000000678,
0.274000000000822, 0.463150000000818, 1.03820000000353, 0.636800000000563,
-0.13663, -0.87225000000281, 0.644550000001354, -0.0579000000003174,
-0.72560000000209, -0.115800000000169, 2.08025000000553, -0.208400000000342,
-0.227700000000415, -0.328050000000636, -0.169850000000303, -0.104200000000212,
-0.0656500000001349, -0.0656500000001373, -0.0424500000000712,
-0.0347500000000697, -0.0285600000000002, -0.0193000000000324,
-0.0270000000000538, -0.0193000000000498, -0.0270000000000513,
-0.00849999999999724, -0.00770000000001513, -0.0162100000000009,
-0.0339800000000025, -0.0502000000001566, -0.0501500000000907,
-0.0193000000000454, -0.00770000000001893, 0.00385000000001136,
0.00390000000001402, 0.00153999999999996, -0.00307999999999993,
0.00390000000000023, 0.00384999999999834, 0.00384999999999644,
0.00385000000002943, -0.0138899999999971, -0.0223899999999993,
-0.0270500000000588, -0.00618999999999943, -0.0270500000000669,
0.00153999999999892, -0.000779999999999603, -2.5238009638656e-15,
0.00465000000000089, -0.00770000000001703, -2.91289464345889e-16,
0.00461999999999805, -0.0115900000000011, -0.00390000000001506,
-0.019300000000043, -0.0115899999999989, -0.0115900000000011,
-0.00770000000003258, 0, 0.00390000000000331, 0.0193000000000281,
0.00385000000002044, 0.00770000000002145, 0.00770000000000148,
0.0077000000000078, 0, 0.00308000000000135, -6.15348059644161e-15,
-0.015450000000036, -0.0309000000000726, -0.00385000000001254,
-0.0154000000000341, -1.11274169835756e-14, -0.00923999999999978,
-0.00234000000000107, -0.00770999999999944, 0.00385000000003251,
0.00461999999999429, 0.00385999999999811, -0.00770000000000798,
-0.023150000000093, -0.0154500000000348, -0.0424500000000737,
-0.019300000000043, -0.0308500000000125, -0.0309000000001054,
-0.0231500000000394, -1.1787959787484e-15, 0.000790000000000646,
-0.00231000000000036, 0, -0.00307999999999851, -0.00390000000002326,
-0.00230999999999753, -0.0193100000000022, -0.042450000000016,
-0.0385500000000679, -0.057900000000106, -0.0347000000000627,
-0.0386000000000922, -0.00385000000000445, 0.0077500000000097,
0.00230999999999995, -0.00385000000000352, 0.00307999999999948,
-0.000769999999999381, -1.1787959787484e-15, -0.015440000000001,
-0.0193000000000099, -0.0425000000000806, -0.0386000000000829,
-0.0424500000001675, -0.0386000000000773, -0.0463000000000192,
-0.00385000000001562, 0, 0.00769999999999875, -3.07674029821757e-15,
-0.00307999999999922, -0.0030799999999978, -0.0154000000000493,
-0.00385000000001254, -0.0231500000000079, -0.0347500000000802,
-0.0231500000000319, -0.0355200000000003, -0.0386000000000829,
-0.0463500000000801, -0.0347500000000678, 0.00155999999999792,
0.00385000000000639, -0.00385000000000231, 0, -0.00385000000000946,
-0.00153999999999966, 0, -0.0285600000000002, -0.0309000000000546,
-0.069450000000125, -0.0502000000000889, -0.0502000000000896,
0.3898000000001, 0.0540500000001028, 0.0115500000000253, 0.0116000000000142,
0.000769999999999981, -0.00385000000000504, -7.40090066366128e-15,
-0.00230999999999995, 0.00385000000000141, 0.00385000000000639,
-0.00385000000001254, -0.0270199999999981, -0.0502000000000896,
0.409100000000679, 0.0386000000000674, -0.0116000000000445, -0.00775000000004081,
-0.00307999999999993, -0.00385000000000757, -0.00770000000000208,
-0.00385000000001562, -0.00385000000001064, -0.00153999999999783,
-8.05101707233625e-15, -0.0177499999999995, -0.0424500000001796,
-0.0509500000000003, -0.0694500000001324, -0.0424500000001587,
-0.061750000000121, -0.0232000000000369, -0.0131299999999989,
-0.00153999999999886, 0.0077000000000059, -0.00310999999999879,
0.00769999999999982, 7.49841812496252e-15, -8.05101707233625e-15,
-0.0077000000000406, -0.0424500000000787, -0.0502000000001032,
-0.0347500000000747, -0.0656000000001262, -0.0733000000001494,
-0.034700000000074, -0.0193000000000869, 0.0231500000000662,
-0.00385000000000757, 0.00770000000001088, 0.0115600000000001,
-0.957150000001501, -0.14670000000027, -0.0772000000001383, -0.0617500000002002,
-0.0463000000000981, -0.0617500000001229, -0.0270000000000544,
-0.0347500000000597, -0.0386000000001412, -0.0694500000001331,
-0.0887500000001619, -0.0386000000000747, -0.0077500000000295,
0.015400000000064, 0.355050000000611, 0.0478699999999975, -6.15348059644161e-15,
-0.0177800000000019, -0.00385000000001064, -0.0116000000000674,
-0.0154500000000435, -0.0524900000000017, -0.0540500000002006,
-0.0540500000001021, -0.0617500000002394, -0.0308500000000688,
-0.0193000000000355, -0.0154000000000216, -0.000770000000000204,
0.00770000000001775, 0.00694000000000017, -0.00385000000001254,
0.0116000000000123, -0.00385000000002063, -0.00385000000000757,
-0.0270000000000743, -0.0309000000000763, -0.0926500000001775,
-0.0887500000003161, -0.0656500000001199, -0.042450000000078,
-0.0270000000000588, -0.0116000000000364, -0.000769999999999982,
-0.00385000000001254, -0.015400000000026, 0.00385000000002041,
0.0115500000000253, 0, -0.00385000000001161, -0.0386000000000723,
-0.0154500000000693, -0.100350000000196, -0.0849000000001704,
-0.0926500000001751, -0.0115500000000116, 0.00385000000000546,
-0.0116000000000154, 6.87160777622118e-15, -0.00384999999999991,
0.00231999999999886, -3.07674029821757e-15, 0.00390000000003514,
0.000779999999996745, -3.07674029821757e-15, -0.0231500000000617,
-0.0270500000000527, -0.0517200000000003, -0.050150000000105,
-0.0347500000000721, -0.0347500000000142, -0.00385000000001161,
0.00770000000000401, -0.00385000000000197, 0.000769999999999982,
-0.00385000000001372, 0.00385000000000141, 0.0116000000000278,
-3.71670324204166e-15, -0.0116000000000584, -0.00385000000001064,
-0.00464999999999875, -0.00775000000004982, -0.00390000000001506,
0.277900000000906, 0.119650000000208, 0.054000000000013, 0.0463000000000931,
0.0154500000000168, 0.00775000000000384, 0.0115500000000154,
0.00769999999999875, 1.89760393249092e-15, 0.00231999999999957,
0.000769999999999304, -0.0231500000000085, -0.0270500000000402,
0.351200000000562, -0.0231500000000833, -0.0270500000000588,
-0.0463500000000216, -0.0139000000000062, -9.23022089465272e-15,
-8.05101707233625e-15, 0.00385000000000546, 0.000759999999998229,
-0.0115500000000395, 0.000769999999999982, -0.011600000000024,
-0.00770000000001206, -0.0540500000001929, -0.0772000000001558,
-0.0656000000000217, -0.0772000000001484, -0.0579000000001128,
-0.0347000000000764, -0.0193000000000461, -0.00385000000000352,
-0.00385000000002122, -0.00696000000000083, 0.000789999999999225,
0.00384999999999834, -0.000800000000000978, -0.0116000000000234,
-0.00775000000001088, -0.0115900000000055, -0.0193000000000218,
-0.0347500000000808, -0.0386000000000897, -0.0501500000000858,
-0.00233999999999881, -0.00385000000000757, 2.00000000009208e-05,
0.308750000000515, 0.092650000000154, 0.0424500000000756, 0.0231500000000227,
0.0154500000000312, -0.00385000000001469, 0.00538999999999237,
0.474750000000936, 0.212300000000357, -0.0030699999999996, -0.0309000000000739,
-0.0115500000000265, -0.0116000000000265, -3.57390000000716,
-0.293350000001048, -0.119650000000226, -0.104200000000194, -0.0926500000001831,
-0.0540500000001096, -0.0694500000002714, -0.0772000000001527,
-0.0965000000001976, -0.0694500000001375, -0.100350000000182,
-0.084950000000289, -0.061750000000121, -0.0425000000000912,
-0.0424500000000662, -0.00770000000002011, -0.0154500000000422,
-0.00307999999999993, -0.00230999999999994, 0.00385000000001447,
-0.00154, -0.00385000000000567, -0.0386000000000747, -0.0695000000002463,
-0.0772000000001664, -0.0849000000002961, -0.0887500000001668,
-0.0193000000000504, -0.0578500000001047, -0.00775000000000708,
-1.2095231788207e-14, 0.00848999999999485, -3.07674029821757e-15,
-0.00541000000000057, -0.00390000000002247, 0.000769999999999981,
-0.0293300000000002, -0.050200000000087, -0.0656000000002546,
-0.0540500000001096, -0.069450000000138, 0.123500000000375, 0.0849000000001387,
0.00384999999999644, 0.023200000000042, 0.0115500000000123, 0.00775000000000473,
0.0115500000000203, 0.00385000000001447, -0.00775000000002506,
0.00466000000000122, -0.0254699999999978, -0.054799999999998,
-0.0231500000000444, 0.0116000000000454, 0.115800000000206, 0.030900000000046,
0.00385000000000331, -0.00153999999999996, 0.00384999999999084,
-0.00385000000000757, 0.00770000000001088, 1.7849988639723e-14,
0.00230999999999994, 0.00385000000001326, -0.00153999999999882,
-0.038600000000126, -0.0309000000000553, -0.00692999999999628,
-0.0154000000000403, -0.0579000000001097, -0.0347500000000678,
-0.0100400000000054, 0.00385000000000023, -0.00385000000001994,
-2.17923926727129e-14, 0.00389999999999028, 0.00390000000001402,
0.00384999999999084, -0.00385000000001751, 0.00770000000001399,
-0.0308500000000632, -0.0502000000001986, -0.0695000000001394,
-0.0501799999999982, -0.0309000000000752, -0.0270500000000557,
-0.0100500000000011, 0.00389999999999596, 0.0116000000000117,
1.89760393249092e-15, 0.0115500000000123, 0.00384999999998841,
-0.00385000000002965, 0.0077000000000078, 0.00385000000000639,
0.00770000000000283, -0.0501500000001132, -0.0617500000002242,
-0.0710100000000004, -0.0810500000000306, -0.0540500000001891,
-0.0386000000000617, -0.019300000000043, 0.00775000000000473,
0.00847000000000282, 0.00462999999999951, -2.11128370304365e-14,
0.00770000000001088, 0.00384999999999858, 9.99999999962123e-06,
-0.00770000000001206, -0.0733000000000254, -0.0656000000001967,
-0.111900000000213, -0.100350000000323, -0.0579000000001141,
-0.0385500000000131, -0.0116000000000215, 0.0193000000000318,
0.00390000000001402, 0.0270000000000452, 0.00770000000000182,
-8.05101707233625e-15)), row.names = c(NA, -717L), class = "data.frame")
As others have said, it is not clear what you are looking for.
specifically, it's not clear how high above "baseline" is too high.
Here's a shot at it:
df_prime <- df$X2[-1] - df$X2[-length(df$X2)]
large_rise <- which(df_prime > sd(df_prime) & df$X2[-length(df$X2)] > -sd(df$X2))
df$X1[large_rise]
It's difficult to know from the question, but aren't you just looking for something like this?
spikes <- as.numeric(df$X1[df$X2 > 0.1])
spikes <- spikes[which(diff(c(0, spikes)) > 3)]
spikes
#> [1] 2738 2758 2984 2994 3126 3139 3190 3260 3273 3309 3316 3363 3377
So, for example if you did
plot(df$X1, df$X2, type = "l")
points(spikes, rep(1, length(spikes)), col="red")
You would get
I was wondering if anyone knows of a way to get the dates to appear on the x axis of an stl plot.
res<- (stl(ts(data[,variable],frequency=52,start=as.Date(data[1,date]) ),s.window="per",robust=TRUE) )
plot(res)
However this is just producing some unicode labels at the bottom of the chart, I have also tried chaning as.Date to as.character however this didn't work.
dput of some data:
structure(c("2007-01-01", "2007-01-08", "2007-01-15", "2007-01-22",
"2007-01-29", "2007-02-05", "2007-02-12", "2007-02-19", "2007-02-26",
"2007-03-05", "2007-03-12", "2007-03-19", "2007-03-26", "2007-04-02",
"2007-04-09", "2007-04-16", "2007-04-23", "2007-04-30", "2007-05-07",
"2007-05-14", "2007-05-21", "2007-05-28", "2007-06-04", "2007-06-11",
"2007-06-18", "2007-06-25", "2007-07-02", "2007-07-09", "2007-07-16",
"2007-07-23", "2007-07-30", "2007-08-06", "2007-08-13", "2007-08-20",
"2007-08-27", "2007-09-03", "2007-09-10", "2007-09-17", "2007-09-24",
"2007-10-01", "2007-10-08", "2007-10-15", "2007-10-22", "2007-10-29",
"2007-11-05", "2007-11-12", "2007-11-19", "2007-11-26", "2007-12-03",
"2007-12-10", "2007-12-17", "2007-12-24", "2007-12-31", "2008-01-07",
"2008-01-14", "2008-01-21", "2008-01-28", "2008-02-04", "2008-02-11",
"2008-02-18", "2008-02-25", "2008-03-03", "2008-03-10", "2008-03-17",
"2008-03-24", "2008-03-31", "2008-04-07", "2008-04-14", "2008-04-21",
"2008-04-28", "2008-05-05", "2008-05-12", "2008-05-19", "2008-05-26",
"2008-06-02", "2008-06-09", "2008-06-16", "2008-06-23", "2008-06-30",
"2008-07-07", "2008-07-14", "2008-07-21", "2008-07-28", "2008-08-04",
"2008-08-11", "2008-08-18", "2008-08-25", "2008-09-01", "2008-09-08",
"2008-09-15", "2008-09-22", "2008-09-29", "2008-10-06", "2008-10-13",
"2008-10-20", "2008-10-27", "2008-11-03", "2008-11-10", "2008-11-17",
"2008-11-24", "2008-12-01", "2008-12-08", "2008-12-15", "2008-12-22",
"2008-12-29", "2009-01-05", "2009-01-12", "2009-01-19", "2009-01-26",
"2009-02-02", "2009-02-09", "2009-02-16", "2009-02-23", "2009-03-02",
"2009-03-09", "2009-03-16", "2009-03-23", "2009-03-30", "2009-04-06",
"2009-04-13", "2009-04-20", "2009-04-27", "2009-05-04", "2009-05-11",
"2009-05-18", "2009-05-25", "2009-06-01", "2009-06-08", "2009-06-15",
"2009-06-22", "2009-06-29", "2009-07-06", "2009-07-13", "2009-07-20",
"2009-07-27", "2009-08-03", "2009-08-10", "2009-08-17", "2009-08-24",
"2009-08-31", "2009-09-07", "2009-09-14", "2009-09-21", "2009-09-28",
"2009-10-05", "2009-10-12", "2009-10-19", "2009-10-26", "2009-11-02",
"2009-11-09", "2009-11-16", "2009-11-23", "2009-11-30", "2009-12-07",
"2009-12-14", "2009-12-21", "2009-12-28", "2010-01-04", "2010-01-11",
"2010-01-18", "2010-01-25", "2010-02-01", "2010-02-08", "2010-02-15",
"2010-02-22", "2010-03-01", "2010-03-08", "2010-03-15", "2010-03-22",
"2010-03-29", "2010-04-05", "2010-04-12", "2010-04-19", "2010-04-26",
"2010-05-03", "2010-05-10", "2010-05-17", "2010-05-24", "2010-05-31",
"2010-06-07", "2010-06-14", "2010-06-21", "2010-06-28", "2010-07-05",
"2010-07-12", "2010-07-19", "2010-07-26", "2010-08-02", "2010-08-09",
"2010-08-16", "2010-08-23", "2010-08-30", "2010-09-06", "2010-09-13",
"2010-09-20", "2010-09-27", "2010-10-04", "2010-10-11", "2010-10-18",
"2010-10-25", "2010-11-01", "2010-11-08", "2010-11-15", "2010-11-22",
"2010-11-29", "2010-12-06", "2010-12-13", "2010-12-20", "2010-12-27",
"2011-01-03", "2011-01-10", "2011-01-17", "2011-01-24", "2011-01-31",
"2011-02-07", "2011-02-14", "2011-02-21", "2011-02-28", "2011-03-07",
"2011-03-14", "2011-03-21", "2011-03-28", "2011-04-04", "2011-04-11",
"2011-04-18", "2011-04-25", "2011-05-02", "2011-05-09", "2011-05-16",
"2011-05-23", "2011-05-30", "2011-06-06", "2011-06-13", "2011-06-20",
"2011-06-27", "2011-07-04", "2011-07-11", "2011-07-18", "2011-07-25",
"2011-08-01", "2011-08-08", "2011-08-15", "2011-08-22", "2011-08-29",
"2011-09-05", "2011-09-12", "2011-09-19", "2011-09-26", "2011-10-03",
"2011-10-10", "2011-10-17", "2011-10-24", "2011-10-31", "2011-11-07",
"2011-11-14", "2011-11-21", "2011-11-28", "2011-12-05", "2011-12-12",
"2011-12-19", "2011-12-26", "442573", "452832", "452785", "459228",
"479509", "477631", "465619", "462001", "485567", "462381", "456059",
"457401", "474094", "468766", "456945", "539126", "545640", "511801",
"486619", "484430", "481428", "470622", "479677", "486755", "477617",
"483656", "497479", "493436", "480080", "481527", "516029", "532349",
"503939", "472171", "461550", "504532", "489715", "480032", "488376",
"470772", "467395", "488155", "455712", "474456", "471237", "482943",
"459320", "456956", "465056", "461930", "441201", "451255", "464508",
"449199", "455411", "476323", "521761", "513416", "521070", "497596",
"485461", "485593", "461148", "429938", "441207", "459484", "462099",
"469285", "454395", "456729", "469251", "517727", "526719", "477985",
"484538", "469766", "472399", "481162", "479039", "481071", "485068",
"462108", "459079", "452410", "488574", "502166", "504323", "514529",
"524206", "504315", "462935", "461899", "461551", "455491", "456857",
"443314", "454586", "458943", "450555", "454311", "442808", "440126",
"414876", "415787", "413352", "423864", "448319", "415440", "431948",
"433313", "448509", "436400", "454154", "454183", "447735", "452220",
"451433", "472808", "446767", "426595", "463693", "435673", "452704",
"456828", "465069", "448685", "457353", "443859", "463972", "480139",
"493342", "500982", "529602", "527365", "512005", "484585", "455007",
"470006", "477522", "443956", "459038", "488877", "466669", "476242",
"470862", "457298", "466438", "454062", "460216", "466645", "445113",
"457255", "451553", "451504", "447991", "435100", "416140", "481390",
"489041", "496984", "486245", "478191", "455201", "448085", "459097",
"480859", "490248", "462523", "489755", "468391", "460229", "481276",
"472845", "481099", "476435", "487314", "475043", "476847", "461928",
"483488", "479379", "456732", "461538", "480773", "471101", "459898",
"482129", "464356", "459420", "457850", "456764", "438152", "467928",
"464732", "458767", "470256", "449488", "433263", "428548", "435099",
"429163", "424251", "434723", "425841", "399498", "418791", "405051",
"385037", "425144", "418296", "397644", "414283", "431907", "429117",
"424862", "439664", "432791", "443588", "434985", "442418", "445760",
"449290", "451412", "456247", "444372", "441390", "458192", "456435",
"450670", "447609", "439083", "464513", "462784", "439423", "450857",
"442374", "447753", "440207", "435254", "430841", "437233", "426523",
"430127", "431305", "470244", "508878", "511064", "504182", "462076",
"452218", "426535", "436892", "459008", "441449", "438783", "427497",
"432275", "436745", "423068", "429574", "416074"), .Dim = c(261L,
2L))
The problem is with how you have created the time series object.
?ts will give you
start : the time of the first observation. Either a single number or a
vector of two integers, which specify a natural time unit and a
(1-based) number of samples into the time unit.
Since your data starts at 2007-01-01 and is a weekly data, you have to specify c(2007,1), Note that the "1" here denotes that data start from the 1st week of 2007, as the data is weekly. Here the frequency should be set to 52 because, after 52 cycles/weeks a year will change from 2007 to 2008.
This should work
res<- (stl(ts(data[,2],frequency=52,start=c(2007,1 )),s.window="per",robust=TRUE) )
I'm trying to replicate with R a chart I made on Excel, which should represent a 95% Confidence Interval (CI) around a time series forecast. The Excel chart looks like this:
So, basically, the original historical time series and from a certain point in time the forecast of what it could be with its respective CI.
They way it's done on Excel is a bit inefficient:
I have four time series which overlap much of the time;
The actual/historical time series (blue line above) simply stops when the forecast begins;
The forecast (dotted red above) is simply hidden below the blue one until the forecast period begins;
Then I have a time series representing the difference between the the upper bound and the lower bound of the CI, which playing around with Excel Stacked Areas charts, becomes the shaded area in the chart above.
Obviously, the computation to generate the forecast and the CIs is much faster and easier to generalize and use with R, and while I could complete the task on R and then simply copy the output on Excel to draw the chart, doing everything in R would be much nicer.
At the end of the question I provided the raw data with dput() as suggested by #MLavoie.
Here the packages I loaded (not sure you need them all here, but they are the ones I usually work with):
require(zoo)
require(xts)
require(lattice)
require(latticeExtra)
My data looks like this for the first 100 rows:
> head(data)
fifth_percentile Median nintyfifth_percentile
2017-06-18 1.146267 1.146267 1.146267
2017-06-19 1.134643 1.134643 1.134643
2017-06-20 1.125664 1.125664 1.125664
2017-06-21 1.129037 1.129037 1.129037
2017-06-22 1.147542 1.147542 1.147542
2017-06-23 1.159989 1.159989 1.159989
Then after the 100 data point, the time series start to diverge and at the end they look like this:
> tail(data)
fifth_percentile Median nintyfifth_percentile
2017-12-30 0.9430930 1.125844 1.341603
2017-12-31 0.9435227 1.127391 1.354928
2018-01-01 0.9417235 1.124625 1.355527
2018-01-02 0.9470077 1.124088 1.361420
2018-01-03 0.9571596 1.127299 1.364005
2018-01-04 0.9515535 1.127978 1.369536
Solution provided by DaveTurek
Thanks to DaveTurek I've found the answer. However, only difference is that for my xts dataframe, apparently, I need first to convert each column to numbers (with as.numeric()). No idea if that stems from me doing something wrong with xts and lattice, or it is the only way to achieve it using DaveTurek suggestion. Will try to investigate it further.
Here is the code to generate the chart:
x = index(data[1:100,2])
y = as.numeric(data[1:100,2])
ex.x = index(data[101:200,2])
ex.y = as.numeric(data[101:200,2])
ex.lo = as.numeric(data[101:200,1])
ex.hi = as.numeric(data[101:200,3])
xyplot(y~x, ylim = c(0.9,1.4),
panel=function(x,y,...) {
panel.lines(x,y,lwd=2,col=4)
panel.polygon(c(ex.x,rev(ex.x)),c(ex.lo,rev(ex.hi)),border=NA,col=5)
panel.lines(ex.x,ex.y,lwd=2,col=2)
})
And here the final result:
Here is the final dataset, from dput(), that I'm trying to plot:
> dput(data)
structure(c(1.14626724930899, 1.13464279067717, 1.12566420479952,
1.12903662366847, 1.14754211999921, 1.15998855701439, 1.15274364578958,
1.16226441955745, 1.16169992687419, 1.16520028734587, 1.16823402018407,
1.19832130049664, 1.18411773220697, 1.18531274215286, 1.16421444455115,
1.17108139956539, 1.18392357740377, 1.20103911352579, 1.17791736605905,
1.18277944964829, 1.20162550199013, 1.19665058179752, 1.19411188122108,
1.19367558590966, 1.19803272562951, 1.20600155861871, 1.22189449901607,
1.22072774140118, 1.22312376195254, 1.25355505518571, 1.25895911759195,
1.2613354420716, 1.24440525381363, 1.24444079462029, 1.24168652168112,
1.24154936710117, 1.23440527301777, 1.22592718438811, 1.21709102449773,
1.21448030929365, 1.23109601090898, 1.24401127451953, 1.23953314346685,
1.21863565024168, 1.20834325548551, 1.20281193695583, 1.20405850724191,
1.19608032796923, 1.22008184095742, 1.21675995421116, 1.20198916403093,
1.20029121301547, 1.18822375424598, 1.19007923345344, 1.19285965857709,
1.1971013197471, 1.1776860331227, 1.18028531916998, 1.18394951589397,
1.16712430930941, 1.17827461393349, 1.18751430033172, 1.21482260909863,
1.2167262724184, 1.21729489152574, 1.21847062594996, 1.21932070698031,
1.19678189566773, 1.17678214957629, 1.17586968485613, 1.16903708967946,
1.16967697995898, 1.14498266161799, 1.12782282645368, 1.11540004479973,
1.12639853863918, 1.11402516325222, 1.10511837662567, 1.10600107687395,
1.10243149863659, 1.10404564773364, 1.12949458422398, 1.11679224666313,
1.11338078540871, 1.10762728498848, 1.12437898939299, 1.11572706259347,
1.1148111967932, 1.12358625045939, 1.11169207274881, 1.13009253108247,
1.13772927166761, 1.12550770863279, 1.13062401691547, 1.12821231512428,
1.13174620070443, 1.13072790983063, 1.1428325334377, 1.12739171867048,
1.1214997813059, 1.11870510839984, 1.096148222775, 1.08805136310032,
1.08701594286129, 1.08047984136855, 1.07939438148434, 1.0684082570972,
1.06497159411023, 1.05820047926833, 1.06322519359802, 1.06234781015662,
1.05431808916504, 1.054405104791, 1.05330182895869, 1.04787681441803,
1.041698698458, 1.03870702538097, 1.03300007904201, 1.02741553353049,
1.03525701392318, 1.0339774223954, 1.0328464056954, 1.03100871401712,
1.03348765946373, 1.03473218333386, 1.02942612874379, 1.02109481188296,
1.02301597272716, 1.01553904377803, 1.0031650628692, 1.00779708136199,
1.01322764666693, 1.01964272925677, 1.02125480865504, 1.02300342204156,
1.02563993245866, 1.02972111884963, 1.02048756192688, 1.00481457379443,
1.00512607721887, 1.01094340128446, 1.01377432300649, 1.01170553705668,
1.00551128145228, 1.00612634442438, 1.00735643866839, 1.0080606590012,
0.985706701720841, 0.982234200010558, 0.975314534071082, 0.973611418201841,
0.968118612511537, 0.973092829667201, 0.975599110408158, 0.967214930243667,
0.968569928969912, 0.963572085616274, 0.964901787179726, 0.957782708788541,
0.951868416101986, 0.956694066411684, 0.956937537219092, 0.956303331651844,
0.947880835881923, 0.956308493824626, 0.948146077843001, 0.945939091828748,
0.945082701640947, 0.937222489932819, 0.937989843132858, 0.948712728941467,
0.939050882255992, 0.946264846068344, 0.944926693194716, 0.946825914432391,
0.939070104432721, 0.950666108330947, 0.949365988007735, 0.943616625744159,
0.946600795357699, 0.941276090147603, 0.939957902451166, 0.941523527816784,
0.946611480333791, 0.959236316317354, 0.96165367272139, 0.957508302724503,
0.954774123925477, 0.960811125123549, 0.956525507301749, 0.948237690612711,
0.951299123137395, 0.945212566792479, 0.94507842203255, 0.942735006048921,
0.943093032220433, 0.943522672031737, 0.941723495992432, 0.947007713852018,
0.95715960245335, 0.951553478810637, 1.14626724930899, 1.13464279067717,
1.12566420479952, 1.12903662366847, 1.14754211999921, 1.15998855701439,
1.15274364578958, 1.16226441955745, 1.16169992687419, 1.16520028734587,
1.16823402018407, 1.19832130049664, 1.18411773220697, 1.18531274215286,
1.16421444455115, 1.17108139956539, 1.18392357740377, 1.20103911352579,
1.17791736605905, 1.18277944964829, 1.20162550199013, 1.19665058179752,
1.19411188122108, 1.19367558590966, 1.19803272562951, 1.20600155861871,
1.22189449901607, 1.22072774140118, 1.22312376195254, 1.25355505518571,
1.25895911759195, 1.2613354420716, 1.24440525381363, 1.24444079462029,
1.24168652168112, 1.24154936710117, 1.23440527301777, 1.22592718438811,
1.21709102449773, 1.21448030929365, 1.23109601090898, 1.24401127451953,
1.23953314346685, 1.21863565024168, 1.20834325548551, 1.20281193695583,
1.20405850724191, 1.19608032796923, 1.22008184095742, 1.21675995421116,
1.20198916403093, 1.20029121301547, 1.18822375424598, 1.19007923345344,
1.19285965857709, 1.1971013197471, 1.1776860331227, 1.18028531916998,
1.18394951589397, 1.16712430930941, 1.17827461393349, 1.18751430033172,
1.21482260909863, 1.2167262724184, 1.21729489152574, 1.21847062594996,
1.21932070698031, 1.19678189566773, 1.17678214957629, 1.17586968485613,
1.16903708967946, 1.16967697995898, 1.14498266161799, 1.12782282645368,
1.11540004479973, 1.12639853863918, 1.11402516325222, 1.10511837662567,
1.10600107687395, 1.10243149863659, 1.10404564773364, 1.12949458422398,
1.11679224666313, 1.11338078540871, 1.10762728498848, 1.12437898939299,
1.11572706259347, 1.1148111967932, 1.12358625045939, 1.11169207274881,
1.13009253108247, 1.13772927166761, 1.12550770863279, 1.13062401691547,
1.12821231512428, 1.13174620070443, 1.13072790983063, 1.1428325334377,
1.12739171867048, 1.1214997813059, 1.11870510839984, 1.11811303551412,
1.11855383782522, 1.11981261957516, 1.12096887905804, 1.12162710713999,
1.12015553029278, 1.12189306008921, 1.1236834173899, 1.12204149206779,
1.12075809542535, 1.12116672935174, 1.12216772364685, 1.11821915571021,
1.12117719223463, 1.11896003906963, 1.11563621625852, 1.1183625095638,
1.12053072892388, 1.1216348268255, 1.12317377733957, 1.11873136428952,
1.12267083202989, 1.12642930089215, 1.13027646770951, 1.13129632891931,
1.12700346009603, 1.12060488827701, 1.12390899402613, 1.13129350591169,
1.12786650327192, 1.1274201121913, 1.13101906643359, 1.12727135093377,
1.12458327192256, 1.12259738972645, 1.12097982776572, 1.12073621452193,
1.12364872830763, 1.12644326299714, 1.12556263098661, 1.12797963752343,
1.12734519199847, 1.1261793072762, 1.12911407446825, 1.12754878937943,
1.12777579027467, 1.12554965831588, 1.12324469267853, 1.12231558194992,
1.12135908710208, 1.11923353817423, 1.12345300992675, 1.12186883237389,
1.12173652640663, 1.12488148969114, 1.12664301925369, 1.12294230775256,
1.12393650688095, 1.13038044949978, 1.12822226676967, 1.12934384230215,
1.1217648908055, 1.12218158739803, 1.12302651609468, 1.12682187689922,
1.13537701046932, 1.13172108462183, 1.1374053505525, 1.13498257452656,
1.12692005654471, 1.13210629725645, 1.12868775509168, 1.13073909215368,
1.13098804355869, 1.13353301668386, 1.13336476594698, 1.13233873705211,
1.12667020676157, 1.12133152301322, 1.12418759586717, 1.12048022460741,
1.12798162212357, 1.13053093896994, 1.12019367019997, 1.12422483586498,
1.11303086301782, 1.11986711815552, 1.12504718249418, 1.11341517044014,
1.12495096618792, 1.12995127061511, 1.13538401552385, 1.13145536081928,
1.1264465959783, 1.12584386458867, 1.1273908895838, 1.12462482614994,
1.1240880626286, 1.12729907535003, 1.12797751377714, 1.14626724930899,
1.13464279067717, 1.12566420479952, 1.12903662366847, 1.14754211999921,
1.15998855701439, 1.15274364578958, 1.16226441955745, 1.16169992687419,
1.16520028734587, 1.16823402018407, 1.19832130049664, 1.18411773220697,
1.18531274215286, 1.16421444455115, 1.17108139956539, 1.18392357740377,
1.20103911352579, 1.17791736605905, 1.18277944964829, 1.20162550199013,
1.19665058179752, 1.19411188122108, 1.19367558590966, 1.19803272562951,
1.20600155861871, 1.22189449901607, 1.22072774140118, 1.22312376195254,
1.25355505518571, 1.25895911759195, 1.2613354420716, 1.24440525381363,
1.24444079462029, 1.24168652168112, 1.24154936710117, 1.23440527301777,
1.22592718438811, 1.21709102449773, 1.21448030929365, 1.23109601090898,
1.24401127451953, 1.23953314346685, 1.21863565024168, 1.20834325548551,
1.20281193695583, 1.20405850724191, 1.19608032796923, 1.22008184095742,
1.21675995421116, 1.20198916403093, 1.20029121301547, 1.18822375424598,
1.19007923345344, 1.19285965857709, 1.1971013197471, 1.1776860331227,
1.18028531916998, 1.18394951589397, 1.16712430930941, 1.17827461393349,
1.18751430033172, 1.21482260909863, 1.2167262724184, 1.21729489152574,
1.21847062594996, 1.21932070698031, 1.19678189566773, 1.17678214957629,
1.17586968485613, 1.16903708967946, 1.16967697995898, 1.14498266161799,
1.12782282645368, 1.11540004479973, 1.12639853863918, 1.11402516325222,
1.10511837662567, 1.10600107687395, 1.10243149863659, 1.10404564773364,
1.12949458422398, 1.11679224666313, 1.11338078540871, 1.10762728498848,
1.12437898939299, 1.11572706259347, 1.1148111967932, 1.12358625045939,
1.11169207274881, 1.13009253108247, 1.13772927166761, 1.12550770863279,
1.13062401691547, 1.12821231512428, 1.13174620070443, 1.13072790983063,
1.1428325334377, 1.12739171867048, 1.1214997813059, 1.11870510839984,
1.14162401974592, 1.15630966411729, 1.15992199767135, 1.16683144867851,
1.16928280999155, 1.17287782220285, 1.18184525262982, 1.17555305757354,
1.18031492211593, 1.18142628277888, 1.18307577052783, 1.18257404220722,
1.19421117710041, 1.19403330560815, 1.19510080390052, 1.2058940348108,
1.19848571699109, 1.20138771250604, 1.20660682710938, 1.20790011589089,
1.20963951875753, 1.21572259411602, 1.21379678812156, 1.220302087399,
1.22062959185172, 1.22743877731977, 1.23135277550334, 1.24075667733246,
1.24169498945046, 1.23529301399753, 1.2399941777708, 1.24823732280171,
1.23861121958778, 1.24816319854615, 1.25252933549084, 1.25133386983018,
1.24512546001264, 1.2617641352045, 1.25486018976211, 1.25424601859098,
1.25820538036104, 1.25968528498312, 1.26939611029084, 1.27883933177157,
1.27926882841012, 1.27951234203094, 1.28997494816278, 1.29391898267335,
1.2971442938215, 1.29733541086814, 1.30376525837809, 1.31025722802128,
1.29718190520268, 1.27919305871102, 1.28685138548374, 1.28594279969497,
1.28695233433419, 1.30277136510213, 1.29178316107299, 1.29586799884087,
1.30076586308517, 1.30881154838964, 1.32171887794143, 1.3197588324899,
1.3121332301804, 1.31744410759858, 1.31402945919721, 1.30926303329755,
1.32019231597949, 1.31449633135152, 1.31730801686101, 1.31834557852015,
1.3175761022299, 1.33430488507454, 1.34091614601639, 1.33606628597812,
1.33180446732765, 1.33630738683041, 1.33449101077219, 1.32521028784732,
1.32241490851887, 1.31488015995544, 1.31913131799656, 1.32901121011698,
1.33177659436063, 1.32577077582349, 1.31960627618725, 1.31307169067904,
1.32148403094167, 1.33104893196281, 1.33491831741272, 1.3386091981919,
1.35730874062825, 1.3460340606746, 1.34160318929376, 1.35492848895938,
1.35552729646417, 1.36141957863605, 1.36400538435282, 1.369536167295),
.indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC",
class = c("xts", "zoo"), index = structure(c(1497744000, 1497830400, 1497916800,
1498003200, 1498089600, 1498176000, 1498262400, 1498348800, 1498435200,
1498521600, 1498608000, 1498694400, 1498780800, 1498867200, 1498953600,
1499040000, 1499126400, 1499212800, 1499299200, 1499385600, 1499472000,
1499558400, 1499644800, 1499731200, 1499817600, 1499904000, 1499990400,
1500076800, 1500163200, 1500249600, 1500336000, 1500422400, 1500508800,
1500595200, 1500681600, 1500768000, 1500854400, 1500940800, 1501027200,
1501113600, 1501200000, 1501286400, 1501372800, 1501459200, 1501545600,
1501632000, 1501718400, 1501804800, 1501891200, 1501977600, 1502064000,
1502150400, 1502236800, 1502323200, 1502409600, 1502496000, 1502582400,
1502668800, 1502755200, 1502841600, 1502928000, 1503014400, 1503100800,
1503187200, 1503273600, 1503360000, 1503446400, 1503532800, 1503619200,
1503705600, 1503792000, 1503878400, 1503964800, 1504051200, 1504137600,
1504224000, 1504310400, 1504396800, 1504483200, 1504569600, 1504656000,
1504742400, 1504828800, 1504915200, 1505001600, 1505088000, 1505174400,
1505260800, 1505347200, 1505433600, 1505520000, 1505606400, 1505692800,
1505779200, 1505865600, 1505952000, 1506038400, 1506124800, 1506211200,
1506297600, 1506384000, 1506470400, 1506556800, 1506643200, 1506729600,
1506816000, 1506902400, 1506988800, 1507075200, 1507161600, 1507248000,
1507334400, 1507420800, 1507507200, 1507593600, 1507680000, 1507766400,
1507852800, 1507939200, 1508025600, 1508112000, 1508198400, 1508284800,
1508371200, 1508457600, 1508544000, 1508630400, 1508716800, 1508803200,
1508889600, 1508976000, 1509062400, 1509148800, 1509235200, 1509321600,
1509408000, 1509494400, 1509580800, 1509667200, 1509753600, 1509840000,
1509926400, 1510012800, 1510099200, 1510185600, 1510272000, 1510358400,
1510444800, 1510531200, 1510617600, 1510704000, 1510790400, 1510876800,
1510963200, 1511049600, 1511136000, 1511222400, 1511308800, 1511395200,
1511481600, 1511568000, 1511654400, 1511740800, 1511827200, 1511913600,
1.512e+09, 1512086400, 1512172800, 1512259200, 1512345600, 1512432000,
1512518400, 1512604800, 1512691200, 1512777600, 1512864000, 1512950400,
1513036800, 1513123200, 1513209600, 1513296000, 1513382400, 1513468800,
1513555200, 1513641600, 1513728000, 1513814400, 1513900800, 1513987200,
1514073600, 1514160000, 1514246400, 1514332800, 1514419200, 1514505600,
1514592000, 1514678400, 1514764800, 1514851200, 1514937600, 1515024000
), tzone = "UTC", tclass = "Date"), .Dim = c(201L, 3L), .Dimnames = list(
NULL, c("fifth_percentile", "Median", "nintyfifth_percentile"
)))
I haven't tried with your data, but if the question is how to shade the forecast area, maybe this simple example will help.
library(lattice)
x = 1:12 # base data
y = x
ex.x = 12:16 # extrapolated data
ex.y = 12:16
ex.lo = 12+0:4*.3 # lower bound
ex.hi = 12+0:4*1.6 # upper bound
xyplot(y~x,xlim=c(0:18),ylim=c(0:20),
panel=function(x,y,...) {
panel.lines(x,y,lwd=2,col=4)
panel.polygon(c(ex.x,rev(ex.x)),c(ex.lo,rev(ex.hi)),border=NA,col=5)
panel.lines(ex.x,ex.y,lwd=2,col=2)
})
You can add the shaded polygon to the lattice plot in a panel function. I used c(ex.x,rev(ex.x)) and c(ex.lo,rev(ex.hi)) to construct the polygon boundary.