简体   繁体   中英

How can I specify a broken time series?

I have survey data collected for many species from 9 surveys within a 11 month period. The surveys span a period that begins in December and ends the following October. There are no data from May or June for any of the species. The following is a simplified example, though my data has many columns of abundance data.

the dates

month <- c("Dec10", "Jan11", "Feb11", "Mar11", "Apr11", "Jul11", "Aug11", "Sep11", "Oct11")

codified using as.yearmon from the package zoo

require(zoo)
month <- as.yearmon(month, "%b%y")

some fake abundance data

meanAbund <- rlnorm(9, 1, 1.2)
meanAbund2 <- meanAbund + 0.5  # to have two series at least

all joined together

df <- cbind.data.frame(meanAbund, meanAbund2, month)

Although I appreciate that this time sequence is not long enough to undertake time series analysis, I would like to specify that these data are a (broken) time series object so that graphs will break the series rather than interpolate or ignore the gap. How should this be done?

I suspect that this should be easy, but I have not cracked the solution. What I want to produce can be seen on page 4 of Shah, Zeileis and Grothendieck's quick reference guide for the zoo package, but I can't see in which step their examples are informed by the code.

I can read it as a time series object

df.ts <- zoo(df[ , 1:2], df$month])

and plot the series (up to the 63 from my actual dataset, although the output is as hard to consider as you might suspect),

plot.zoo(df.ts)

but the series ignore the gaps.

How should i specify the graph or read in these data so that plotting functions "know" to break the series?

The second argument of zoo allows for the order of your data. A gap will be inserted for you for the missing dates:

df
      Date Value
1 Jan 2005     1
2 Feb 2005     2
3 Mar 2005     3
5 May 2005     5
6 Jun 2005     6

Create zoo time series:

library(zoo)
df.ts <- zoo(df$Value, df$Date)

Plot

ts.plot(df.ts)

在此处输入图片说明

Data

df <- structure(list(Date = structure(c(2005, 2005.08333333333, 2005.16666666667, 
                                        2005.33333333333, 2005.41666666667), class = "yearmon"), Value = c(1L, 
                                                                                                           2L, 3L, 5L, 6L)), .Names = c("Date", "Value"), row.names = c("1", 
                                                                                                                                                                        "2", "3", "5", "6"), class = "data.frame")
df$Date <- as.yearmon(df$Date, "%b %Y")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM