model.frame mangles time series (PR#121)

pd@biostat.ku.dk pd@biostat.ku.dk
Thu, 18 Feb 1999 15:47:27 +0100


This one showed up while looking at one of Ripley's other reports:

> data(freeny)
> model.frame(y~1,data=freeny,subset=1:10)
              y
1962.25 8.79236
1962.5  8.79137
1962.75 8.81486
1963    8.81301
1963.25 8.90751
1963.5  8.93673
1963.75 8.96161
1964    8.96044
1964.25 9.00868
1964.5  9.03049
> model.frame(y~1,data=freeny,subset=1:10)$y
Warning: Replacement length not a multiple of the elements to replace in matrix(...) 
Error: length of dimnames[1] not equal to array extent
> model.frame(y~1,data=freeny[1:10,])$y
         Qtr1    Qtr2    Qtr3    Qtr4
1962:      NA 8.79236 8.79137 8.81486
1963: 8.81301 8.90751 8.93673 8.96161
1964: 8.96044 9.00868 9.03049      NA
> dput(model.frame(y~1,data=freeny,subset=1:10)$y)
structure(c(8.79236, 8.79137, 8.81486, 8.81301, 8.90751, 8.93673, 
8.96161, 8.96044, 9.00868, 9.03049), .Tsp = c(1962.25, 1971.75, 
4), class = "ts")

The upshot of this is that glm(...,subset=...) fails on the freeny data.

The cause is seen by 

> model.frame(y~1,data=freeny[1:10,])$y
         Qtr1    Qtr2    Qtr3    Qtr4
1962:      NA 8.79236 8.79137 8.81486
1963: 8.81301 8.90751 8.93673 8.96161
1964: 8.96044 9.00868 9.03049      NA
> dput(model.frame(y~1,data=freeny,subset=1:10)$y)
structure(c(8.79236, 8.79137, 8.81486, 8.81301, 8.90751, 8.93673, 
8.96161, 8.96044, 9.00868, 9.03049), .Tsp = c(1962.25, 1971.75, 
4), class = "ts")

Notice that the .Tsp attribute doesn't reflect the shorter time series
(1971.75 should be 1964.5).

--please do not edit the information below--

Version:
 platform = i586-unknown-linux
 arch = i586
 os = linux
 system = i586, linux
 status = in progress
 status.rev = 0
 major = 0
 minor = 63.3
 year = 1999
 month = February
 day = 19
 language = R

Search Path:
 .GlobalEnv, Autoloads, package:base

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._