Related
I used following code to generate the sets:
H=list('ASD'=c("SCN3A", "TSC2", "RASSF8", "XDH", "CNTN5", "CHD7", "DPYD", "BUB1", "DPP4", "AMPD1", "ARID4A", "QSER1", "OCA2", "GPR141", "DNAH9", "LOXHD1", "SETX", "GSTP1", "SLC6A15", "ASTN1", "CACNA1D", "WFS1", "KCNC1", "TPRA1", "NBAS", "LAMB1", "TSNARE1", "GABRB3", "PAG1", "SOS1", "LHFPL4", "KMT2C", "GATM", "NPTX2", "ANK3", "SH3TC2", "CLPP", "TP53BP1", "EBF4", "ANO1", "DNAJC10", "TTC25", "NDUFB7", "PCSK1", "ROBO3", "MYO9A", "RPS23", "ZNF292", "CRBN", "HIVEP2", "CYP1B1", "KCNE2", "NRP2", "ADSL", "XIRP2", "SMARCA4", "HDAC2", "JAK2", "ATP9B", "ESR1", "MDN1", "CTNNA2", "CNTNAP2", "SPTB", "ACY1", "CEP290", "WNT2", "IQGAP3", "CACNG3", "CACNA1H", "FOXN1", "SPAST", "ADCY1", "IGF2", "RNF4", "CTTNBP2", "TMF1", "CPT1A", "TENM3", "RABGGTA", "MBD3", "CCDC18", "SMG1", "SYNE1", "PITX3", "HMGA2", "PDE6C", "CTU2", "PNPLA7", "PIEZO1", "MAP2", "MCF2L", "PRF1", "VWA8", "LRP2", "RYR3", "IPO9", "DIXDC1", "CNTNAP5", "ELP4", "LRRN1", "TRIO", "SACS", "ASIC2", "KIF1B", "AXIN2", "SORL1", "DLG2", "VPS13C", "F2RL1", "NRP1", "LAMA1", "LARP1", "SDK1", "LAMC2", "LSG1", "EP300", "DGCR6L", "TSHB", "APC", "TENM4", "IGSF21"),
'Epilepsy'=c("ADCY1", "ADSL", "ANK3", "APC", "ASIC2", "ASTN1", "ATP9B", "AXIN2", "BUB1", "CACNA1D", "CACNA1H", "CACNG3", "CEP290", "CLPP", "CNTN5", "CNTNAP2", "CNTNAP5", "CTNNA2", "CTU2", "DGCR6L", "DLG2", "DNAJC10", "ELP4", "EP300", "GABRB3", "HDAC2", "HMGA2", "IGSF21", "IPO9", "IQGAP3", "JAK2", "KCNC1", "KCNE2", "KIF1B", "LAMB1", "LAMC2", "LARP1", "LHFPL4", "MCF2L", "MYO9A", "NDUFB7", "NRP2", "RABGGTA", "RYR3", "SACS", "SCN3A", "SETX", "SMARCA4", "SMG1", "SORL1", "SPAST", "SPTB", "TMF1", "TP53BP1", "TPRA1", "TRIO", "TSC2", "TSHB", "VPS13C", "WFS1", "XDH", "ZNF292", "ABCA1", "ABCG5", "ACP2", "ADCY6", "ADGRA3", "ADGRV1", "AGA", "AGRN", "ALG3", "ANK2", "ANKRD44", "AP5Z1", "ARAP1", "ARHGEF11", "ASCC3", "ASPM", "ATRN", "AURKB", "BRINP2", "BRSK2", "CAPN15", "CAPN2", "CC2D2A", "CD36", "CDX1", "CHAT", "CHM", "CHTF18", "CLCN2", "CLCN7", "CLEC12A", "COG5", "COG6", "COL12A1", "COL17A1", "COL28A1", "COL6A2", "COQ3", "CYBB", "DBNL", "DBR1", "DEAF1", "DGKQ", "DHX29", "DMXL1", "DMXL2", "DNAH12", "DOCK7", "DOLK", "DSG4", "DZIP1", "EFHC1", "EPHA7", "EPHB1", "EPHB3", "ESYT1", "EXOC7", "F13A1", "F5", "FAH", "FARP1", "FASN", "FAT1", "FERMT1", "FGFR3", "FLNB", "FLRT1", "FMNL1", "FN1", "FOLR1", "FZD4", "GAA", "GAK", "GALC", "GANAB", "GLB1", "GM2A", "GNA14", "GOSR2", "GPC1", "GSS", "GTPBP4", "HEATR1", "HGS", "HIPK2", "HSPA13", "HTR2B", "INO80E", "KALRN", "KCNH2", "KCNJ16", "KIAA0586", "KRIT1", "LAMB2", "LMAN1", "LTBP3", "MASTL", "MED17", "METTL25", "MGAT5B", "MPL", "MRPL24", "MRPS27", "MSX2", "MUS81", "NALCN", "NEB", "NFE2L1", "NMBR", "NOL11", "NUCB1", "OBSL1", "OGDHL", "OGFOD2", "PARP1", "PCCB", "PDGFRA", "PDYN", "PFAS", "PFKFB3", "PLEC", "PLOD2", "PNKD", "PNPO", "POLD1", "POLE", "POLL", "PPAT", "PRDX3", "PSEN2", "PTCH1", "PTK2B", "RAB5A", "RAD54B", "RELB", "RHOT2", "RIMS2", "RTN4IP1", "SAE1", "SCAPER", "SCN1B", "SCN5A", "SEC23IP", "SERPINE2", "SGCB", "SIGLEC1", "SLC18A3", "SLC26A4", "SLC2A1", "SLC4A1", "SLC4A3", "SLITRK6", "SPG11", "STARD13", "STT3A", "SYF2", "SYNJ1", "SZT2", "TECPR2", "TES", "TMEM67", "TNK2", "TNS1", "TNS3", "TRAP1", "TRAPPC11", "TRAPPC8", "TRIP10", "TRPM2", "TRPM3", "TRPV1", "TUBGCP6", "TYW1", "UNC13B", "USP45", "VCP", "WDR62", "WWOX", "YAP1", "ZBTB48", "ZFHX4", "ZW10"),
'Intellectual'=c("YAP1", "TSC2", "FMNL1", "MADD", "KRIT1", "TNK2", "NUP155", "COG6", "TRAPPC8", "IPO9", "CCT8", "ZFYVE16", "FAT1", "SLC37A1", "KAT6B", "WWOX", "PTK2B", "CNTNAP5", "HEATR1", "TRAPPC11", "ARID4A", "ADGRV1", "GPC1", "AURKB", "TTC39B", "GSS", "GANAB", "RFWD3", "CUL9", "SAE1", "CACNG3", "SMC4", "ASIC2", "SYF2", "PFAS", "GAK", "METTL25", "OGDHL", "RAB5A", "VPS13C", "FGFR3", "KCNC1", "DDOST", "CTNND1", "ATRN", "UNC13B", "FASN", "MYO18A", "TMF1", "CRBN", "FLNB", "LARP1", "RCC2", "MASTL", "ADGRA3", "SCAPER", "SZT2", "LRP4", "SMG1", "SYNE1", "ADCY6", "RNGTT", "EP300", "ARAP1", "ANKRD44", "VPS39", "DGCR6L", "STT3A", "COG5", "NFE2L1", "SLC7A2", "ASCC3", "LMAN1", "OBSL1", "KIF20B", "PNPLA7"),
'Schizophrenia'=c("CRB1", "FBXW4", "CNTN5", "CHM", "DPYD", "BUB1", "DPP4", "ADGRV1", "GPC1", "DLD", "RBM19", "ITIH1", "ADCY7", "KCNC1", "ACBD5", "ELF1", "TSNARE1", "GABRB3", "TMEM182", "STT3A", "KMT2C", "ANK3", "SAMD4A", "NALCN", "PDLIM5", "LIMA1", "DYNC1I2", "TMEM26", "ANK2", "GRIN3A", "EPHB1", "BRINP2", "KALRN", "MICAL2", "TTLL6", "ZNF292", "SERPINB1", "SCAPER", "KCNS3", "VAMP1", "HDAC2", "DLG1", "CFAP58", "JAK2", "ESR1", "EFCAB14", "CNTNAP2", "PENK", "WWOX", "GLT8D1", "SFMBT2", "EEFSEC", "PDZD8", "GALC", "CACNG3", "SPG7", "ADCY1", "CLDN10", "TENM3", "OTOS", "CAPN2", "LRP4", "SYNE1", "HMGA2", "APOL4", "ARAP1", "DOPEY1", "EPN2", "MCF2L", "PLAA", "RYR3", "CNTNAP5", "POLE", "TRIO", "RAB11FIP5", "BNIP3L", "RUNX1", "AXIN2", "KIF1B", "DLG2", "MAP3K9", "CERCAM", "VPS13C", "MYO18B", "NRP1", "IRS1", "MANEA", "EP300", "DGCR6L", "TSHB", "AASDHPPT", "TRAPPC3", "APC", "TENM4"),
'ADHD'=c("TSC2", "CSMD2", "ANK3", "ASPM", "CNTN5", "TP53BP1", "CNTNAP2", "CHD7", "GLT8D1", "CNTNAP5", "SFMBT2", "MLH1", "FLII", "PTCH1", "SPRED1", "ARHGEF12", "CHMP7", "SVEP1", "CREB5", "MSH6", "TTLL8", "DLG2", "MICAL2", "DNAH3", "ADGRA3", "ACBD5", "SYNE1", "NUCB1", "NRP2", "TMEM182", "STT3A", "GNE", "PAX5", "TENM4"),
'Biopolar Disoder'=c("CSMD2", "ANK3", "NUMB", "CNTN5", "CTNNA2", "CNTNAP2", "NALCN", "RDH14", "WWOX", "GLT8D1", "SFMBT2", "SPRED1", "ADAMTS14", "TTC39B", "SVEP1", "COL28A1", "PDZD8", "GALC", "SORL1", "ITIH1", "CLSPN", "SLCO4A1", "VPS13C", "MYO18B", "TTLL6", "CRBN", "NFATC2", "SYNE1", "INTS7", "TMEM182", "STT3A", "WSCD1", "KCNS3", "PDGFRA"),
'circadian'=c("YTHDC2", "LRP1B", "SAMD4A", "VTA1", "NALCN", "F13A1", "SLC4A1", "TMEM26", "ADAMTS14", "COL28A1", "RNF19A", "BRINP2", "TRHR", "CCBE1", "CACNA2D3", "MYO18A", "SLC26A7", "FRAS1", "EP300", "GNE", "LMAN1", "NMBR", "TGFBI", "CHAT", "HIPK2", "SERPINE2", "RELB", "ARHGEF12", "SETX", "CACNA1D", "ADCY7", "NBAS", "GPR83", "LTBP3", "GABRB3", "HMBS", "PSMA4", "MADD", "SIX3", "EPHB1", "GAK", "SPRY4", "ABCA13", "SLC8A3", "HIVEP2", "FAH", "ADCY6", "MYLIP", "NFE2L1", "PRKAG1", "HDAC2", "TNS1", "GSS", "CACNA1H", "POLL", "CPT1A", "CAPN2", "PITX3", "NFE2L3", "PNPLA7", "AGA", "STX16", "TNK2", "PRF1", "RYR3", "DIXDC1", "PSEN2", "SREBF1", "POLE", "RAB11FIP5", "KIF1B", "RAB5A", "NGB", "ARHGEF11", "SIX6", "SDK1", "AATK", "CYP7A1", "CUL9"),
'dementia'=c("LMAN1", "PRDX3", "NPLOC4", "PSEN2", "ZFYVE16", "CHAT", "PENK", "LTBP1", "SNCAIP", "NOL11", "GANAB", "DLD", "SPG11", "IGSF21", "RNF19A", "ASIC2", "ASTN1", "SORL1", "SPRY4", "VCP", "TATDN1", "RAB5A", "VPS13C", "GM2A", "IRS1", "PSMB4", "NGB", "F2RL1", "RAB38", "SMOX", "PARP1", "ABCC9", "RPN2", "CAPN2", "GALNT7", "SMG1", "TBK1", "MASP2", "GNE", "GTPBP4", "CCT8", "CD63", "PSMA4", "TUBA4A", "CUL9")
)
venn(H)
Throws me an error:
Error in drawVennDiagram(data = counts, small = small, showSetLogicLabel = showSetLogicLabel, : Venn diagrams for 8 dimensions are not yet supported.
Here is a solution with package venneuler.
The data must first be restructured. A lapply loop will create data.frames with element name and set as 1st and 2nd columns, respectively. Then they are rbinded and the diagram is created.
library(venneuler)
Hmat <- lapply(seq_along(H), \(i) {
Set <- names(H)[i]
data.frame(Element = H[[i]], Set)
})
Hmat <- do.call(rbind, Hmat)
vd <- venneuler(Hmat)
plot(vd)
A double sapply loop is a way to get the overlap counts.
overlap <- function(x, y) length(intersect(x, y))
sapply(H, function(h1) sapply(H, function(h2) overlap(h1, h2)))
Using ggvenn package,
library(ggvenn)
ggvenn(H)
I developed a dashboard to show the dummy example of the problem that I am running. The shiny dashboard has four boxes. Top two boxes display a plotly chart and forecasted data using non-seasonal arima model. The bottom two boxes demonstrate a plotly chart and forecasted data using seasonal arima model. I also have a radio button for displaying items in either seasonal or non-seasonal boxes. I want the appropriate boxes to be displayed only when I click submit button. For example: if I check seasonal option in radio-button and click predict, I would like to see the seasonal chart and seasonally forecasted data. Currently, the dashboard display the boxes only based on the selected option in the radio-button.
skin <- Sys.getenv("DASHBOARD_SKIN")
skin <- tolower(skin)
if (skin == "")
skin <- "black"
sidebar <- dashboardSidebar(
sidebarSearchForm(label = "Search...", "searchText", "searchButton"),
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
)
)
)
body <- dashboardBody(
tabItems(
tabItem("dashboard",
# Boxes with solid headers
fluidRow(
box(
title = "Enter Stock Code", width = 4, solidHeader = TRUE, status = "primary",
radioButtons("seasonal", "Select", c(NonSeasonal = "NonSeasonal", Seasonal = "Seasonal")),
actionButton(inputId = "click", label = "Predict")
)
),
fluidRow(
box(
title = "Auto Arima - Non Seasonal",
status = "primary",
uiOutput("arima_nonseasonal", height = 350),
height = 470
),
box(
title = "Auto Arima - Non Seasonal",
width = "6",
tableOutput("arima_nonseasonal_Data"),
height = 470
)
),
fluidRow(
box(
title = "Auto Arima Seasonal",
status = "primary",
uiOutput("arima.seasonal", height = 350),
height = 470
),
box(
title = "Auto Arima Seasonal",
width = "6",
tableOutput("arima.seasonalData"),
height = 470
)
)
)
)
)
header <- dashboardHeader(
title = "Executive Dashboard"
)
ui <- dashboardPage(header, sidebar, body, skin = skin)
server <- function(input, output, session) {
output$nonseasonalplot <- renderPlotly({
qxts = structure(list(y=c(-0.4120000005, -0.452666665083333, -0.458666667316667, -0.460666666416667, -0.505333344133333, -0.506666670233333, -0.50999999045, -0.498666668933333, -0.502666672066667, -0.505333344133333, -0.50200000405, -0.506666680166667, -0.508000006266667, -0.5040000081, -0.501333341, -0.50200000405, -0.502000009016667, -0.504000003133333, -0.50466667115, -0.505333344133333, -0.501333341, -0.503333340083333, -0.496666664883333, -0.5040000081, -0.49799999595, -0.389333337533333, -0.3640000075, -0.365333338566667, -0.3586666733, -0.3599999994, -0.355333338183333, -0.365333338566667, -0.360666667416667, -0.3640000075, -0.3546666652, -0.369999999783333, -0.3653333336, -0.36733333765, -0.396666670833333, -0.469333335766667, -0.4586666673, -0.4639999916, -0.457333331283333, -0.4646666596, -0.4680000047, -0.4687999964, -0.467333336683333, -0.460666661433333, -0.4653333326, -0.4720000029, -0.453333328166667, -0.466000000616667, -0.4646666646, -0.45933333535, -0.464666659633333, -0.4579999993, -0.464666669566667, -0.473999996983333, -0.417333334666667, -0.46400000155, -0.4599999934, -0.46866666775, -0.47200000288, -0.465333337583333, -0.4719999979, -0.462666660516667, -0.46240000126, -0.465333322666667, -0.4673333317, -0.459999993416667, -0.464666659616667, -0.461333329466667, -0.46599999565, -0.461999997483333, -0.461999992516667, -0.466666663683333, -0.457333336283333, -0.46600000065, -0.463999996566667, -0.46400000155, -0.488666658566667, -0.543333326766667, -0.489333341533333, -0.3600000143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.3573333323, -0.464666662133333, -0.3360000037, -0.445333333066667, -0.49333334465, -0.444666661316667, -0.325333339483333, -0.60199998815, -0.33039999454, -0.394666674216667, -0.406666671233333, -0.4066666588, -0.52533333005, -0.552000006066667, -0.6973333458, -0.526000003, -0.565333336583333, -0.451428575185714, -0.3973333314, -0.591999994871429, -0.49120000004, -0.4313333432, -0.197333325966667, -0.545999998833333, -0.49600000976, -0.4595000035875, -0.45920000072, -0.453714281285714, -0.455333337166667, -0.461333334433333, -0.461999992533333, -0.457333331283333, -0.4606666664, -0.456000005183333, -0.4593333254, -0.4579999993, -0.45679999586, -0.455428570485714, -0.454666664183333, -0.453999991183333, -0.452666665083333, -0.464000001533333, -0.456666668216667, -0.45439999696, -0.45666666825, -0.454666664166667, -0.459999998383333, -0.45840000508, -0.459333330366667, -0.394666661816667, -0.367333332983333, -0.2823999971, -0.3446666648, -0.464666659633333, -0.443333327766667, -0.33920000494, -0.332666660333333, -0.363333340716667, -0.43599999546, -0.518000001716667, -0.15933333585, -0.2493333357, -0.43359999356, -0.462666669166667, -0.410000008833333, -0.357333337883333, -0.3615999937, -0.494666665783333, -0.52200000485, -0.29400000225, -0.4527999997, -0.474000004416667, -0.342666663233333, -0.53680000306, -0.423333331933333, -0.498666671416667, -0.439333344516667, -0.46480000914, -0.368666668733333, -0.2673333399, -0.303333333366667, -0.21279999912, -0.398000004383333, -0.444666676216667, -0.63679999114, -0.337333336466667, -0.2599999905 ),
date = c(1493139120, 1493139180, 1493139240, 1493139300, 1493139360, 1493139420, 1493139480, 1493139540, 1493139600, 1493139660, 1493139720, 1493139780, 1493139840, 1493139900, 1493139960, 1493140020, 1493140080, 1493140140, 1493140200, 1493140260, 1493140320, 1493140380, 1493140440, 1493140500, 1493140560, 1493140620, 1493140680, 1493140740, 1493140800, 1493140860, 1493140920, 1493140980, 1493141040, 1493141100, 1493141160, 1493141220, 1493141280, 1493141340, 1493141400, 1493141460, 1493141520, 1493141580, 1493141640, 1493141700, 1493141760, 1493141820, 1493141880, 1493141940, 1493142000, 1493142060, 1493142120, 1493142180, 1493142240, 1493142300, 1493142360, 1493142420, 1493142480, 1493142540, 1493142600, 1493142660, 1493142720, 1493142780, 1493142840, 1493142900, 1493142960, 1493143020, 1493143080, 1493143140, 1493143200, 1493143260, 1493143320, 1493143380, 1493143440, 1493143500, 1493143560, 1493143620, 1493143680, 1493143740, 1493143800, 1493143860, 1493143920, 1493143980, 1493144040, 1493144100, 1493144160, 1493144220, 1493144280, 1493144340, 1493144400, 1493144460, 1493144520, 1493144580, 1493144640, 1493144700, 1493144760, 1493144820, 1493144880, 1493144940, 1493145000, 1493145060, 1493145120, 1493145180, 1493145240, 1493145300, 1493145360, 1493145420, 1493145480, 1493145540, 1493145600, 1493145660, 1493145720, 1493145780, 1493145840, 1493145900, 1493145960, 1493146020, 1493146080, 1493146140, 1493146200, 1493146260, 1493146320, 1493146380, 1493146440, 1493146500, 1493146560, 1493146620, 1493146680, 1493146740, 1493146800, 1493146860, 1493146920, 1493146980, 1493147040, 1493147100, 1493147160, 1493147220, 1493147280, 1493147340, 1493147400, 1493147460, 1493147520, 1493147580, 1493147640, 1493147700, 1493147760, 1493147820, 1493147880, 1493147940, 1493148000, 1493148060, 1493148120, 1493148180, 1493148240, 1493148300, 1493148360, 1493148420, 1493148480, 1493148540, 1493148600, 1493148660, 1493148720, 1493148780, 1493148840, 1493148900, 1493148960, 1493149020, 1493149080, 1493149140, 1493149200, 1493149260, 1493149320, 1493149380, 1493149440, 1493149500, 1493149560, 1493149620, 1493149680, 1493149740, 1493149800, 1493149860, 1493149920, 1493149980, 1493150040, 1493150100, 1493150160, 1493150220, 1493150280, 1493150340, 1493150400, 1493150460, 1493150520))
)
fit.xts <- auto.arima(qxts$y, seasonal = FALSE)
forecast_length <- 10
fore.xts <- forecast(fit.xts, h=forecast_length)
fore.dates <- seq(as.POSIXct(qxts$date[length(qxts$date)], origin="1970-01-01"),
by=qxts$date[length(qxts$date)] - qxts$date[length(qxts$date)-1], len=forecast_length)
nonseasonal_p <- plot_ly() %>%
add_lines(x = as.POSIXct(qxts$date, origin="1970-01-01"), y = qxts$y,
color = I("black"),
name = "observed",
marker=list(mode="lines")) %>%
add_lines(x = fore.dates, y = fore.xts$mean, color = I("blue"), name = "prediction") %>%
add_ribbons(x = fore.dates,
ymin = fore.xts$lower[, 2],
ymax = fore.xts$upper[, 2],
color = I("gray95"),
name = "95% confidence") %>%
add_ribbons(x = fore.dates,
ymin = fore.xts$lower[, 1],
ymax = fore.xts$upper[, 1],
color = I("gray80"), name = "80% confidence")
return(nonseasonal_p)
})
#Nonseasonal plot Auto.Arima - plot here Tile#4
output$arima_nonseasonal <- renderUI({
if (input$seasonal == "NonSeasonal"){
plotlyOutput("nonseasonalplot")
}
})
nonseasonaltable <- reactive({
qxts = structure(list(y=c(-0.4120000005, -0.452666665083333, -0.458666667316667, -0.460666666416667, -0.505333344133333, -0.506666670233333, -0.50999999045, -0.498666668933333, -0.502666672066667, -0.505333344133333, -0.50200000405, -0.506666680166667, -0.508000006266667, -0.5040000081, -0.501333341, -0.50200000405, -0.502000009016667, -0.504000003133333, -0.50466667115, -0.505333344133333, -0.501333341, -0.503333340083333, -0.496666664883333, -0.5040000081, -0.49799999595, -0.389333337533333, -0.3640000075, -0.365333338566667, -0.3586666733, -0.3599999994, -0.355333338183333, -0.365333338566667, -0.360666667416667, -0.3640000075, -0.3546666652, -0.369999999783333, -0.3653333336, -0.36733333765, -0.396666670833333, -0.469333335766667, -0.4586666673, -0.4639999916, -0.457333331283333, -0.4646666596, -0.4680000047, -0.4687999964, -0.467333336683333, -0.460666661433333, -0.4653333326, -0.4720000029, -0.453333328166667, -0.466000000616667, -0.4646666646, -0.45933333535, -0.464666659633333, -0.4579999993, -0.464666669566667, -0.473999996983333, -0.417333334666667, -0.46400000155, -0.4599999934, -0.46866666775, -0.47200000288, -0.465333337583333, -0.4719999979, -0.462666660516667, -0.46240000126, -0.465333322666667, -0.4673333317, -0.459999993416667, -0.464666659616667, -0.461333329466667, -0.46599999565, -0.461999997483333, -0.461999992516667, -0.466666663683333, -0.457333336283333, -0.46600000065, -0.463999996566667, -0.46400000155, -0.488666658566667, -0.543333326766667, -0.489333341533333, -0.3600000143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.3573333323, -0.464666662133333, -0.3360000037, -0.445333333066667, -0.49333334465, -0.444666661316667, -0.325333339483333, -0.60199998815, -0.33039999454, -0.394666674216667, -0.406666671233333, -0.4066666588, -0.52533333005, -0.552000006066667, -0.6973333458, -0.526000003, -0.565333336583333, -0.451428575185714, -0.3973333314, -0.591999994871429, -0.49120000004, -0.4313333432, -0.197333325966667, -0.545999998833333, -0.49600000976, -0.4595000035875, -0.45920000072, -0.453714281285714, -0.455333337166667, -0.461333334433333, -0.461999992533333, -0.457333331283333, -0.4606666664, -0.456000005183333, -0.4593333254, -0.4579999993, -0.45679999586, -0.455428570485714, -0.454666664183333, -0.453999991183333, -0.452666665083333, -0.464000001533333, -0.456666668216667, -0.45439999696, -0.45666666825, -0.454666664166667, -0.459999998383333, -0.45840000508, -0.459333330366667, -0.394666661816667, -0.367333332983333, -0.2823999971, -0.3446666648, -0.464666659633333, -0.443333327766667, -0.33920000494, -0.332666660333333, -0.363333340716667, -0.43599999546, -0.518000001716667, -0.15933333585, -0.2493333357, -0.43359999356, -0.462666669166667, -0.410000008833333, -0.357333337883333, -0.3615999937, -0.494666665783333, -0.52200000485, -0.29400000225, -0.4527999997, -0.474000004416667, -0.342666663233333, -0.53680000306, -0.423333331933333, -0.498666671416667, -0.439333344516667, -0.46480000914, -0.368666668733333, -0.2673333399, -0.303333333366667, -0.21279999912, -0.398000004383333, -0.444666676216667, -0.63679999114, -0.337333336466667, -0.2599999905 ),
date = c(1493139120, 1493139180, 1493139240, 1493139300, 1493139360, 1493139420, 1493139480, 1493139540, 1493139600, 1493139660, 1493139720, 1493139780, 1493139840, 1493139900, 1493139960, 1493140020, 1493140080, 1493140140, 1493140200, 1493140260, 1493140320, 1493140380, 1493140440, 1493140500, 1493140560, 1493140620, 1493140680, 1493140740, 1493140800, 1493140860, 1493140920, 1493140980, 1493141040, 1493141100, 1493141160, 1493141220, 1493141280, 1493141340, 1493141400, 1493141460, 1493141520, 1493141580, 1493141640, 1493141700, 1493141760, 1493141820, 1493141880, 1493141940, 1493142000, 1493142060, 1493142120, 1493142180, 1493142240, 1493142300, 1493142360, 1493142420, 1493142480, 1493142540, 1493142600, 1493142660, 1493142720, 1493142780, 1493142840, 1493142900, 1493142960, 1493143020, 1493143080, 1493143140, 1493143200, 1493143260, 1493143320, 1493143380, 1493143440, 1493143500, 1493143560, 1493143620, 1493143680, 1493143740, 1493143800, 1493143860, 1493143920, 1493143980, 1493144040, 1493144100, 1493144160, 1493144220, 1493144280, 1493144340, 1493144400, 1493144460, 1493144520, 1493144580, 1493144640, 1493144700, 1493144760, 1493144820, 1493144880, 1493144940, 1493145000, 1493145060, 1493145120, 1493145180, 1493145240, 1493145300, 1493145360, 1493145420, 1493145480, 1493145540, 1493145600, 1493145660, 1493145720, 1493145780, 1493145840, 1493145900, 1493145960, 1493146020, 1493146080, 1493146140, 1493146200, 1493146260, 1493146320, 1493146380, 1493146440, 1493146500, 1493146560, 1493146620, 1493146680, 1493146740, 1493146800, 1493146860, 1493146920, 1493146980, 1493147040, 1493147100, 1493147160, 1493147220, 1493147280, 1493147340, 1493147400, 1493147460, 1493147520, 1493147580, 1493147640, 1493147700, 1493147760, 1493147820, 1493147880, 1493147940, 1493148000, 1493148060, 1493148120, 1493148180, 1493148240, 1493148300, 1493148360, 1493148420, 1493148480, 1493148540, 1493148600, 1493148660, 1493148720, 1493148780, 1493148840, 1493148900, 1493148960, 1493149020, 1493149080, 1493149140, 1493149200, 1493149260, 1493149320, 1493149380, 1493149440, 1493149500, 1493149560, 1493149620, 1493149680, 1493149740, 1493149800, 1493149860, 1493149920, 1493149980, 1493150040, 1493150100, 1493150160, 1493150220, 1493150280, 1493150340, 1493150400, 1493150460, 1493150520))
)
fit.xts <- auto.arima(qxts$y, seasonal = FALSE)
forecast_length <- 10
fore.xts <- forecast(fit.xts, h=forecast_length)
return(fore.xts)
return(nonseasonal_nwforcast)
})
#Non seasonal dataAuto.Arima1 - plot here Tile#5
output$arima_nonseasonal_Data <- renderTable({
if (input$seasonal == "NonSeasonal"){
nonseasonaltable()
}
})
output$seasonalplot<- renderPlotly({
qxts = structure(list(y=c(-0.4120000005, -0.452666665083333, -0.458666667316667, -0.460666666416667, -0.505333344133333, -0.506666670233333, -0.50999999045, -0.498666668933333, -0.502666672066667, -0.505333344133333, -0.50200000405, -0.506666680166667, -0.508000006266667, -0.5040000081, -0.501333341, -0.50200000405, -0.502000009016667, -0.504000003133333, -0.50466667115, -0.505333344133333, -0.501333341, -0.503333340083333, -0.496666664883333, -0.5040000081, -0.49799999595, -0.389333337533333, -0.3640000075, -0.365333338566667, -0.3586666733, -0.3599999994, -0.355333338183333, -0.365333338566667, -0.360666667416667, -0.3640000075, -0.3546666652, -0.369999999783333, -0.3653333336, -0.36733333765, -0.396666670833333, -0.469333335766667, -0.4586666673, -0.4639999916, -0.457333331283333, -0.4646666596, -0.4680000047, -0.4687999964, -0.467333336683333, -0.460666661433333, -0.4653333326, -0.4720000029, -0.453333328166667, -0.466000000616667, -0.4646666646, -0.45933333535, -0.464666659633333, -0.4579999993, -0.464666669566667, -0.473999996983333, -0.417333334666667, -0.46400000155, -0.4599999934, -0.46866666775, -0.47200000288, -0.465333337583333, -0.4719999979, -0.462666660516667, -0.46240000126, -0.465333322666667, -0.4673333317, -0.459999993416667, -0.464666659616667, -0.461333329466667, -0.46599999565, -0.461999997483333, -0.461999992516667, -0.466666663683333, -0.457333336283333, -0.46600000065, -0.463999996566667, -0.46400000155, -0.488666658566667, -0.543333326766667, -0.489333341533333, -0.3600000143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.3573333323, -0.464666662133333, -0.3360000037, -0.445333333066667, -0.49333334465, -0.444666661316667, -0.325333339483333, -0.60199998815, -0.33039999454, -0.394666674216667, -0.406666671233333, -0.4066666588, -0.52533333005, -0.552000006066667, -0.6973333458, -0.526000003, -0.565333336583333, -0.451428575185714, -0.3973333314, -0.591999994871429, -0.49120000004, -0.4313333432, -0.197333325966667, -0.545999998833333, -0.49600000976, -0.4595000035875, -0.45920000072, -0.453714281285714, -0.455333337166667, -0.461333334433333, -0.461999992533333, -0.457333331283333, -0.4606666664, -0.456000005183333, -0.4593333254, -0.4579999993, -0.45679999586, -0.455428570485714, -0.454666664183333, -0.453999991183333, -0.452666665083333, -0.464000001533333, -0.456666668216667, -0.45439999696, -0.45666666825, -0.454666664166667, -0.459999998383333, -0.45840000508, -0.459333330366667, -0.394666661816667, -0.367333332983333, -0.2823999971, -0.3446666648, -0.464666659633333, -0.443333327766667, -0.33920000494, -0.332666660333333, -0.363333340716667, -0.43599999546, -0.518000001716667, -0.15933333585, -0.2493333357, -0.43359999356, -0.462666669166667, -0.410000008833333, -0.357333337883333, -0.3615999937, -0.494666665783333, -0.52200000485, -0.29400000225, -0.4527999997, -0.474000004416667, -0.342666663233333, -0.53680000306, -0.423333331933333, -0.498666671416667, -0.439333344516667, -0.46480000914, -0.368666668733333, -0.2673333399, -0.303333333366667, -0.21279999912, -0.398000004383333, -0.444666676216667, -0.63679999114, -0.337333336466667, -0.2599999905 ),
date = c(1493139120, 1493139180, 1493139240, 1493139300, 1493139360, 1493139420, 1493139480, 1493139540, 1493139600, 1493139660, 1493139720, 1493139780, 1493139840, 1493139900, 1493139960, 1493140020, 1493140080, 1493140140, 1493140200, 1493140260, 1493140320, 1493140380, 1493140440, 1493140500, 1493140560, 1493140620, 1493140680, 1493140740, 1493140800, 1493140860, 1493140920, 1493140980, 1493141040, 1493141100, 1493141160, 1493141220, 1493141280, 1493141340, 1493141400, 1493141460, 1493141520, 1493141580, 1493141640, 1493141700, 1493141760, 1493141820, 1493141880, 1493141940, 1493142000, 1493142060, 1493142120, 1493142180, 1493142240, 1493142300, 1493142360, 1493142420, 1493142480, 1493142540, 1493142600, 1493142660, 1493142720, 1493142780, 1493142840, 1493142900, 1493142960, 1493143020, 1493143080, 1493143140, 1493143200, 1493143260, 1493143320, 1493143380, 1493143440, 1493143500, 1493143560, 1493143620, 1493143680, 1493143740, 1493143800, 1493143860, 1493143920, 1493143980, 1493144040, 1493144100, 1493144160, 1493144220, 1493144280, 1493144340, 1493144400, 1493144460, 1493144520, 1493144580, 1493144640, 1493144700, 1493144760, 1493144820, 1493144880, 1493144940, 1493145000, 1493145060, 1493145120, 1493145180, 1493145240, 1493145300, 1493145360, 1493145420, 1493145480, 1493145540, 1493145600, 1493145660, 1493145720, 1493145780, 1493145840, 1493145900, 1493145960, 1493146020, 1493146080, 1493146140, 1493146200, 1493146260, 1493146320, 1493146380, 1493146440, 1493146500, 1493146560, 1493146620, 1493146680, 1493146740, 1493146800, 1493146860, 1493146920, 1493146980, 1493147040, 1493147100, 1493147160, 1493147220, 1493147280, 1493147340, 1493147400, 1493147460, 1493147520, 1493147580, 1493147640, 1493147700, 1493147760, 1493147820, 1493147880, 1493147940, 1493148000, 1493148060, 1493148120, 1493148180, 1493148240, 1493148300, 1493148360, 1493148420, 1493148480, 1493148540, 1493148600, 1493148660, 1493148720, 1493148780, 1493148840, 1493148900, 1493148960, 1493149020, 1493149080, 1493149140, 1493149200, 1493149260, 1493149320, 1493149380, 1493149440, 1493149500, 1493149560, 1493149620, 1493149680, 1493149740, 1493149800, 1493149860, 1493149920, 1493149980, 1493150040, 1493150100, 1493150160, 1493150220, 1493150280, 1493150340, 1493150400, 1493150460, 1493150520))
)
fit.xts <- auto.arima(qxts$y, seasonal = TRUE)
forecast_length <- 10
fore.xts <- forecast(fit.xts, h=forecast_length)
fore.dates <- seq(as.POSIXct(qxts$date[length(qxts$date)], origin="1970-01-01"),
by=qxts$date[length(qxts$date)] - qxts$date[length(qxts$date)-1], len=forecast_length)
seasonal_p <- plot_ly() %>%
add_lines(x = as.POSIXct(qxts$date, origin="1970-01-01"), y = qxts$y,
color = I("black"),
name = "observed",
marker=list(mode="lines")) %>%
add_lines(x = fore.dates, y = fore.xts$mean, color = I("blue"), name = "prediction") %>%
add_ribbons(x = fore.dates,
ymin = fore.xts$lower[, 2],
ymax = fore.xts$upper[, 2],
color = I("gray95"),
name = "95% confidence") %>%
add_ribbons(x = fore.dates,
ymin = fore.xts$lower[, 1],
ymax = fore.xts$upper[, 1],
color = I("gray80"), name = "80% confidence")
return(seasonal_p)
})
#Auto.Arima Seasonal
output$arima.seasonal <- renderUI({
if (input$seasonal == "Seasonal"){
plotlyOutput("seasonalplot")
}
})
seasonaldata <- reactive({
qxts = structure(list(y=c(-0.4120000005, -0.452666665083333, -0.458666667316667, -0.460666666416667, -0.505333344133333, -0.506666670233333, -0.50999999045, -0.498666668933333, -0.502666672066667, -0.505333344133333, -0.50200000405, -0.506666680166667, -0.508000006266667, -0.5040000081, -0.501333341, -0.50200000405, -0.502000009016667, -0.504000003133333, -0.50466667115, -0.505333344133333, -0.501333341, -0.503333340083333, -0.496666664883333, -0.5040000081, -0.49799999595, -0.389333337533333, -0.3640000075, -0.365333338566667, -0.3586666733, -0.3599999994, -0.355333338183333, -0.365333338566667, -0.360666667416667, -0.3640000075, -0.3546666652, -0.369999999783333, -0.3653333336, -0.36733333765, -0.396666670833333, -0.469333335766667, -0.4586666673, -0.4639999916, -0.457333331283333, -0.4646666596, -0.4680000047, -0.4687999964, -0.467333336683333, -0.460666661433333, -0.4653333326, -0.4720000029, -0.453333328166667, -0.466000000616667, -0.4646666646, -0.45933333535, -0.464666659633333, -0.4579999993, -0.464666669566667, -0.473999996983333, -0.417333334666667, -0.46400000155, -0.4599999934, -0.46866666775, -0.47200000288, -0.465333337583333, -0.4719999979, -0.462666660516667, -0.46240000126, -0.465333322666667, -0.4673333317, -0.459999993416667, -0.464666659616667, -0.461333329466667, -0.46599999565, -0.461999997483333, -0.461999992516667, -0.466666663683333, -0.457333336283333, -0.46600000065, -0.463999996566667, -0.46400000155, -0.488666658566667, -0.543333326766667, -0.489333341533333, -0.3600000143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.3573333323, -0.464666662133333, -0.3360000037, -0.445333333066667, -0.49333334465, -0.444666661316667, -0.325333339483333, -0.60199998815, -0.33039999454, -0.394666674216667, -0.406666671233333, -0.4066666588, -0.52533333005, -0.552000006066667, -0.6973333458, -0.526000003, -0.565333336583333, -0.451428575185714, -0.3973333314, -0.591999994871429, -0.49120000004, -0.4313333432, -0.197333325966667, -0.545999998833333, -0.49600000976, -0.4595000035875, -0.45920000072, -0.453714281285714, -0.455333337166667, -0.461333334433333, -0.461999992533333, -0.457333331283333, -0.4606666664, -0.456000005183333, -0.4593333254, -0.4579999993, -0.45679999586, -0.455428570485714, -0.454666664183333, -0.453999991183333, -0.452666665083333, -0.464000001533333, -0.456666668216667, -0.45439999696, -0.45666666825, -0.454666664166667, -0.459999998383333, -0.45840000508, -0.459333330366667, -0.394666661816667, -0.367333332983333, -0.2823999971, -0.3446666648, -0.464666659633333, -0.443333327766667, -0.33920000494, -0.332666660333333, -0.363333340716667, -0.43599999546, -0.518000001716667, -0.15933333585, -0.2493333357, -0.43359999356, -0.462666669166667, -0.410000008833333, -0.357333337883333, -0.3615999937, -0.494666665783333, -0.52200000485, -0.29400000225, -0.4527999997, -0.474000004416667, -0.342666663233333, -0.53680000306, -0.423333331933333, -0.498666671416667, -0.439333344516667, -0.46480000914, -0.368666668733333, -0.2673333399, -0.303333333366667, -0.21279999912, -0.398000004383333, -0.444666676216667, -0.63679999114, -0.337333336466667, -0.2599999905 ),
date = c(1493139120, 1493139180, 1493139240, 1493139300, 1493139360, 1493139420, 1493139480, 1493139540, 1493139600, 1493139660, 1493139720, 1493139780, 1493139840, 1493139900, 1493139960, 1493140020, 1493140080, 1493140140, 1493140200, 1493140260, 1493140320, 1493140380, 1493140440, 1493140500, 1493140560, 1493140620, 1493140680, 1493140740, 1493140800, 1493140860, 1493140920, 1493140980, 1493141040, 1493141100, 1493141160, 1493141220, 1493141280, 1493141340, 1493141400, 1493141460, 1493141520, 1493141580, 1493141640, 1493141700, 1493141760, 1493141820, 1493141880, 1493141940, 1493142000, 1493142060, 1493142120, 1493142180, 1493142240, 1493142300, 1493142360, 1493142420, 1493142480, 1493142540, 1493142600, 1493142660, 1493142720, 1493142780, 1493142840, 1493142900, 1493142960, 1493143020, 1493143080, 1493143140, 1493143200, 1493143260, 1493143320, 1493143380, 1493143440, 1493143500, 1493143560, 1493143620, 1493143680, 1493143740, 1493143800, 1493143860, 1493143920, 1493143980, 1493144040, 1493144100, 1493144160, 1493144220, 1493144280, 1493144340, 1493144400, 1493144460, 1493144520, 1493144580, 1493144640, 1493144700, 1493144760, 1493144820, 1493144880, 1493144940, 1493145000, 1493145060, 1493145120, 1493145180, 1493145240, 1493145300, 1493145360, 1493145420, 1493145480, 1493145540, 1493145600, 1493145660, 1493145720, 1493145780, 1493145840, 1493145900, 1493145960, 1493146020, 1493146080, 1493146140, 1493146200, 1493146260, 1493146320, 1493146380, 1493146440, 1493146500, 1493146560, 1493146620, 1493146680, 1493146740, 1493146800, 1493146860, 1493146920, 1493146980, 1493147040, 1493147100, 1493147160, 1493147220, 1493147280, 1493147340, 1493147400, 1493147460, 1493147520, 1493147580, 1493147640, 1493147700, 1493147760, 1493147820, 1493147880, 1493147940, 1493148000, 1493148060, 1493148120, 1493148180, 1493148240, 1493148300, 1493148360, 1493148420, 1493148480, 1493148540, 1493148600, 1493148660, 1493148720, 1493148780, 1493148840, 1493148900, 1493148960, 1493149020, 1493149080, 1493149140, 1493149200, 1493149260, 1493149320, 1493149380, 1493149440, 1493149500, 1493149560, 1493149620, 1493149680, 1493149740, 1493149800, 1493149860, 1493149920, 1493149980, 1493150040, 1493150100, 1493150160, 1493150220, 1493150280, 1493150340, 1493150400, 1493150460, 1493150520))
)
fit.xts <- auto.arima(qxts$y, seasonal = TRUE)
forecast_length <- 10
fore.xts <- forecast(fit.xts, h=forecast_length)
return(fore.xts)
})
#Auto.Arima Seasonal data
output$arima.seasonalData <- renderTable({
if (input$seasonal == "Seasonal"){
seasonaldata()
}
})
}
shinyApp(ui, server)
I would like the dashboard to wait for me to hit the predict button before displaying the chart and the forecasted data in the boxes based on selected radio-button option.
input$seasonal is a reactive; when it changes value it triggers an update in any reactive or observers that uses it (which also includes renderXXX). Your actionbutton input$click is also a reactive, and follows the exact same rules. Its value is a simple integer counting how many times the button has been clicked in that session.
Use isolate(input$seasonal) if you want to use the value of the radio buttons, but not have changes trigger an update.
To then have a reactive, observer or renderXXX to be triggered by a click on the action button, simply include input$click somewhere, i.e.:
output$plot <- renderPlot({
if (isolate(input$seasonal) == 'foo') {
data = "foo"
} else {
data = "bar"
}
input$click # <--- this is where we react to the action button
plot(data)
})
I have some time series data and I would like to run "mini" regression models on it but on a rolling basis.
I can run a linear model and plot it using:
mod <- lm(Y1 ~ time(data), data = data)
ggplot(data, aes(x = time(data), y = Y1)) +
geom_line() +
geom_line(aes(x = as.Date(rownames(data.frame(mod$fitted.values))),
y = mod$fitted.values), colour = "blue")
Now I want to use the rollapply function to apply the linear model. I can use the roll_lm function.
library(roll)
rolledLinearModel <- roll_lm(
y = data[, "Y1"],
x = time(data),
width = 200
)
However, this does not store the fitted values. I am trying to use the rollapply function to do so.
library(zoo)
lmFunction <- function(x){
lm(Y1 ~ time(x), data = x)
}
data %>%
zoo() %>%
rollapply(
width = 40,
FUN = lmFunction
#fill = NA,
#by = 30,
#by.column = FALSE,
#align = "right"
)
However, I cannot seem to get it to work. Once I get the results I would like to plot all the (rolling) fitted values as (many different) lines on the plot.
Data:
data <- structure(c(46.423225, 46.59877, 46.010689, 46.265236, 45.975586,
44.685474, 45.480743, 45.312847, 44.950558, 45.454235, 45.683979,
45.957905, 44.570602, 46.320194, 45.904892, 46.408562, 45.675144,
46.072777, 46.691334, 46.373215, 46.470417, 45.065445, 44.641296,
45.330524, 44.323177, 44.181801, 44.641296, 44.199478, 44.349686,
44.552933, 44.031586, 43.916706, 47.884232, 48.379078, 49.138992,
49.810566, 50.455616, 50.013802, 49.969612, 49.050632, 49.545479,
50.38493, 49.775219, 49.465939, 49.412922, 49.377586, 49.943104,
50.367249, 51.940125, 52.523323, 52.134529, 52.152199, 51.507149,
50.968124, 51.339252, 51.374603, 51.825249, 52.797256, 52.97398,
53.159546, 52.850277, 52.947468, 53.804592, 54.84729, 52.761902,
53.000492, 53.327438, 54.529179, 54.405468, 53.733906, 53.680893,
53.954819, 53.323814, 53.172737, 52.58617, 52.639492, 53.137177,
53.066078, 51.404156, 51.706329, 51.937397, 51.466366, 51.688549,
51.848522, 52.381763, 52.959442, 53.01276, 52.523964, 51.679668,
51.990719, 51.555241, 51.830746, 52.195129, 52.390652, 52.008492,
51.750771, 52.097378, 52.666157, 53.057194, 53.341595, 53.483791,
52.515076, 51.475258, 50.693172, 50.293247, 49.991081, 50.168823,
50.355453, 50.311031, 50.51543, 50.444328, 50.959793, 51.125267,
51.644028, 51.259422, 50.463383, 50.919544, 51.098431, 51.474087,
51.590363, 50.588608, 51.00005, 50.427608, 52.234341, 52.449009,
52.610001, 51.500927, 51.679802, 52.350624, 52.547401, 53.710148,
54.121578, 53.754868, 56.295029, 55.874653, 55.677883, 55.320114,
54.175247, 54.139469, 54.139469, 53.844307, 53.826427, 54.282574,
54.202076, 54.56879, 54.112637, 54.989174, 54.550903, 53.683315,
54.41674, 54.479347, 55.311165, 55.498993, 54.604576, 53.397095,
53.128769, 50.901653, 50.454445, 50.508106, 49.917789, 50.373947,
51.169979, 51.769249, 51.903408, 50.812214, 50.436554, 50.186123,
49.694187, 49.747845, 50.257668, 49.676296, 50.284504, 50.758549,
49.676296, 49.381134, 48.334663, 48.397266, 47.395515, 47.189796,
47.064575, 47.359734, 47.589401, 46.832859, 46.706779, 47.121067,
47.742504, 47.742504, 48.012695, 47.94965, 48.120773, 46.895912,
46.949951, 47.598412, 47.98568, 47.940647, 48.354935, 48.039719,
49.435692, 49.976078, 49.940052, 49.994087, 50.399372, 50.642544,
50.021107, 49.624825, 49.093456, 49.273579, 48.706184, 48.652142,
49.38166, 48.571087, 47.589401, 47.283188, 47.27417, 46.82386,
45.346828, 46.310501, 46.490631, 46.832859, 44.085945, 43.923824,
43.923824, 43.464508, 43.662643, 43.356422, 43.806747, 45.26577,
44.004883, 43.833763, 44.004883, 43.050209, 43.221336, 43.536556,
43.284374, 43.059219, 43.050209, 42.617908, 42.816051, 43.140274,
42.942135, 42.825058, 42.419773, 42.221638, 42.527843, 43.203323,
42.194607, 42.509838, 42.978161, 42.383747, 42.392757, 42.500824,
42.338715, 42.662945, 41.366032, 42.014492, 42.284679, 42.671947,
43.175678, 43.130299, 43.529648, 44.391899, 43.575035, 44.07423,
43.69302, 43.883621, 43.529648, 43.783783, 44.428204, 45.009079,
44.745869, 44.60973, 43.756557, 44.065147, 44.428204, 44.273903,
42.522182, 41.941311, 41.551029, 42.041149, 41.995766, 42.168213,
42.313438, 42.268051, 43.130299, 43.584103, 43.647644, 44.927391,
44.028839, 44.900166, 44.373741, 44.292057, 43.420738, 42.839863,
42.966927, 43.38443, 43.856403, 42.694641, 40.979225, 40.643402,
41.305969, 41.614567, 42.930618, 42.549423, 42.594803, 43.084919,
43.656719, 42.885235, 42.440498, 42.367893, 43.275513, 43.021385,
43.130299, 44.700481, 44.455433, 45.562733, 45.408432, 47.02401,
45.962086, 46.179916, 46.452209, 46.461273, 46.098225, 46.30698,
46.297901, 45.726559, 46.128777, 47.216648, 46.796124, 46.357327,
47.362907, 47.390331, 47.326347, 46.878399, 47.143509, 46.512733,
47.591454, 45.799683, 46.595013, 46.595013, 47.116085, 47.783428,
47.673729, 49.026688, 49.739738, 47.518318, 48.002823, 47.847416,
48.450764, 49.191235, 49.428928, 51.147552, 50.004845, 50.416222,
50.544209, 46.476173, 44.300457, 44.501572, 43.422855, 42.417274,
44.44672, 44.318741, 43.459419, 43.724533, 44.19989, 43.527405,
44.163044, 43.895897, 43.4445, 42.965462, 42.652256, 42.993103,
42.937824, 42.956257, 41.952137, 41.804737, 41.556007, 40.717705,
41.66655, 40.837463, 40.441341, 40.846676, 40.855885, 41.28886,
41.316494, 40.036007, 39.999153, 40.662434, 40.109707, 39.612244,
39.870186, 38.810791, 38.17514, 39.059517, 38.709457, 39.317463,
39.501705, 38.737087, 39.26218, 39.326668, 39.252972, 38.866058,
38.64497, 39.041096, 38.737087, 38.820004, 38.875278, 38.727882,
38.681816, 38.598911, 37.73296, 37.806664, 37.77903, 38.700245,
38.995029, 38.525215, 38.525215, 37.889572, 37.52108, 37.051262,
36.867023, 37.769817, 37.539513, 37.134182, 36.94072, 37.428967,
37.557945, 37.659267, 37.889572, 38.985821, 39.216122, 39.151634,
39.317463, 39.271393, 38.746304, 38.543636, 38.976608, 39.022667,
39.022663, 38.176979, 37.805244, 38.269909, 38.539417, 39.905521,
39.543095, 39.636028, 39.747547, 40.286556, 41.169422, 41.076492,
42.693531, 42.349682, 41.550449, 42.451904, 42.042999, 41.085785,
38.632347, 38.400021, 38.706692, 38.93903, 39.106308, 38.976196,
39.292168, 39.217831, 39.394398, 40.32373, 40.602531, 39.914825,
40.18433, 39.89624, 39.905521, 39.636028, 39.143475, 39.143475,
38.67881, 38.520832, 41.476101, 41.903599, 41.448223, 41.243774,
41.020733, 39.859066, 39.645321, 39.924118, 40.946388, 40.277267,
40.546772, 40.574654, 40.658291, 40.193626, 38.455772, 38.660225,
38.102631, 38.204857, 39.273586, 39.440865, 40.221504, 39.812599,
39.719662, 39.821892, 40.444546, 40.072819, 40.175037, 39.450161,
39.608143, 39.859066, 40.955681, 40.955681, 41.234474, 41.448223,
41.262356, 41.336704, 41.40176, 41.141548, 41.582008, 41.619503,
42.369228, 42.584782, 42.500431, 41.863163, 41.97562, 42.013115,
42.172424, 42.453575, 42.781593, 42.697239, 42.125572, 40.907253,
41.197773, 40.9916, 39.820141, 38.573715, 38.358166, 38.348793,
38.151989, 38.629944, 39.051666, 37.823982, 37.083618, 36.296402,
35.49044, 35.36861, 34.96563, 33.728573, 34.225269, 35.387352,
35.818447, 36.821217, 37.299168, 36.746246, 37.02739, 38.386276,
38.292564, 38.170727, 38.217587, 38.986061, 38.911098, 38.779888,
38.779888, 37.664661, 37.561581, 37.5522, 37.383514, 38.798634,
39.023552, 40.110668, 39.820141, 39.63271, 40.663593, 39.229729,
36.971169, 35.846561, 34.646996, 33.841026, 33.756687, 33.074928,
32.876083, 32.137501, 32.03334, 31.484144, 31.256889, 30.518316,
30.215313, 32.014408, 32.099625, 32.156437, 32.307938, 32.270069,
31.379988, 32.8382, 33.813499, 34.495262, 34.542606, 34.656235,
34.608887, 34.883484, 35.016052, 35.101273, 35.300117, 35.442154,
34.400574, 34.135445, 34.561543, 34.921364, 34.665699, 32.913948,
34.542606, 34.902424, 34.703579, 34.627827, 34.665699, 34.466854,
33.709335, 33.37793, 33.794556, 34.06916, 34.561543, 34.731983,
35.319054, 35.139149, 35.290649, 35.442154, 35.139149, 35.593655,
34.902424, 35.356934, 35.148617, 35.868252, 35.546307, 36.739395,
36.152321, 35.470562, 35.659939, 35.356934, 34.85508, 34.898132,
34.859859, 35.012924, 34.553741, 34.764198, 33.463173, 33.635368,
32.372612, 32.525665, 33.319679, 34.008457, 34.084988, 34.113686,
35.357315, 36.141758, 36.313953, 37.366253, 38.562046, 38.542919,
37.146229, 37.624546, 37.71064, 38.475952, 38.332451, 38.992538,
39.260391, 39.116898, 37.997635, 37.232327, 36.141758, 34.9077,
35.500813, 35.912163, 35.615608, 34.917259, 35.46254, 35.596478,
35.051189, 34.725933, 34.649403, 34.391109, 34.343281, 32.525665,
33.233582, 33.444038, 33.577969, 33.06139, 33.300545, 34.113686,
33.654503, 32.774391, 33.003986, 32.439568, 32.183231, 32.318657,
31.651194, 32.415386, 33.121548, 33.247292, 33.208603, 33.51815,
33.914757, 33.943775, 33.421413, 33.759983, 33.508476, 33.431091,
33.837368, 33.769657, 34.833725, 35.443142, 34.146915, 34.040508,
34.514507, 34.427444, 34.659607, 34.514507, 34.021156, 35.075558,
34.843399, 34.582218, 34.292019, 34.475811, 34.92078, 35.433472,
35.201309, 35.404449, 34.688625, 34.572548, 33.711617, 33.160236,
35.288372, 34.524178, 34.408096, 34.727318, 34.417774, 34.050182,
34.611237, 33.701942, 33.86639, 32.212246, 32.308979, 32.270287,
33.227947, 32.734612, 32.067146, 32.686241, 30.809612, 30.316271,
31.206217, 31.49642, 30.838631, 31.022425, 30.92569, 29.716522,
29.88097, 29.397303, 29.803583, 30.383986, 30.857977, 30.016397,
30.451698, 31.515768, 31.486744, 33.276314, 34.233978, 34.533848,
34.872417, 35.462494, 35.320778, 34.128433, 33.845005, 34.001381,
34.470497, 34.607327, 33.248837, 34.245716, 34.421635, 34.900524,
35.154633, 34.705059, 34.020927, 34.275032, 34.56823, 33.336796,
32.418102, 32.506058, 33.033817, 34.304352, 34.411861, 35.604202,
35.731258, 35.868084, 35.741028, 36.239471, 39.132374, 38.663254,
37.871616, 38.497108, 39.435345, 39.562401, 39.220333, 38.027985,
38.438469, 37.969349, 38.555748, 37.666374, 38.360283, 38.497108,
37.646828, 37.490456, 36.952927, 36.816093, 37.119068, 36.698818,
36.024456, 34.714832, 34.959164, 35.643299, 36.288338, 36.327427,
36.131962, 35.55534, 35.47715, 35.095993, 35.154633, 35.066673,
36.073326, 35.88763, 36.346977, 36.718361, 37.38295, 36.864769,
36.430485, 36.943729, 37.318794, 36.874641, 36.943729, 37.427364,
37.397755, 37.348404, 37.269444, 37.062172), index = structure(c(1472688000,
1472774400, 1473120000, 1473206400, 1473292800, 1473379200, 1473638400,
1473724800, 1473811200, 1473897600, 1473984000, 1474243200, 1474329600,
1474416000, 1474502400, 1474588800, 1474848000, 1474934400, 1475020800,
1475107200, 1475193600, 1475452800, 1475539200, 1475625600, 1475712000,
1475798400, 1476057600, 1476144000, 1476230400, 1476316800, 1476403200,
1476662400, 1476748800, 1476835200, 1476921600, 1477008000, 1477267200,
1477353600, 1477440000, 1477526400, 1477612800, 1477872000, 1477958400,
1478044800, 1478131200, 1478217600, 1478476800, 1478563200, 1478649600,
1478736000, 1478822400, 1479081600, 1479168000, 1479254400, 1479340800,
1479427200, 1479686400, 1479772800, 1479859200, 1480032000, 1480291200,
1480377600, 1480464000, 1480550400, 1480636800, 1480896000, 1480982400,
1481068800, 1481155200, 1481241600, 1481500800, 1481587200, 1481673600,
1481760000, 1481846400, 1482105600, 1482192000, 1482278400, 1482364800,
1482451200, 1482796800, 1482883200, 1482969600, 1483056000, 1483401600,
1483488000, 1483574400, 1483660800, 1483920000, 1484006400, 1484092800,
1484179200, 1484265600, 1484611200, 1484697600, 1484784000, 1484870400,
1485129600, 1485216000, 1485302400, 1485388800, 1485475200, 1485734400,
1485820800, 1485907200, 1485993600, 1486080000, 1486339200, 1486425600,
1486512000, 1486598400, 1486684800, 1486944000, 1487030400, 1487116800,
1487203200, 1487289600, 1487635200, 1487721600, 1487808000, 1487894400,
1488153600, 1488240000, 1488326400, 1488412800, 1488499200, 1488758400,
1488844800, 1488931200, 1489017600, 1489104000, 1489363200, 1489449600,
1489536000, 1489622400, 1489708800, 1489968000, 1490054400, 1490140800,
1490227200, 1490313600, 1490572800, 1490659200, 1490745600, 1490832000,
1490918400, 1491177600, 1491264000, 1491350400, 1491436800, 1491523200,
1491782400, 1491868800, 1491955200, 1492041600, 1492387200, 1492473600,
1492560000, 1492646400, 1492732800, 1492992000, 1493078400, 1493164800,
1493251200, 1493337600, 1493596800, 1493683200, 1493769600, 1493856000,
1493942400, 1494201600, 1494288000, 1494374400, 1494460800, 1494547200,
1494806400, 1494892800, 1494979200, 1495065600, 1495152000, 1495411200,
1495497600, 1495584000, 1495670400, 1495756800, 1496102400, 1496188800,
1496275200, 1496361600, 1496620800, 1496707200, 1496793600, 1496880000,
1496966400, 1497225600, 1497312000, 1497398400, 1497484800, 1497571200,
1497830400, 1497916800, 1498003200, 1498089600, 1498176000, 1498435200,
1498521600, 1498608000, 1498694400, 1498780800, 1499040000, 1499212800,
1499299200, 1499385600, 1499644800, 1499731200, 1499817600, 1499904000,
1499990400, 1500249600, 1500336000, 1500422400, 1500508800, 1500595200,
1500854400, 1500940800, 1501027200, 1501113600, 1501200000, 1501459200,
1501545600, 1501632000, 1501718400, 1501804800, 1502064000, 1502150400,
1502236800, 1502323200, 1502409600, 1502668800, 1502755200, 1502841600,
1502928000, 1503014400, 1503273600, 1503360000, 1503446400, 1503532800,
1503619200, 1503878400, 1503964800, 1504051200, 1504137600, 1504224000,
1504569600, 1504656000, 1504742400, 1504828800, 1505088000, 1505174400,
1505260800, 1505347200, 1505433600, 1505692800, 1505779200, 1505865600,
1505952000, 1506038400, 1506297600, 1506384000, 1506470400, 1506556800,
1506643200, 1506902400, 1506988800, 1507075200, 1507161600, 1507248000,
1507507200, 1507593600, 1507680000, 1507766400, 1507852800, 1508112000,
1508198400, 1508284800, 1508371200, 1508457600, 1508716800, 1508803200,
1508889600, 1508976000, 1509062400, 1509321600, 1509408000, 1509494400,
1509580800, 1509667200, 1509926400, 1510012800, 1510099200, 1510185600,
1510272000, 1510531200, 1510617600, 1510704000, 1510790400, 1510876800,
1511136000, 1511222400, 1511308800, 1511481600, 1511740800, 1511827200,
1511913600, 1512000000, 1512086400, 1512345600, 1512432000, 1512518400,
1512604800, 1512691200, 1512950400, 1513036800, 1513123200, 1513209600,
1513296000, 1513555200, 1513641600, 1513728000, 1513814400, 1513900800,
1514246400, 1514332800, 1514419200, 1514505600, 1514851200, 1514937600,
1515024000, 1515110400, 1515369600, 1515456000, 1515542400, 1515628800,
1515715200, 1516060800, 1516147200, 1516233600, 1516320000, 1516579200,
1516665600, 1516752000, 1516838400, 1516924800, 1517184000, 1517270400,
1517356800, 1517443200, 1517529600, 1517788800, 1517875200, 1517961600,
1518048000, 1518134400, 1518393600, 1518480000, 1518566400, 1518652800,
1518739200, 1519084800, 1519171200, 1519257600, 1519344000, 1519603200,
1519689600, 1519776000, 1519862400, 1519948800, 1520208000, 1520294400,
1520380800, 1520467200, 1520553600, 1520812800, 1520899200, 1520985600,
1521072000, 1521158400, 1521417600, 1521504000, 1521590400, 1521676800,
1521763200, 1522022400, 1522108800, 1522195200, 1522281600, 1522627200,
1522713600, 1522800000, 1522886400, 1522972800, 1523232000, 1523318400,
1523404800, 1523491200, 1523577600, 1523836800, 1523923200, 1524009600,
1524096000, 1524182400, 1524441600, 1524528000, 1524614400, 1524700800,
1524787200, 1525046400, 1525132800, 1525219200, 1525305600, 1525392000,
1525651200, 1525737600, 1525824000, 1525910400, 1525996800, 1526256000,
1526342400, 1526428800, 1526515200, 1526601600, 1526860800, 1526947200,
1527033600, 1527120000, 1527206400, 1527552000, 1527638400, 1527724800,
1527811200, 1528070400, 1528156800, 1528243200, 1528329600, 1528416000,
1528675200, 1528761600, 1528848000, 1528934400, 1529020800, 1529280000,
1529366400, 1529452800, 1529539200, 1529625600, 1529884800, 1529971200,
1530057600, 1530144000, 1530230400, 1530489600, 1530576000, 1530748800,
1530835200, 1531094400, 1531180800, 1531267200, 1531353600, 1531440000,
1531699200, 1531785600, 1531872000, 1531958400, 1532044800, 1532304000,
1532390400, 1532476800, 1532563200, 1532649600, 1532908800, 1532995200,
1533081600, 1533168000, 1533254400, 1533513600, 1533600000, 1533686400,
1533772800, 1533859200, 1534118400, 1534204800, 1534291200, 1534377600,
1534464000, 1534723200, 1534809600, 1534896000, 1534982400, 1535068800,
1535328000, 1535414400, 1535500800, 1535587200, 1535673600, 1536019200,
1536105600, 1536192000, 1536278400, 1536537600, 1536624000, 1536710400,
1536796800, 1536883200, 1537142400, 1537228800, 1537315200, 1537401600,
1537488000, 1537747200, 1537833600, 1537920000, 1538006400, 1538092800,
1538352000, 1538438400, 1538524800, 1538611200, 1538697600, 1538956800,
1539043200, 1539129600, 1539216000, 1539302400, 1539561600, 1539648000,
1539734400, 1539820800, 1539907200, 1540166400, 1540252800, 1540339200,
1540425600, 1540512000, 1540771200, 1540857600, 1540944000, 1541030400,
1541116800, 1541376000, 1541462400, 1541548800, 1541635200, 1541721600,
1541980800, 1542067200, 1542153600, 1542240000, 1542326400, 1542585600,
1542672000, 1542758400, 1542931200, 1543190400, 1543276800, 1543363200,
1543449600, 1543536000, 1543795200, 1543881600, 1544054400, 1544140800,
1544400000, 1544486400, 1544572800, 1544659200, 1544745600, 1545004800,
1545091200, 1545177600, 1545264000, 1545350400, 1545609600, 1545782400,
1545868800, 1545955200, 1546214400, 1546387200, 1546473600, 1546560000,
1546819200, 1546905600, 1546992000, 1547078400, 1547164800, 1547424000,
1547510400, 1547596800, 1547683200, 1547769600, 1548115200, 1548201600,
1548288000, 1548374400, 1548633600, 1548720000, 1548806400, 1548892800,
1548979200, 1549238400, 1549324800, 1549411200, 1549497600, 1549584000,
1549843200, 1549929600, 1550016000, 1550102400, 1550188800, 1550534400,
1550620800, 1550707200, 1550793600, 1551052800, 1551139200, 1551225600,
1551312000, 1551398400, 1551657600, 1551744000, 1551830400, 1551916800,
1552003200, 1552262400, 1552348800, 1552435200, 1552521600, 1552608000,
1552867200, 1552953600, 1553040000, 1553126400, 1553212800, 1553472000,
1553558400, 1553644800, 1553731200, 1553817600, 1554076800, 1554163200,
1554249600, 1554336000, 1554422400, 1554681600, 1554768000, 1554854400,
1554940800, 1555027200, 1555286400, 1555372800, 1555459200, 1555545600,
1555891200, 1555977600, 1556064000, 1556150400, 1556236800, 1556496000,
1556582400, 1556668800, 1556755200, 1556841600, 1557100800, 1557187200,
1557273600, 1557360000, 1557446400, 1557705600, 1557792000, 1557878400,
1557964800, 1558051200, 1558310400, 1558396800, 1558483200, 1558569600,
1558656000, 1559001600, 1559088000, 1559174400, 1559260800, 1559520000,
1559606400, 1559692800, 1559779200, 1559865600, 1560124800, 1560211200,
1560297600, 1560384000, 1560470400, 1560729600, 1560816000, 1560902400,
1560988800, 1561075200, 1561334400, 1561420800, 1561507200, 1561593600,
1561680000, 1561939200, 1562025600, 1562112000, 1562284800, 1562544000,
1562630400, 1562716800, 1562803200, 1562889600, 1563148800, 1563235200,
1563321600, 1563408000, 1563494400, 1563753600, 1563840000, 1563926400,
1564012800, 1564099200, 1564358400, 1564444800, 1564531200, 1564617600,
1564704000, 1564963200, 1565049600, 1565136000, 1565222400, 1565308800,
1565568000, 1565654400, 1565740800, 1565827200, 1565913600, 1566172800,
1566259200, 1566345600, 1566432000, 1566518400, 1566777600, 1566864000,
1566950400, 1567036800, 1567123200, 1567468800, 1567555200, 1567641600,
1567728000, 1567987200, 1568073600, 1568160000, 1568246400, 1568332800,
1568592000, 1568678400, 1568764800, 1568851200, 1568937600, 1569196800,
1569283200, 1569369600, 1569456000, 1569542400, 1569801600, 1569888000,
1569974400, 1570060800, 1570147200, 1570406400, 1570492800, 1570579200,
1570665600, 1570752000, 1571011200, 1571097600, 1571184000, 1571270400,
1571356800, 1571616000, 1571702400, 1571788800, 1571875200, 1571961600,
1572220800, 1572307200, 1572393600, 1572480000, 1572566400, 1572825600,
1572912000, 1572998400, 1573084800, 1573171200, 1573430400, 1573516800,
1573603200, 1573689600, 1573776000, 1574035200, 1574121600, 1574208000,
1574294400, 1574380800, 1574640000, 1574726400, 1574812800, 1574985600,
1575244800, 1575331200, 1575417600, 1575504000, 1575590400, 1575849600,
1575936000, 1576022400, 1576108800, 1576195200, 1576454400, 1576540800,
1576627200, 1576713600, 1576800000, 1577059200, 1577145600, 1577318400,
1577404800, 1577664000), tzone = "UTC", tclass = "Date"), class = c("xts",
"zoo"), src = "yahoo", updated = structure(1585412559.29406, class = c("POSIXct",
"POSIXt")), .Dim = c(837L, 1L), .Dimnames = list(NULL, "Y1"))
The function used in rollapply must produce an ordinary vector. An lm object is not an acceptable output.
Also by default it just passes the coredata of the object into the function but if you want a zoo object passed so that you can get its time then use coredata = FALSE.
lm may have problems with the zoo object passed so use its coredata.
In lmFunction shown in the question it is trying to use lm(..., x) as if x were a data frame but x is not a data frame.
The two examples below return fitted values and coefficients respectively.
Plotting a line for each time point is going to look like a real mess with all those lines but we show how to produce it anyways at the end.
library(xts)
Y1 <- as.zoo(data)$Y1
fitfun <- function(x) fitted(lm(coredata(x) ~ time(x)))
r1 <- rollapplyr(Y1, 40, fitfun, coredata = FALSE, fill = NA)
dim(r1)
## [1] 837 40
coeffun <- function(x) coef(lm(coredata(x) ~ time(x)))
r2 <- rollapplyr(Y1, 40, coeffun, coredata = FALSE, fill = NA)
dim(r2)
## [1] 837 2
# plot
r2na <- na.omit(r2)
plot(Y1)
junk <- Map(abline, a = r2na[, 1], b = r2na[, 2])
I have this zoo series.
> str(ALLXbm)
‘zoo’ series from 1998-01-01 to 2017-12-01
Data: num [1:240, 1:19] 0.00289 0.00992 -0.00424 0.07958 -0.035 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:19] "DE" "DB" "DM" "IE" ...
Index: Date[1:240], format: "1998-01-01" "1998-02-01" "1998-03-01" "1998-04-01" "1998-05-01" "1998-06-01" "1998-07-01" ...
The followings are the dput() results. The dependent variable is
> dput(ALLX$DE)
structure(c(" 0.0028923077", " 0.0099160000", "-0.0042440000",
" 0.0795800000", "-0.0350041667", "-0.2480500000", " 0.0042880000",
"-0.1620888889", " 0.0637518519", " 0.0928178571", "-0.0974379310",
"-0.1012612903", "-0.0141133333", " 0.0373500000", " 0.0420323529",
" 0.0406323529", "-0.0479314286", " 0.0393514286", " 0.0134594595",
"-0.0042162162", " 0.0282142857", "-0.0467717949", " 0.0271487179",
" 0.0484756757", " 0.0388105263", "-0.0232324324", "-0.1534487179",
"-0.0553538462", "-0.0127976190", " 0.0248613636", "-0.0069093023",
" 0.0016234043", "-0.0004617021", "-0.0747617021", " 0.0362914894",
" 0.0773816327", "-0.0038936170", " 0.0876829787", "-0.0198040000",
"-0.0078372549", " 0.0343978723", " 0.0350833333", "-0.0382480000",
" 0.0824346939", "-0.0280615385", "-0.0312228070", "-0.1020928571",
"-0.1011178571", " 0.0460186441", " 0.0407403509", "-0.0200607143",
" 0.1692310345", " 0.1254927273", "-0.0012947368", " 0.0410393443",
"-0.0060650000", " 0.1175457627", "-0.0219952381", " 0.0538709677",
" 0.1302564516", " 0.0177306452", " 0.0465440678", "-0.0318777778",
"-0.0027257576", "-0.0808714286", " 0.0753223881", " 0.0421338235",
" 0.0192617647", " 0.0645835821", " 0.0178743243", " 0.0917106667",
"-0.0504720000", "-0.0605917808", " 0.0670115942", " 0.0841644737",
"-0.0862937500", " 0.0583458333", " 0.0341283951", " 0.0363376623",
"-0.0072297619", " 0.0697188235", " 0.0708900000", " 0.0964263736",
" 0.0265102273", "-0.0310302326", " 0.0419810000", "-0.0719272727",
" 0.0243521739", "-0.0945943925", " 0.0339018868", " 0.0440350000",
" 0.0503681818", " 0.0629381356", "-0.0510975000", " 0.0249760684",
" 0.0827214876", " 0.0892224806", "-0.0168313043", " 0.0291585366",
" 0.0273647541", "-0.0975674242", "-0.0746062016", " 0.0238595238",
"-0.0278552000", "-0.0925223077", " 0.0659656934", " 0.0456731343",
" 0.0466132450", "-0.0135568493", " 0.0414873016", " 0.0340628205",
" 0.0267903846", "-0.0494906667", " 0.0180333333", " 0.0387062500",
"-0.0283124183", " 0.0306898810", " 0.0886619048", "-0.0198162921",
"-0.0154431818", "-0.0838285714", " 0.0658326531", "-0.0614076503",
" 0.0424984211", "-0.0170115000", " 0.0205202970", " 0.0596765258",
"-0.0538638298", "-0.0453000000", "-0.0493330317", " 0.0545885714",
" 0.1193183168", "-0.0335423810", " 0.0599138393", " 0.0207066964",
" 0.0554773756", " 0.0606587156", " 0.0448098039", "-0.0354082569",
" 0.0057316038", " 0.0019272727", " 0.0214976303", "-0.0108309179",
" 0.0166442211", " 0.0028019512", "-0.0548807910", " 0.0297556962",
"-0.0161016854", " 0.0100739726", " 0.0538203704", " 0.0304168724",
" 0.0246617647", " 0.0294436975", "-0.0192055300", "-0.0221397906",
" 0.0429194215", "-0.1356025974", " 0.0155836364", " 0.0421339806",
" 0.0193581152", "-0.0316510526", " 0.0171187192", " 0.0299633484",
" 0.0136308017", "-0.0803899225", "-0.0462198413", "-0.0337478469",
"-0.0044057018", " 0.0297085185", " 0.0273300000", "-0.0814074689",
" 0.0194720183", "-0.0640064885", " 0.0194782979", " 0.0047418868",
"-0.0393941634", " 0.0119372093", "-0.0092268116", "-0.0221629956",
" 0.0803489130", "-0.0976939502", "-0.0391824701", "-0.0672646154",
"-0.0124784247", "-0.1038085627", "-0.0105592476", "-0.0279538710",
" 0.0196077181", " 0.0338205788", "-0.0189602996", "-0.0860247273",
"-0.0478760714", "-0.0510344720", " 0.0275029586", " 0.0428622291",
" 0.0166286232", "-0.0288036101", "-0.0180476923", " 0.0393909483",
"-0.0641453901", "-0.0841982143", " 0.0047675900", "-0.0240106312",
"-0.0700313793", " 0.0733418994", "-0.0533325905", "-0.0331509589",
" 0.0489809399", "-0.0736352078", " 0.0240526646", "-0.0939243553",
"-0.0042405995", "-0.0387828042", "-0.0470409756", "-0.0931115294",
"-0.0910497738", " 0.0013111111", " 0.0348456633", " 0.0705459082",
" 0.0758425000", "-0.1478202222", " 0.0717040179", " 0.0569382114",
"-0.0945091623", " 0.1044561713", " 0.0293398396", "-0.1272769802",
" 0.0325193750", " 0.0277184066", "-0.0341782369", "-0.0250598160",
" 0.0189187500", "-0.0074535385", "-0.0359813953", " 0.0160150115",
" 0.0476877551", "-0.1018837398", "-0.0427113689", " 0.0191961637",
" 0.1059326403"), index = structure(c(883612800, 886291200, 888710400,
891388800, 893980800, 896659200, 899251200, 901929600, 904608000,
907200000, 909878400, 912470400, 915148800, 917827200, 920246400,
922924800, 925516800, 928195200, 930787200, 933465600, 936144000,
938736000, 941414400, 944006400, 946684800, 949363200, 951868800,
954547200, 957139200, 959817600, 962409600, 965088000, 967766400,
970358400, 973036800, 975628800, 978307200, 980985600, 983404800,
986083200, 988675200, 991353600, 993945600, 996624000, 999302400,
1001894400, 1004572800, 1007164800, 1009843200, 1012521600, 1014940800,
1017619200, 1020211200, 1022889600, 1025481600, 1028160000, 1030838400,
1033430400, 1036108800, 1038700800, 1041379200, 1044057600, 1046476800,
1049155200, 1051747200, 1054425600, 1057017600, 1059696000, 1062374400,
1064966400, 1067644800, 1070236800, 1072915200, 1075593600, 1078099200,
1080777600, 1083369600, 1086048000, 1088640000, 1091318400, 1093996800,
1096588800, 1099267200, 1101859200, 1104537600, 1107216000, 1109635200,
1112313600, 1114905600, 1117584000, 1120176000, 1122854400, 1125532800,
1128124800, 1130803200, 1133395200, 1136073600, 1138752000, 1141171200,
1143849600, 1146441600, 1149120000, 1151712000, 1154390400, 1157068800,
1159660800, 1162339200, 1164931200, 1167609600, 1170288000, 1172707200,
1175385600, 1177977600, 1180656000, 1183248000, 1185926400, 1188604800,
1191196800, 1193875200, 1196467200, 1199145600, 1201824000, 1204329600,
1207008000, 1209600000, 1212278400, 1214870400, 1217548800, 1220227200,
1222819200, 1225497600, 1228089600, 1230768000, 1233446400, 1235865600,
1238544000, 1241136000, 1243814400, 1246406400, 1249084800, 1251763200,
1254355200, 1257033600, 1259625600, 1262304000, 1264982400, 1267401600,
1270080000, 1272672000, 1275350400, 1277942400, 1280620800, 1283299200,
1285891200, 1288569600, 1291161600, 1293840000, 1296518400, 1298937600,
1301616000, 1304208000, 1306886400, 1309478400, 1312156800, 1314835200,
1317427200, 1320105600, 1322697600, 1325376000, 1328054400, 1330560000,
1333238400, 1335830400, 1338508800, 1341100800, 1343779200, 1346457600,
1349049600, 1351728000, 1354320000, 1356998400, 1359676800, 1362096000,
1364774400, 1367366400, 1370044800, 1372636800, 1375315200, 1377993600,
1380585600, 1383264000, 1385856000, 1388534400, 1391212800, 1393632000,
1396310400, 1398902400, 1401580800, 1404172800, 1406851200, 1409529600,
1412121600, 1414800000, 1417392000, 1420070400, 1422748800, 1425168000,
1427846400, 1430438400, 1433116800, 1435708800, 1438387200, 1441065600,
1443657600, 1446336000, 1448928000, 1451606400, 1454284800, 1456790400,
1459468800, 1462060800, 1464739200, 1467331200, 1470009600, 1472688000,
1475280000, 1477958400, 1480550400, 1483228800, 1485907200, 1488326400,
1491004800, 1493596800, 1496275200, 1498867200, 1501545600, 1504224000,
1506816000, 1509494400, 1512086400), tzone = "UTC", tclass = "Date"), class = c("xts",
"zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC", .Dim = c(240L,
1L), .Dimnames = list(NULL, "DE"))
and the independent variable dput() is
> dput(ALLX$SMB_L)
structure(c("-0.0465320170", "-0.0697526439", " 0.0273518415",
"-0.0740531793", " 0.0316742119", " 0.0152537452", "-0.0264616225",
" 0.0288440266", "-0.1158052743", "-0.1629207669", "-0.0321036909",
"-0.0155047450", "-0.0826901559", "-0.0958867805", "-0.1071221681",
"-0.0448685814", "-0.0246406184", "-0.1212194655", "-0.0753136163",
" 0.0410887618", "-0.0472807197", "-0.0821359482", "-0.0538328997",
"-0.1193170755", " 0.0451348940", "-0.0666430865", " 0.1030261973",
"-0.0512679603", "-0.0858501881", "-0.1100767741", " 0.2831559983",
" 0.0049661923", "-0.0466122487", "-0.0566777104", "-0.0268275721",
"-0.0592022576", " 0.0095647556", "-0.0369526728", "-0.0246719322",
" 0.0051186559", "-0.0462739541", "-0.1027257463", " 0.0041844398",
"-0.0443327227", " 0.0513661492", "-0.0672995604", "-0.0509956017",
"-0.0377391126", " 0.1208954628", " 0.0656631973", "-0.0109091553",
"-0.0319298318", " 0.0762361370", " 0.0082987739", " 0.0744911252",
" 0.0268991873", " 0.0106712270", "-0.0162705327", "-0.0030339799",
" 0.0437060161", "-0.0484248103", "-0.0131028206", "-0.0551732558",
"-0.0827144280", " 0.0412271313", "-0.0625801905", "-0.0531687861",
"-0.0194387563", " 0.0651252536", " 0.0185203178", " 0.0212495415",
"-0.0058409877", " 0.0005737324", " 0.0033661115", " 0.0166057656",
" 0.0273215778", "-0.0160116096", "-0.0516442850", " 0.0622634418",
" 0.0059385646", "-0.1501443652", " 0.0901923236", " 0.0033375512",
"-0.0753535560", " 0.0112127728", " 0.0174845326", " 0.0523481171",
"-0.0687008257", " 0.0364307873", " 0.0136230636", " 0.0058142113",
" 0.0554519027", " 0.0519022715", "-0.0570389442", "-0.0170328466",
" 0.0497557753", "-0.0022714909", " 0.0319902902", " 0.0567367912",
"-0.0807706219", " 0.0858961234", " 0.0222949488", " 0.0242892126",
" 0.0215915873", " 0.0537398523", "-0.0632469276", " 0.0111250970",
" 0.0532290206", "-0.0146115567", "-0.0497947429", "-0.0261614454",
"-0.0231347005", " 0.1003858901", " 0.0445487378", "-0.0150134676",
"-0.0457789040", "-0.0034933110", "-0.0668239816", "-0.0159024243",
"-0.0077140317", " 3.6823096028", "-0.0901045024", "-0.0143629036",
"-0.0098836289", "-0.0311347099", "-0.0151321886", "-0.0233462522",
"-0.0458991158", "-0.0282613742", "-0.0779876682", " 0.0117855889",
"-0.0893392649", "-0.0328418515", "-0.0090601777", "-0.0322611560",
"-0.0641631336", "-0.0595636188", " 0.0206379342", "-0.0891543562",
" 0.0717742257", "-0.0461537130", "-0.0954444539", "-0.0543154861",
"-0.0714790350", " 0.0474770475", "-0.0037168520", "-0.0077110744",
"-0.0355079545", " 0.0354765095", "-0.0152485350", "-0.0037694163",
" 0.0088693973", "-0.0013576659", "-0.0158975649", "-0.0569949742",
"-0.0047187899", " 0.0359832832", " 0.0048156392", "-0.0213823507",
"-0.0253481502", "-0.0305909946", "-0.0459944589", " 0.0697664274",
"-0.0053565569", " 0.0119311291", "-0.0068067904", "-0.0046527312",
"-0.0317481424", " 0.0322190631", " 0.0095508469", " 0.0009492415",
" 0.0109837401", " 0.0129883296", "-0.0230918819", " 0.0291994624",
" 0.0053826778", " 0.0116937939", " 0.7079728243", " 0.0103552944",
" 0.0016701093", " 0.0283116307", " 0.0367686262", " 0.0352952954",
" 0.0251452293", " 0.6522285618", " 0.0005676648", "-0.0355068478",
" 0.0383934967", "-0.0054156326", "-0.0288061771", " 0.0076047198",
"-0.0261335344", " 0.0587687305", " 0.0635220884", "-0.0035395762",
" 0.0638110053", "-0.0043276134", "-0.0183498085", "-0.0306437649",
"-0.0153833213", " 0.0165571651", "-0.0014514427", "-0.0111594992",
" 0.0061678879", "-0.0898811021", "-0.0106517096", " 0.0582380903",
" 0.0471135599", " 0.0946734825", " 0.0518059714", " 0.0075574758",
" 0.0078389969", " 0.0998944849", "-0.0259425031", "-0.0031939886",
"-0.0078991041", "-0.0583307843", "-0.0664592297", "-0.0428550515",
"-0.0282970576", " 0.0085063220", " 0.0027516516", "-0.0413816309",
"-0.0080472825", " 0.0001809490", "-0.0719654720", " 0.0250187336",
" 0.0017591069", "-0.0352040828", " 0.0032731177", "-0.0182234806",
"-0.0276918415", " 0.0246782744", " 0.0390556980", "-0.0240913343",
"-0.0207629243", " 0.0289632858", "-0.0398579730", " 0.0048926744",
"-0.0397687581"), index = structure(c(883612800, 886291200, 888710400,
891388800, 893980800, 896659200, 899251200, 901929600, 904608000,
907200000, 909878400, 912470400, 915148800, 917827200, 920246400,
922924800, 925516800, 928195200, 930787200, 933465600, 936144000,
938736000, 941414400, 944006400, 946684800, 949363200, 951868800,
954547200, 957139200, 959817600, 962409600, 965088000, 967766400,
970358400, 973036800, 975628800, 978307200, 980985600, 983404800,
986083200, 988675200, 991353600, 993945600, 996624000, 999302400,
1001894400, 1004572800, 1007164800, 1009843200, 1012521600, 1014940800,
1017619200, 1020211200, 1022889600, 1025481600, 1028160000, 1030838400,
1033430400, 1036108800, 1038700800, 1041379200, 1044057600, 1046476800,
1049155200, 1051747200, 1054425600, 1057017600, 1059696000, 1062374400,
1064966400, 1067644800, 1070236800, 1072915200, 1075593600, 1078099200,
1080777600, 1083369600, 1086048000, 1088640000, 1091318400, 1093996800,
1096588800, 1099267200, 1101859200, 1104537600, 1107216000, 1109635200,
1112313600, 1114905600, 1117584000, 1120176000, 1122854400, 1125532800,
1128124800, 1130803200, 1133395200, 1136073600, 1138752000, 1141171200,
1143849600, 1146441600, 1149120000, 1151712000, 1154390400, 1157068800,
1159660800, 1162339200, 1164931200, 1167609600, 1170288000, 1172707200,
1175385600, 1177977600, 1180656000, 1183248000, 1185926400, 1188604800,
1191196800, 1193875200, 1196467200, 1199145600, 1201824000, 1204329600,
1207008000, 1209600000, 1212278400, 1214870400, 1217548800, 1220227200,
1222819200, 1225497600, 1228089600, 1230768000, 1233446400, 1235865600,
1238544000, 1241136000, 1243814400, 1246406400, 1249084800, 1251763200,
1254355200, 1257033600, 1259625600, 1262304000, 1264982400, 1267401600,
1270080000, 1272672000, 1275350400, 1277942400, 1280620800, 1283299200,
1285891200, 1288569600, 1291161600, 1293840000, 1296518400, 1298937600,
1301616000, 1304208000, 1306886400, 1309478400, 1312156800, 1314835200,
1317427200, 1320105600, 1322697600, 1325376000, 1328054400, 1330560000,
1333238400, 1335830400, 1338508800, 1341100800, 1343779200, 1346457600,
1349049600, 1351728000, 1354320000, 1356998400, 1359676800, 1362096000,
1364774400, 1367366400, 1370044800, 1372636800, 1375315200, 1377993600,
1380585600, 1383264000, 1385856000, 1388534400, 1391212800, 1393632000,
1396310400, 1398902400, 1401580800, 1404172800, 1406851200, 1409529600,
1412121600, 1414800000, 1417392000, 1420070400, 1422748800, 1425168000,
1427846400, 1430438400, 1433116800, 1435708800, 1438387200, 1441065600,
1443657600, 1446336000, 1448928000, 1451606400, 1454284800, 1456790400,
1459468800, 1462060800, 1464739200, 1467331200, 1470009600, 1472688000,
1475280000, 1477958400, 1480550400, 1483228800, 1485907200, 1488326400,
1491004800, 1493596800, 1496275200, 1498867200, 1501545600, 1504224000,
1506816000, 1509494400, 1512086400), tzone = "UTC", tclass = "Date"), class = c("xts",
"zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC", .Dim = c(240L,
1L), .Dimnames = list(NULL, "SMB_L"))
I wanted a gmm rolling regression and i set up the code below.
dogmm <- function(x) {gmm(ALLX$DE~ ALLX$SMB_L, x = ALLXbm)}
kk=rollapply(dogmm, ALLXbm,width=24, by.column = FALSE)
Error message is
Error in zoo(rval, index(x)[i]) :
“x” : attempt to define invalid zoo object
I really can't figure out even if i spent much time. when i tried the gmm code alone, it does work
gmm(ALLXbm$DE~ ALLXbm$SMB_L, x = ALLXbm). I'm thinking that, the problem is in the rollapply code. I'm sorry this's my first attempt to GMM. Please some help?
I have a uiview class that calls a custom drawing class method with a drawrect in it. The drawrect drawing coordinates are drawn for a 433x439 uiview. When this app opens on an iPad Pro autolayout changes the size of the uiview (correctly). But the drawrect still draws to the old 'size'(433x439) and does not scale to fill the new uiview bounds.
Any idea how I can get this to work? I do not want to draw it again to the new coordinates. Seems like content mode or something should redraw? Note: I tap on these shapes to do something else. The scaling(?) that someone hopefully helps me with should not affect that, correct?
+ (void)drawDemos
{
collectedppaths = [NSMutableArray new];
//// Color Declarations
UIColor* color2 = [UIColor colorWithRed: 1 green: 0 blue: 0 alpha: 1];
//// Group
{
//// demo 0 Drawing
UIBezierPath* demo0Path = [UIBezierPath bezierPath];
[demo0Path moveToPoint: CGPointMake(35.5, 215.55)];
[demo0Path addLineToPoint: CGPointMake(86.38, 215.55)];
[demo0Path addLineToPoint: CGPointMake(86.38, 253.39)];
[demo0Path addLineToPoint: CGPointMake(35.5, 254.32)];
[demo0Path addLineToPoint: CGPointMake(35.5, 215.55)];
[demo0Path closePath];
[color2 setStroke];
demo0Path.lineWidth = 5;
[demo0Path stroke];
[collectedppaths addObject:demo0Path];
//// demo 1 Drawing
UIBezierPath* demo1Path = [UIBezierPath bezierPath];
[demo1Path moveToPoint: CGPointMake(35.5, 254.79)];
[demo1Path addLineToPoint: CGPointMake(86.38, 254.79)];
[demo1Path addLineToPoint: CGPointMake(86.38, 304.76)];
[demo1Path addLineToPoint: CGPointMake(35.5, 303.36)];
[demo1Path addLineToPoint: CGPointMake(35.5, 254.79)];
[demo1Path closePath];
[color2 setStroke];
demo1Path.lineWidth = 5;
[demo1Path stroke];
[collectedppaths addObject:demo1Path];
//// demo 3 Drawing
UIBezierPath* demo3Path = [UIBezierPath bezierPath];
[demo3Path moveToPoint: CGPointMake(86.38, 254.79)];
[demo3Path addLineToPoint: CGPointMake(102.71, 256.19)];
[demo3Path addLineToPoint: CGPointMake(122.78, 260.39)];
[demo3Path addLineToPoint: CGPointMake(138.19, 266)];
[demo3Path addLineToPoint: CGPointMake(155.46, 259.46)];
[demo3Path addLineToPoint: CGPointMake(169.46, 250.12)];
[demo3Path addLineToPoint: CGPointMake(177.86, 240.78)];
[demo3Path addLineToPoint: CGPointMake(183.46, 239.37)];
[demo3Path addLineToPoint: CGPointMake(182.53, 302.9)];
[demo3Path addLineToPoint: CGPointMake(88.24, 303.83)];
[demo3Path addLineToPoint: CGPointMake(86.38, 254.79)];
[demo3Path closePath];
[color2 setStroke];
demo3Path.lineWidth = 5;
[demo3Path stroke];
[collectedppaths addObject:demo3Path];
//// demo 6 Drawing
UIBezierPath* demo6Path = [UIBezierPath bezierPath];
[demo6Path moveToPoint: CGPointMake(183.93, 238.91)];
[demo6Path addLineToPoint: CGPointMake(182.53, 308.5)];
[demo6Path addLineToPoint: CGPointMake(279.61, 307.1)];
[demo6Path addLineToPoint: CGPointMake(279.61, 254.79)];
[demo6Path addLineToPoint: CGPointMake(208.2, 254.79)];
[demo6Path addLineToPoint: CGPointMake(191.4, 241.24)];
[demo6Path addLineToPoint: CGPointMake(183.93, 238.91)];
[demo6Path closePath];
[color2 setStroke];
demo6Path.lineWidth = 5;
[demo6Path stroke];
[collectedppaths addObject:demo6Path];
//// demo 5 Drawing
UIBezierPath* demo5Path = [UIBezierPath bezierPath];
[demo5Path moveToPoint: CGPointMake(182.99, 158.1)];
[demo5Path addLineToPoint: CGPointMake(279.14, 206.68)];
[demo5Path addLineToPoint: CGPointMake(279.61, 254.79)];
[demo5Path addLineToPoint: CGPointMake(208.66, 254.79)];
[demo5Path addCurveToPoint: CGPointMake(191.4, 241.24) controlPoint1: CGPointMake(208.66, 254.79) controlPoint2: CGPointMake(191.4, 241.71)];
[demo5Path addCurveToPoint: CGPointMake(183.93, 238.91) controlPoint1: CGPointMake(191.4, 240.78) controlPoint2: CGPointMake(183.93, 238.91)];
[demo5Path addLineToPoint: CGPointMake(182.99, 158.1)];
[demo5Path closePath];
[color2 setStroke];
demo5Path.lineWidth = 5;
[demo5Path stroke];
[collectedppaths addObject:demo5Path];
//// demo 4 Drawing
UIBezierPath* demo4Path = [UIBezierPath bezierPath];
[demo4Path moveToPoint: CGPointMake(218.47, 74.5)];
[demo4Path addLineToPoint: CGPointMake(225.47, 82.91)];
[demo4Path addLineToPoint: CGPointMake(232.94, 103.46)];
[demo4Path addLineToPoint: CGPointMake(241.34, 119.34)];
[demo4Path addLineToPoint: CGPointMake(260.01, 132.42)];
[demo4Path addLineToPoint: CGPointMake(281.48, 139.42)];
[demo4Path addLineToPoint: CGPointMake(279.14, 206.68)];
[demo4Path addLineToPoint: CGPointMake(182.99, 158.1)];
[demo4Path addLineToPoint: CGPointMake(182.99, 111.4)];
[demo4Path addLineToPoint: CGPointMake(179.26, 97.39)];
[demo4Path addLineToPoint: CGPointMake(218.47, 74.5)];
[demo4Path closePath];
[color2 setStroke];
demo4Path.lineWidth = 5;
[demo4Path stroke];
[collectedppaths addObject:demo4Path];
//// demo 7 Drawing
UIBezierPath* demo7Path = [UIBezierPath bezierPath];
[demo7Path moveToPoint: CGPointMake(281.95, 140.36)];
[demo7Path addLineToPoint: CGPointMake(300.62, 143.16)];
[demo7Path addLineToPoint: CGPointMake(319.75, 143.16)];
[demo7Path addLineToPoint: CGPointMake(352.42, 165.58)];
[demo7Path addLineToPoint: CGPointMake(359.43, 183.79)];
[demo7Path addLineToPoint: CGPointMake(387.9, 196.4)];
[demo7Path addLineToPoint: CGPointMake(397.7, 221.16)];
[demo7Path addLineToPoint: CGPointMake(377.16, 228.63)];
[demo7Path addLineToPoint: CGPointMake(297.35, 228.63)];
[demo7Path addLineToPoint: CGPointMake(292.68, 225.83)];
[demo7Path addLineToPoint: CGPointMake(289.88, 213.69)];
[demo7Path addLineToPoint: CGPointMake(279.14, 206.68)];
[demo7Path addLineToPoint: CGPointMake(281.95, 140.36)];
[demo7Path closePath];
[color2 setStroke];
demo7Path.lineWidth = 5;
[demo7Path stroke];
[collectedppaths addObject:demo7Path];
//// demo 8 Drawing
UIBezierPath* demo8Path = [UIBezierPath bezierPath];
[demo8Path moveToPoint: CGPointMake(279.61, 206.21)];
[demo8Path addLineToPoint: CGPointMake(289.88, 213.69)];
[demo8Path addLineToPoint: CGPointMake(292.68, 225.83)];
[demo8Path addLineToPoint: CGPointMake(297.35, 228.63)];
[demo8Path addLineToPoint: CGPointMake(376.7, 228.63)];
[demo8Path addLineToPoint: CGPointMake(397.7, 221.16)];
[demo8Path addLineToPoint: CGPointMake(400.5, 228.63)];
[demo8Path addLineToPoint: CGPointMake(393.5, 253.85)];
[demo8Path addLineToPoint: CGPointMake(279.61, 253.85)];
[demo8Path addLineToPoint: CGPointMake(279.61, 206.21)];
[demo8Path addLineToPoint: CGPointMake(279.61, 206.21)];
[demo8Path closePath];
[color2 setStroke];
demo8Path.lineWidth = 5;
[demo8Path stroke];
[collectedppaths addObject:demo8Path];
//// demo 9 Drawing
UIBezierPath* demo9Path = [UIBezierPath bezierPath];
[demo9Path moveToPoint: CGPointMake(280.08, 253.39)];
[demo9Path addLineToPoint: CGPointMake(398.17, 253.39)];
[demo9Path addLineToPoint: CGPointMake(394.9, 261.33)];
[demo9Path addLineToPoint: CGPointMake(388.83, 266.93)];
[demo9Path addCurveToPoint: CGPointMake(382.76, 270.67) controlPoint1: CGPointMake(388.83, 266.93) controlPoint2: CGPointMake(382.76, 270.2)];
[demo9Path addCurveToPoint: CGPointMake(377.16, 276.74) controlPoint1: CGPointMake(382.76, 271.13) controlPoint2: CGPointMake(377.16, 276.74)];
[demo9Path addLineToPoint: CGPointMake(374.83, 282.81)];
[demo9Path addLineToPoint: CGPointMake(377.16, 308.5)];
[demo9Path addLineToPoint: CGPointMake(280.08, 308.5)];
[demo9Path addLineToPoint: CGPointMake(280.08, 253.39)];
[demo9Path closePath];
[color2 setStroke];
demo9Path.lineWidth = 5;
[demo9Path stroke];
[collectedppaths addObject:demo9Path];
//// demo 2 Drawing
UIBezierPath* demo2Path = [UIBezierPath bezierPath];
[demo2Path moveToPoint: CGPointMake(86.84, 215.55)];
[demo2Path addLineToPoint: CGPointMake(183.93, 215.55)];
[demo2Path addLineToPoint: CGPointMake(183.93, 238.91)];
[demo2Path addLineToPoint: CGPointMake(177.86, 240.78)];
[demo2Path addLineToPoint: CGPointMake(169.46, 250.12)];
[demo2Path addLineToPoint: CGPointMake(155.46, 259.46)];
[demo2Path addLineToPoint: CGPointMake(138.19, 266)];
[demo2Path addLineToPoint: CGPointMake(122.78, 260.39)];
[demo2Path addLineToPoint: CGPointMake(102.71, 256.19)];
[demo2Path addLineToPoint: CGPointMake(86.84, 254.79)];
[demo2Path addLineToPoint: CGPointMake(86.84, 215.55)];
[demo2Path closePath];
[color2 setStroke];
demo2Path.lineWidth = 5;
[demo2Path stroke];
[collectedppaths addObject:demo2Path];
}
}
You are hardcoding your points. Of course it is going to draw in the same place and same size.
Instead, define your points as proportions of the entire view, and calculate the exact x and y values based on the rect that is passed into drawRect.
Now all you have to do is superimpose your view in the correct spot and size and the drawing should scale automatically. You can even have the user zoom and the area should just redraw itself correctly.