Skip to content

time series contains internal NAs error

6 messages · Harsh, stephen sefick, Achim Zeileis +1 more

#
Hello R List,
I seem to have a peculiar problem. When using  time series data, I get
the following error when running the acf and pacf function.
Using the function acf(dtxts,plot= TRUE,xaxt = "n",col="red",na.action
= na.omit) (where dtxts is a time series object created with package
"xts" ) results in the error below.

Error in na.omit.ts(as.ts(x)) : time series contains internal NAs

The above error is seen in R 2.8.0 running on Linux.

The same function does not yield any error in R 2.8.0 on a Windows system.


I've also tried na.remove(dtxts) from the "tseries" package to solve
this problem but to no avail.

Thank you.

Harsh Singhal
Decision Systems
Mu Sigma Inc.,
#
It would be helpful to have a reproducible dataset to track down what
is happening.
On Mon, Jan 19, 2009 at 3:45 AM, Harsh <singhalblr at gmail.com> wrote:

  
    
#
On Mon, 19 Jan 2009, stephen sefick wrote:

            
True.

Although in this case it's relatively easy to guess what went wrong. 
The user probably has some irregular series, for example daily with 
missing days:
    x <- xts(rnorm(10), as.Date("2009-01-19") + c(0:4, 7:11))
acf() just works with regular time series of class "ts". Everything else 
is coerced via as.ts(). This is where the problem is created for your data 
as the error message conveyed:
as.ts(x) detects that there is an underlying regularity (1-day steps) if 
you include two internal NAs (the weekend).

na.omit(as.ts(x)) cannot omit internal NAs because the "ts" class cannot 
represent such an object. Even if it could, acf() couldn't compute the ACF 
with internal mising data.

Some people just ignore the weekend effect (i.e., assume that the Mon-Fri 
correlation is the same as Tue-Mon). If one wants to do this, it can be 
obtained via acf(coredata(x)).
I'm fairly certain it does.
Z
#
The statement to read in the data is missing from your post but
I suspect that you are representing the data as daily data so its filling
in 364 or 365 NA's between points.  Represent it as the annual data
that it is.  Try this:

Lines <- "Sunspots,Datefield
9.5,1/1/1900
2.7,1/1/1901
5,1/1/1902
24.4,1/1/1903
42,1/1/1904
63.5,1/1/1905
53.8,1/1/1906
62,1/1/1907
48.5,1/1/1908
43.9,1/1/1909
18.6,1/1/1910
5.7,1/1/1911
3.6,1/1/1912
1.4,1/1/1913
9.6,1/1/1914
47.4,1/1/1915
57.1,1/1/1916
103.9,1/1/1917
80.6,1/1/1918
63.6,1/1/1919
37.6,1/1/1920
26.1,1/1/1921
14.2,1/1/1922
5.8,1/1/1923
16.7,1/1/1924
44.3,1/1/1925
63.9,1/1/1926
69,1/1/1927
77.8,1/1/1928
64.9,1/1/1929
35.7,1/1/1930
21.2,1/1/1931
11.1,1/1/1932
5.7,1/1/1933
8.7,1/1/1934
36.1,1/1/1935
79.7,1/1/1936
114.4,1/1/1937
109.6,1/1/1938
88.8,1/1/1939
67.8,1/1/1940
47.5,1/1/1941
30.6,1/1/1942
16.3,1/1/1943
9.6,1/1/1944
33.2,1/1/1945
92.6,1/1/1946
151.6,1/1/1947
136.3,1/1/1948
134.7,1/1/1949
83.9,1/1/1950
69.4,1/1/1951
31.5,1/1/1952
13.9,1/1/1953
4.4,1/1/1954
38,1/1/1955
141.7,1/1/1956
190.2,1/1/1957
184.8,1/1/1958
159,1/1/1959
112.3,1/1/1960
53.9,1/1/1961
37.5,1/1/1962
27.9,1/1/1963
10.2,1/1/1964
15.1,1/1/1965
47,1/1/1966
93.8,1/1/1967
105.9,1/1/1968
105.5,1/1/1969
104.5,1/1/1970
66.6,1/1/1971
68.9,1/1/1972
38,1/1/1973
34.5,1/1/1974
15.5,1/1/1975
12.6,1/1/1976
27.5,1/1/1977
92.5,1/1/1978
155.4,1/1/1979
32.27,1/1/1980
54.25,1/1/1981
59.65,1/1/1982
63.62,1/1/1983"

library(chron)
library(zoo)
z <- read.zoo(textConnection(Lines), header = TRUE, sep = ",",
	FUN = function(x) as.yearmon(chron(x)), index = 2)
acf(z)
On Mon, Jan 19, 2009 at 9:34 AM, Harsh <singhalblr at gmail.com> wrote:
#
On Mon, 19 Jan 2009, Gabor Grothendieck wrote:

            
One further pointer: Also look at
   help("sunspots")